implement auto login and remember password

This commit is contained in:
Eduardo Bart 2011-11-16 16:59:55 -02:00
parent f381cb0a74
commit 9159e14895
6 changed files with 62 additions and 10 deletions

View File

@ -12,3 +12,15 @@ end
function string:starts(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

View File

@ -15,7 +15,7 @@ CharacterListLabel < Label
MainWindow
id: charactersWindow
title: Character List
size: 250 250
size: 250 248
onEnter: CharacterList.doLogin()
onEscape: CharacterList.destroy()
@ -35,11 +35,12 @@ MainWindow
Free Account
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: next.top
anchors.bottom: separator.top
margin.left: 16
margin.bottom: 5
HorizontalSeparator
id: separator
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: next.top
@ -47,6 +48,17 @@ MainWindow
margin.right: 16
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
id: buttonOk
text: Ok

View File

@ -10,7 +10,7 @@ local motdMessage
local function onError(protocol, error)
loadBox:destroy()
local errorBox = displayErrorBox('Login Error', error)
errorBox.onOk = EnterGame.create
errorBox.onOk = EnterGame.show
end
local function onMotd(protocol, motd)
@ -20,6 +20,17 @@ local function onMotd(protocol, motd)
end
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()
CharacterList.create(characters, premDays)
@ -35,6 +46,21 @@ end
-- public functions
function EnterGame.create()
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
function EnterGame.destroy()

View File

@ -14,7 +14,6 @@ MainWindow
LineEdit
id: accountNameLineEdit
text: otclient0
anchors.left: parent.left
anchors.right: parent.right
anchors.top: prev.bottom
@ -30,7 +29,6 @@ MainWindow
PasswordLineEdit
id: accountPasswordLineEdit
text: 123456
anchors.left: parent.left
anchors.right: parent.right
anchors.top: prev.bottom
@ -41,17 +39,23 @@ MainWindow
CheckBox
id: rememberPasswordBox
text: Remember password
checked: true
tooltip: Remember account and password when starts otclient
anchors.left: parent.left
anchors.right: parent.right
anchors.top: prev.bottom
margin.top: 10
margin.left: 18
margin.right: 18
@onCheckChange: |
function(self, checked)
self:getParent():getChildById('autoLoginBox'):setEnabled(checked)
end
CheckBox
id: autoLoginBox
enabled: false
text: Auto login
tooltip: Open charlist automatically when starting otclient
anchors.left: parent.left
anchors.right: parent.right
anchors.top: prev.bottom

View File

@ -92,8 +92,6 @@ void push_luavalue(const std::string& str)
bool luavalue_cast(int index, std::string& str)
{
str = g_lua.toString(index);
if(str.empty() && g_lua.isString(index) && !g_lua.isNil())
return false;
return true;
}

View File

@ -361,7 +361,7 @@ void UIWidget::addChild(const UIWidgetPtr& child)
auto self = asUIWidget();
g_dispatcher.addEvent([self,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);
});