Permalink
Browse files

Save 'remember-password' setting per user

  • Loading branch information...
1 parent db46997 commit cd8c27cbecec79c12cad2e6adf5066a6a695df83 @Flakebi Flakebi committed Jun 5, 2014
@@ -166,15 +166,12 @@ PlayerManager::PlayerManager()
*/
PlayerManager::~PlayerManager()
{
- // If the passwords should not be remembered, clear all saved sessions.
- if(!UserConfigParams::m_remember_user)
+ // If the passwords should not be remembered, clear the saved session.
+ PlayerProfile *player;
+ for_in(player, m_all_players)
{
- PlayerProfile *player;
- for_in(player, m_all_players)
- {
+ if(player->rememberPassword())
player->clearSession();
- }
-
}
save();
@@ -266,7 +263,7 @@ void PlayerManager::save()
players_file << L"<?xml version=\"1.0\"?>\n";
players_file << L"<players version=\"1\" >\n";
- if(m_current_player && UserConfigParams::m_remember_user)
+ if(m_current_player)
{
players_file << L" <current player=\""
<< m_current_player->getName() << L"\"/>\n";
@@ -47,6 +47,7 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest)
m_saved_user_id = 0;
m_last_online_name = "";
m_last_was_online = false;
+ m_remember_password = false;
initRemainingData();
} // PlayerProfile
@@ -72,20 +73,22 @@ PlayerProfile::PlayerProfile(const XMLNode* node)
m_saved_user_id = 0;
m_last_online_name = "";
m_last_was_online = false;
+ m_remember_password = false;
m_story_mode_status = NULL;
m_achievements_status = NULL;
m_icon_filename = "";
- node->get("name", &m_local_name );
- node->get("guest", &m_is_guest_account);
- node->get("use-frequency", &m_use_frequency );
- node->get("unique-id", &m_unique_id );
- node->get("saved-session", &m_saved_session );
- node->get("saved-user", &m_saved_user_id );
- node->get("saved-token", &m_saved_token );
- node->get("last-online-name", &m_last_online_name);
- node->get("last-was-online", &m_last_was_online );
- node->get("icon-filename", &m_icon_filename );
+ node->get("name", &m_local_name );
+ node->get("guest", &m_is_guest_account );
+ node->get("use-frequency", &m_use_frequency );
+ node->get("unique-id", &m_unique_id );
+ node->get("saved-session", &m_saved_session );
+ node->get("saved-user", &m_saved_user_id );
+ node->get("saved-token", &m_saved_token );
+ node->get("last-online-name", &m_last_online_name );
+ node->get("last-was-online", &m_last_was_online );
+ node->get("remember-password", &m_remember_password);
+ node->get("icon-filename", &m_icon_filename );
#ifdef DEBUG
m_magic_number = 0xABCD1234;
@@ -203,7 +206,8 @@ void PlayerProfile::save(UTFWriter &out)
out << L" saved-user=\"" << m_saved_user_id
<< L"\" saved-token=\"" << m_saved_token << L"\"\n";
out << L" last-online-name=\"" << m_last_online_name
- << L"\" last-was-online=\"" << m_last_was_online<< L"\">\n";
+ << L"\" last-was-online=\"" << m_last_was_online << L"\"\n";
+ out << L" remember-password=\"" << m_remember_password << L"\">\n";
{
if(m_story_mode_status)
m_story_mode_status->save(out);
@@ -101,6 +101,9 @@ class PlayerProfile : public NoCopy
/** True if the last time this player was used as online. */
bool m_last_was_online;
+ /** True if the login data are saved. */
+ bool m_remember_password;
+
/** The complete challenge state. */
StoryModeStatus *m_story_mode_status;
@@ -269,6 +272,13 @@ class PlayerProfile : public NoCopy
/** Sets if this player was logged in last time it was used. */
void setWasOnlineLastTime(bool b) { m_last_was_online = b; }
// ------------------------------------------------------------------------
+ /** Returns if the last time this player was used it was used online or
+ * offline. */
+ bool rememberPassword() const { return m_remember_password; }
+ // ------------------------------------------------------------------------
+ /** Sets if this player was logged in last time it was used. */
+ void setRememberPassword(bool b) { m_remember_password = b; }
+ // ------------------------------------------------------------------------
}; // class PlayerProfile
#endif
@@ -682,10 +682,6 @@ namespace UserConfigParams
// ---- User managerment
- PARAM_PREFIX BoolUserConfigParam m_remember_user
- PARAM_DEFAULT( BoolUserConfigParam(true, "remember_me",
- "Automatically remember login data"));
-
PARAM_PREFIX BoolUserConfigParam m_always_show_login_screen
PARAM_DEFAULT( BoolUserConfigParam(false, "always_show_login_screen",
"Always show the login screen even if last player's session was saved."));
@@ -125,8 +125,8 @@ namespace Online
request->addParameter("username",username);
request->addParameter("password",password);
request->addParameter("save-session",
- UserConfigParams::m_remember_user ? "true"
- : "false");
+ rememberPassword() ? "true"
+ : "false");
request->queue();
m_online_state = OS_SIGNING_IN;
return request;
@@ -187,7 +187,7 @@ namespace Online
m_profile = new OnlineProfile(userid, username, true);
assert(token_fetched && username_fetched && userid_fetched);
m_online_state = OS_SIGNED_IN;
- if(UserConfigParams::m_remember_user)
+ if(rememberPassword())
{
saveSession(getOnlineId(), getToken() );
}
@@ -238,8 +238,8 @@ namespace Online
{
m_player = player;
m_player->setUserDetails(this,
- UserConfigParams::m_remember_user ? "client-quit"
- :"disconnect");
+ m_player->rememberPassword() ? "client-quit"
+ : "disconnect");
setAbortable(false);
} // SignOutRequest
}; // SignOutRequest
@@ -282,7 +282,7 @@ namespace Online
m_profile = NULL;
m_online_state = OS_SIGNED_OUT;
// Discard token if session should not be saved.
- if(!UserConfigParams::m_remember_user)
+ if(!rememberPassword())
clearSession();
} // signOut
@@ -74,7 +74,7 @@ void BaseUserScreen::init()
assert(m_info_widget);
getWidget<CheckBoxWidget>("remember-user")
- ->setState(UserConfigParams::m_remember_user);
+ ->setState(false);
m_sign_out_name = "";
m_sign_in_name = "";
@@ -114,6 +114,8 @@ void BaseUserScreen::init()
// Select 'online
m_online_cb->setState(player->wasOnlineLastTime() ||
player->isLoggedIn() );
+ getWidget<CheckBoxWidget>("remember-user")->setState(
+ player->rememberPassword());
makeEntryFieldsVisible();
// We have to deactivate after make visible (since make visible
// automatically activates widgets).
@@ -157,8 +159,6 @@ void BaseUserScreen::selectUser(int index)
PlayerProfile *profile = PlayerManager::get()->getPlayer(index);
assert(profile);
- getWidget<TextBoxWidget >("username")->setText(profile
- ->getLastOnlineName());
m_players->setSelection(StringUtils::toString(index), 0, /*focusIt*/true);
// Last game was not online, so make the offline settings the default
@@ -175,6 +175,8 @@ void BaseUserScreen::selectUser(int index)
m_online_cb->setState(true);
makeEntryFieldsVisible();
m_username_tb->setText(profile->getLastOnlineName());
+ getWidget<CheckBoxWidget>("remember-user")->setState(
+ profile->rememberPassword());
// And make the password invisible if the session is saved (i.e
// the user does not need to enter a password).
@@ -242,8 +244,8 @@ void BaseUserScreen::eventCallback(Widget* widget,
}
else if (name == "remember-user")
{
- UserConfigParams::m_remember_user =
- getWidget<CheckBoxWidget>("remember-user")->getState();
+ getSelectedPlayer()->setRememberPassword(
+ getWidget<CheckBoxWidget>("remember-user")->getState());
}
else if (name == "online")
{
@@ -257,8 +259,13 @@ void BaseUserScreen::eventCallback(Widget* widget,
true);
sfx_manager->quickSound( "anvil" );
m_online_cb->setState(false);
+ } else
+ {
+ m_username_tb->setText("");
+ m_password_tb->setText("");
+ getWidget<CheckBoxWidget>("remember-user")->setState(false);
+ makeEntryFieldsVisible();
}
- makeEntryFieldsVisible();
}
else if (name == "options")
{

0 comments on commit cd8c27c

Please sign in to comment.