implement auto login and remember password
This commit is contained in:
parent
f381cb0a74
commit
9159e14895
|
@ -10,5 +10,17 @@ function string:split(sep)
|
||||||
end
|
end
|
||||||
|
|
||||||
function string:starts(start)
|
function string:starts(start)
|
||||||
return self:sub(1, #start) == start
|
return self:sub(1, #start) == start
|
||||||
|
end
|
||||||
|
|
||||||
|
function string.trim(str)
|
||||||
|
return str:match'^%s*(.*%S)' or ''
|
||||||
|
end
|
||||||
|
|
||||||
|
function toboolean(str)
|
||||||
|
str = string.trim(str)
|
||||||
|
if str == '1' or str == 'true' then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
|
@ -15,7 +15,7 @@ CharacterListLabel < Label
|
||||||
MainWindow
|
MainWindow
|
||||||
id: charactersWindow
|
id: charactersWindow
|
||||||
title: Character List
|
title: Character List
|
||||||
size: 250 250
|
size: 250 248
|
||||||
onEnter: CharacterList.doLogin()
|
onEnter: CharacterList.doLogin()
|
||||||
onEscape: CharacterList.destroy()
|
onEscape: CharacterList.destroy()
|
||||||
|
|
||||||
|
@ -35,11 +35,12 @@ MainWindow
|
||||||
Free Account
|
Free Account
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.bottom: next.top
|
anchors.bottom: separator.top
|
||||||
margin.left: 16
|
margin.left: 16
|
||||||
margin.bottom: 5
|
margin.bottom: 5
|
||||||
|
|
||||||
HorizontalSeparator
|
HorizontalSeparator
|
||||||
|
id: separator
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.bottom: next.top
|
anchors.bottom: next.top
|
||||||
|
@ -47,6 +48,17 @@ MainWindow
|
||||||
margin.right: 16
|
margin.right: 16
|
||||||
margin.bottom: 10
|
margin.bottom: 10
|
||||||
|
|
||||||
|
CheckBox
|
||||||
|
id: charAutoLoginBox
|
||||||
|
text: Auto login
|
||||||
|
tooltip: Auto login selected character on next charlist load
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.bottom: next.top
|
||||||
|
margin.bottom: 6
|
||||||
|
margin.left: 18
|
||||||
|
margin.right: 18
|
||||||
|
|
||||||
Button
|
Button
|
||||||
id: buttonOk
|
id: buttonOk
|
||||||
text: Ok
|
text: Ok
|
||||||
|
|
|
@ -10,7 +10,7 @@ local motdMessage
|
||||||
local function onError(protocol, error)
|
local function onError(protocol, error)
|
||||||
loadBox:destroy()
|
loadBox:destroy()
|
||||||
local errorBox = displayErrorBox('Login Error', error)
|
local errorBox = displayErrorBox('Login Error', error)
|
||||||
errorBox.onOk = EnterGame.create
|
errorBox.onOk = EnterGame.show
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onMotd(protocol, motd)
|
local function onMotd(protocol, motd)
|
||||||
|
@ -20,6 +20,17 @@ local function onMotd(protocol, motd)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onCharacterList(protocol, characters, premDays)
|
local function onCharacterList(protocol, characters, premDays)
|
||||||
|
if enterGame:getChildById('rememberPasswordBox'):isChecked() then
|
||||||
|
Configs.set('account', EnterGame.account)
|
||||||
|
Configs.set('password', EnterGame.password)
|
||||||
|
Configs.set('autologin', tostring(enterGame:getChildById('autoLoginBox'):isChecked()))
|
||||||
|
else
|
||||||
|
Configs.set('account', nil)
|
||||||
|
Configs.set('password', nil)
|
||||||
|
enterGame:getChildById('accountNameLineEdit'):clearText()
|
||||||
|
enterGame:getChildById('accountPasswordLineEdit'):clearText()
|
||||||
|
end
|
||||||
|
|
||||||
loadBox:destroy()
|
loadBox:destroy()
|
||||||
CharacterList.create(characters, premDays)
|
CharacterList.create(characters, premDays)
|
||||||
|
|
||||||
|
@ -35,6 +46,21 @@ end
|
||||||
-- public functions
|
-- public functions
|
||||||
function EnterGame.create()
|
function EnterGame.create()
|
||||||
enterGame = UI.loadAndDisplay('/entergame/entergame.otui')
|
enterGame = UI.loadAndDisplay('/entergame/entergame.otui')
|
||||||
|
|
||||||
|
local account = Configs.get('account')
|
||||||
|
local password = Configs.get('password')
|
||||||
|
local autologin = toboolean(Configs.get('autologin'))
|
||||||
|
|
||||||
|
enterGame:getChildById('accountNameLineEdit'):setText(account)
|
||||||
|
enterGame:getChildById('accountPasswordLineEdit'):setText(password)
|
||||||
|
|
||||||
|
if #account > 0 then
|
||||||
|
enterGame:getChildById('rememberPasswordBox'):setChecked(true)
|
||||||
|
if autologin then
|
||||||
|
enterGame:getChildById('autoLoginBox'):setChecked(true)
|
||||||
|
addEvent(EnterGame.doLogin)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function EnterGame.destroy()
|
function EnterGame.destroy()
|
||||||
|
|
|
@ -14,7 +14,6 @@ MainWindow
|
||||||
|
|
||||||
LineEdit
|
LineEdit
|
||||||
id: accountNameLineEdit
|
id: accountNameLineEdit
|
||||||
text: otclient0
|
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
|
@ -30,7 +29,6 @@ MainWindow
|
||||||
|
|
||||||
PasswordLineEdit
|
PasswordLineEdit
|
||||||
id: accountPasswordLineEdit
|
id: accountPasswordLineEdit
|
||||||
text: 123456
|
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
|
@ -41,17 +39,23 @@ MainWindow
|
||||||
CheckBox
|
CheckBox
|
||||||
id: rememberPasswordBox
|
id: rememberPasswordBox
|
||||||
text: Remember password
|
text: Remember password
|
||||||
checked: true
|
tooltip: Remember account and password when starts otclient
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
margin.top: 10
|
margin.top: 10
|
||||||
margin.left: 18
|
margin.left: 18
|
||||||
margin.right: 18
|
margin.right: 18
|
||||||
|
@onCheckChange: |
|
||||||
|
function(self, checked)
|
||||||
|
self:getParent():getChildById('autoLoginBox'):setEnabled(checked)
|
||||||
|
end
|
||||||
|
|
||||||
CheckBox
|
CheckBox
|
||||||
id: autoLoginBox
|
id: autoLoginBox
|
||||||
|
enabled: false
|
||||||
text: Auto login
|
text: Auto login
|
||||||
|
tooltip: Open charlist automatically when starting otclient
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
|
|
|
@ -92,8 +92,6 @@ void push_luavalue(const std::string& str)
|
||||||
bool luavalue_cast(int index, std::string& str)
|
bool luavalue_cast(int index, std::string& str)
|
||||||
{
|
{
|
||||||
str = g_lua.toString(index);
|
str = g_lua.toString(index);
|
||||||
if(str.empty() && g_lua.isString(index) && !g_lua.isNil())
|
|
||||||
return false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -361,7 +361,7 @@ void UIWidget::addChild(const UIWidgetPtr& child)
|
||||||
auto self = asUIWidget();
|
auto self = asUIWidget();
|
||||||
g_dispatcher.addEvent([self,child]() {
|
g_dispatcher.addEvent([self,child]() {
|
||||||
// always focus new child
|
// always focus new child
|
||||||
if(child->isFocusable() && child->isExplicitlyVisible() && child->isExplicitlyEnabled())
|
if(child->getParent() == self && child->isFocusable() && child->isExplicitlyVisible() && child->isExplicitlyEnabled())
|
||||||
self->focusChild(child, Fw::ActiveFocusReason);
|
self->focusChild(child, Fw::ActiveFocusReason);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue