Author: baufo
Date: Fri Mar 21 20:15:55 2008
New Revision: 24949
URL: http://svn.gna.org/viewcvs/wesnoth?rev=24949&view=rev
Log:
Wiring in the password reminder function
Modified:
branches/mp_registration/src/multiplayer.cpp
branches/mp_registration/src/server/player.cpp
branches/mp_registration/src/server/player.hpp
branches/mp_registration/src/server/server.cpp
branches/mp_registration/src/server/user_handler.hpp
Modified: branches/mp_registration/src/multiplayer.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/mp_registration/src/multiplayer.cpp?rev=24949&r1=24948&r2=24949&view=diff
==============================================================================
--- branches/mp_registration/src/multiplayer.cpp (original)
+++ branches/mp_registration/src/multiplayer.cpp Fri Mar 21 20:15:55 2008
@@ -220,32 +220,51 @@
bool first_time = true;
config* error = NULL;
+ std::vector<std::string> opts;
+ opts.push_back(_("Log in with password"));
+ opts.push_back(_("Request password reminder for this username"));
+ opts.push_back(_("Choose a different username"));
+
do {
- if(error != NULL) {
-
gui::dialog(disp,"",(*error)["message"],gui::OK_ONLY).show();
- }
-
- std::string login = preferences::login();
+ std::string login = preferences::login();
std::string password = "";
+ std::string password_reminder = "";
if(!first_time) {
- //This implementation is just a temporary
hack
-
- //! @todo Instead of just asking for the
password we should provide
- //! the user with a dialog where he can
choose a different name,
- //! provide a password or request a
password reminder
+ //Somewhat hacky implementation
//! @todo A fancy textbox that displays
characters as dots or asterisk would
//! be nice, just in chase your enemy is
standing behind you
+
if((*error).child("password_request")) {
- const int res = gui::show_dialog(disp, NULL, "",
- _("Please enter a password"), gui::OK_CANCEL,
- NULL, NULL, _("Password: "), &password,
mp::max_login_size);
- if(res != 0 || password.empty()) {
- return ABORT_SERVER;
+ const int res = gui::show_dialog(disp, NULL,
_("Login"),
+ (*error)["message"], gui::OK_CANCEL,
+ &opts, NULL, _("Password: "), &password,
mp::max_login_size);
+
+ switch(res) {
+ //Log in with password
+ case 0:
+ break;
+ //Request a password reminder
+ case 1:
+ password_reminder = login;
+ break;
+ //Choose a different username
+ case 2:
+ password = "";
+ goto new_username;
+ break;
+ default: return ABORT_SERVER;
}
+
} else {
+ if(error != NULL) {
+
gui::dialog(disp,"",(*error)["message"],gui::OK_ONLY).show();
+ }
+
+ new_username:
+
const int res = gui::show_dialog(disp, NULL, "",
_("You must log in to this server"),
gui::OK_CANCEL,
NULL, NULL, _("Login: "), &login,
mp::max_login_size);
@@ -261,6 +280,8 @@
config response;
response.add_child("login")["username"] = login;
(*(response.child("login")))["password"] =
password;
+
(*(response.child("login")))["password_reminder"] = password_reminder;
+
network::send_data(response, 0, true);
network::connection data_res =
network::receive_data(data, 0, 3000);
Modified: branches/mp_registration/src/server/player.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/mp_registration/src/server/player.cpp?rev=24949&r1=24948&r2=24949&view=diff
==============================================================================
--- branches/mp_registration/src/server/player.cpp (original)
+++ branches/mp_registration/src/server/player.cpp Fri Mar 21 20:15:55 2008
@@ -36,6 +36,7 @@
void player::mark_registered(bool registered) {
cfg_.set_attr("registered", registered ? "yes" : "no");
+ registered_ = registered;
}
bool player::is_message_flooding() {
Modified: branches/mp_registration/src/server/player.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/mp_registration/src/server/player.hpp?rev=24949&r1=24948&r2=24949&view=diff
==============================================================================
--- branches/mp_registration/src/server/player.hpp (original)
+++ branches/mp_registration/src/server/player.hpp Fri Mar 21 20:15:55 2008
@@ -32,6 +32,7 @@
void mark_registered(bool registered =true);
+ bool registered() const {return registered_;}
const std::string& name() const { return name_; }
@@ -44,6 +45,8 @@
const std::string name_;
simple_wml::node& cfg_;
+ bool registered_;
+
time_t flood_start_;
unsigned int messages_since_flood_start_;
const size_t MaxMessages;
Modified: branches/mp_registration/src/server/server.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/mp_registration/src/server/server.cpp?rev=24949&r1=24948&r2=24949&view=diff
==============================================================================
--- branches/mp_registration/src/server/server.cpp (original)
+++ branches/mp_registration/src/server/server.cpp Fri Mar 21 20:15:55 2008
@@ -700,6 +700,21 @@
return;
}
+ if(user_handler_) {
+ //If this is a request for password reminder
+ std::string password_reminder =
(*login)["password_reminder"].to_string();
+ if(!password_reminder.empty()) {
+ try {
+ user_handler_->password_reminder(password_reminder);
+ send_error(sock, "Your password reminder email has been
sent.");
+ } catch (user_handler::error e) {
+ send_error(sock, ("Your password reminder email could not be
sent."
+ " The error message was: " + e.message).c_str());
+ }
+ return;
+ }
+ }
+
// Check if the username is valid (all alpha-numeric plus underscore
and hyphen)
std::string username = (*login)["username"].to_string();
if (!utils::isvalid_username(username)) {
@@ -739,12 +754,13 @@
if(user_handler_->user_exists(username)) {
//This name is registered and no password provided
if(password.empty()) {
- send_password_request(sock, "This username is registered on
this server.");
+ send_password_request(sock, ("The username '" + username + "'
is registered on this server.").c_str());
return;
}
//This name is registered and an incorrect password provided
else if(!(user_handler_->login(username, password))) {
- send_password_request(sock, "The password you provided was
incorrect");
+ send_password_request(sock, ("The password you provided for
the username '" + username +
+ "' was incorrect.").c_str());
LOG_SERVER << network::ip_address(sock) << "\t"
<< "Login attempt with incorrect password for username
'" << username << "'.\n";
@@ -916,16 +932,25 @@
lobby_.send_server_message(res.c_str(), sock);
} catch (user_handler::error e) {
lobby_.send_server_message(("There was and error looking up the
details of the user '" +
- (*data.child("info"))["name"].to_string() + "'. " +" Tſhe error
message was: "
+ (*data.child("info"))["name"].to_string() + "'. " +" The error
message was: "
+ e.message).c_str(), sock);
}
-
+ return;
}
//A user requested to delete his nick
if(data.child("drop")) {
if(!(user_handler_->user_exists(pl->second.name()))) {
lobby_.send_server_message("You are not registered.",
+ sock);
+ return;
+ }
+
+ //With the current policy of dissallowing to log in with a
+ //registerd username without the password we should never get
+ //to calling this
+ if(!(pl->second.registered())) {
+ lobby_.send_server_message("You are not logged in.",
sock);
return;
}
@@ -946,8 +971,8 @@
lobby_.send_server_message(("There was and error dropping your
username. The error message was: "
+ e.message).c_str(), sock);
}
- }
-
+ return;
+ }
}
std::string server::process_command(const std::string& query) {
Modified: branches/mp_registration/src/server/user_handler.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/mp_registration/src/server/user_handler.hpp?rev=24949&r1=24948&r2=24949&view=diff
==============================================================================
--- branches/mp_registration/src/server/user_handler.hpp (original)
+++ branches/mp_registration/src/server/user_handler.hpp Fri Mar 21 20:15:55
2008
@@ -53,7 +53,6 @@
//! Returns true if we can send emails
bool mail();
-
struct error {
error(const std::string& msg) : message(msg) {}
std::string message;
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits