Fixed login problems (e.g. only online log in worked), improved handling

of error message, removed need for m_login_successful.
This commit is contained in:
hiker 2014-05-06 08:21:53 +10:00
parent d847e8de00
commit bef811e098
2 changed files with 35 additions and 23 deletions

View File

@ -54,7 +54,6 @@ void UserScreen::loadedFromFile()
void UserScreen::init() void UserScreen::init()
{ {
m_login_successful = false;
m_online_cb = getWidget<CheckBoxWidget>("online"); m_online_cb = getWidget<CheckBoxWidget>("online");
assert(m_online_cb); assert(m_online_cb);
m_username_tb = getWidget<TextBoxWidget >("username"); m_username_tb = getWidget<TextBoxWidget >("username");
@ -73,6 +72,12 @@ void UserScreen::init()
RibbonWidget* tabs = getWidget<RibbonWidget>("login_tabs"); RibbonWidget* tabs = getWidget<RibbonWidget>("login_tabs");
if (tabs) tabs->select( "tab_login", PLAYER_ID_GAME_MASTER ); if (tabs) tabs->select( "tab_login", PLAYER_ID_GAME_MASTER );
// It should always be activated ... but just in case
m_options_widget->setActivated();
// Clean any error message still shown
m_info_widget->setText("", true);
m_info_widget->setErrorColor();
Screen::init(); Screen::init();
PlayerProfile *player = PlayerManager::getCurrentPlayer(); PlayerProfile *player = PlayerManager::getCurrentPlayer();
if (player && !m_is_popup_window) if (player && !m_is_popup_window)
@ -231,6 +236,15 @@ void UserScreen::eventCallback(Widget* widget,
} // eventCallback } // eventCallback
// ----------------------------------------------------------------------------
/** Closes the UserScreen, and makes sure that the right screen is displayed
* next.
*/
void UserScreen::closeScreen()
{
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
} // closeScreen
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Called when OK or OK-and-save is clicked. /** Called when OK or OK-and-save is clicked.
* This will trigger the actual login (if requested) etc. * This will trigger the actual login (if requested) etc.
@ -239,6 +253,8 @@ void UserScreen::eventCallback(Widget* widget,
*/ */
void UserScreen::login(bool remember_me) void UserScreen::login(bool remember_me)
{ {
// If an error occurs, the callback informing this screen about the
// problem will activate the widget again.
m_options_widget->setDeactivated(); m_options_widget->setDeactivated();
const std::string &s_id = m_players->getSelectionIDString(0); const std::string &s_id = m_players->getSelectionIDString(0);
@ -258,16 +274,21 @@ void UserScreen::login(bool remember_me)
// a failed logout request // a failed logout request
profile->requestSignOut(); profile->requestSignOut();
} }
m_login_successful = true; closeScreen();
// This will trigger replacing this screen with the main menu screen.
onUpdate(0.0f);
return; return;
} }
// Player wants to be online, and is already online - nothing to do
if(profile->isLoggedIn()) if(profile->isLoggedIn())
{
closeScreen();
return; return;
}
// If the user is not already logged in, start a login request // Now we need to start a login request to the server
// This implies that this screen will wait till the server responds, so
// that error messages ('invalid password') can be shown, and the user
// can decide what to do about them.
if (profile->hasSavedSession()) if (profile->hasSavedSession())
{ {
// Online login with saved token // Online login with saved token
@ -275,7 +296,7 @@ void UserScreen::login(bool remember_me)
} }
else else
{ {
// Online login with password // Online login with password --> we need a valid password
if (m_password_tb->getText() == "") if (m_password_tb->getText() == "")
{ {
m_info_widget->setText(_("You need to enter a password."), true); m_info_widget->setText(_("You need to enter a password."), true);
@ -286,6 +307,7 @@ void UserScreen::login(bool remember_me)
m_password_tb->getText(), m_password_tb->getText(),
remember_me); remember_me);
} // !hasSavedSession } // !hasSavedSession
} // login } // login
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -297,17 +319,6 @@ void UserScreen::onUpdate(float dt)
if (!m_options_widget->isActivated()) if (!m_options_widget->isActivated())
m_info_widget->setText(Online::Messages::loadingDots( _("Signing in")), m_info_widget->setText(Online::Messages::loadingDots( _("Signing in")),
false); false);
if(m_online_cb->getState() && m_login_successful)
{
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
return;
}
PlayerProfile *cp = PlayerManager::getCurrentPlayer();
if (cp && cp->isLoggedIn())
cp->requestSignOut();
} // onUpdate } // onUpdate
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -315,9 +326,13 @@ void UserScreen::onUpdate(float dt)
*/ */
void UserScreen::loginSuccessful() void UserScreen::loginSuccessful()
{ {
m_options_widget->setActivated();
// Clean any error message still shown
m_info_widget->setText("", true);
m_info_widget->setErrorColor();
// The callback is done from the main thread, so no need to sync // The callback is done from the main thread, so no need to sync
// access to m_success // access to m_success. OnUpdate will check this flag
m_login_successful = true; closeScreen();
} // loginSuccessful } // loginSuccessful
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -49,10 +49,6 @@ private:
* immediately go to the main menu if a current player is defined. */ * immediately go to the main menu if a current player is defined. */
bool m_is_popup_window; bool m_is_popup_window;
/** Set in the callback from the login request to indicate that this
* window can be closed. */
bool m_login_successful;
/** Online check box. */ /** Online check box. */
GUIEngine::CheckBoxWidget *m_online_cb; GUIEngine::CheckBoxWidget *m_online_cb;
@ -74,6 +70,7 @@ private:
void selectUser(int index); void selectUser(int index);
void makeEntryFieldsVisible(bool online); void makeEntryFieldsVisible(bool online);
void login(bool remember_me); void login(bool remember_me);
void closeScreen();
virtual void onDialogClose(); virtual void onDialogClose();
virtual void onUpdate(float dt) OVERRIDE; virtual void onUpdate(float dt) OVERRIDE;