28 if(c[
"user_expiration"].empty()) {
34 std::cerr <<
"Bad lexical cast reading 'user_expiration', using default value.\n";
43 users_.insert(std::pair<std::string, user>(name,
user()));
58 std::map<std::string,user>::const_iterator u =
users_.find(name);
60 return (u !=
users_.end());
69 std::vector<std::string>
users;
70 for(std::map<std::string,user>::const_iterator u =
users_.begin(); u !=
users_.end(); ++u) {
71 users.push_back(u->first);
77 if(detail ==
"mail") {
79 }
else if (detail ==
"password") {
81 }
else if (detail ==
"realname") {
89 return "'mail', 'password', 'realname';";
115 users_[user].realname = realname;
123 users_[user].lastlogin = lastlogin;
133 return users_[user].password;
137 return users_[user].realname;
141 return users_[user].lastlogin;
145 return users_[user].registrationdate;
152 throw error(
"This username contains invalid "
153 "characters. Only alpha-numeric characters, underscores and hyphens"
156 if(name.size() > 20) {
157 throw error(
"This username is too long. Usernames must be 20 characters or less.");
167 throw error(
"Password contains invalid characters");
172 if(realname.size() > 50) {
173 throw error(
"This name is too long. Names must be 50 characters or less");
188 time_t now = time(
nullptr);
194 std::vector<std::string> us =
users();
195 for(std::vector<std::string>::const_iterator u = us.begin(); u != us.end(); ++u) {
197 std::cout <<
"User '" << *u <<
"' exceeds expiration limit.\n";
212 std::stringstream
msg;
213 msg <<
"Hello " << name <<
",\nyour password is '" <<
get_password(name) <<
"'.\n\nHave fun playing Wesnoth :)";
214 send_mail(name,
"Wesnoth Password Reminder", msg.str());
218 if(!
user_exists(name))
throw error(
"No user with the name '" + name +
"' exists.");
227 ll_string = ctime(&ll_date);
229 ll_string =
"Never\n";
232 std::stringstream
info;
233 info <<
"Name: " << name <<
"\n"
235 <<
"Registered: " << reg_string
236 <<
"Last login: " << ll_string;
238 info <<
"This account is currently inactive.\n";
void set_mail(const std::string &user, const std::string &mail)
void check_mail(const std::string &mail)
bool user_is_moderator(const std::string &name)
Returns true if this user is a moderator on this server.
bool isvalid_username(const std::string &username)
Check if the username contains only valid characters.
void clean_up()
Called by the server once a day.
static l_noret error(LoadState *S, const char *why)
bool login(const std::string &name, const std::string &password, const std::string &)
Return true if the given password matches the password for the given user.
void set_lastlogin(const std::string &user, const time_t &lastlogin)
bool send_mail(const std::string &to_user, const std::string &subject, const std::string &message)
Sends an email to the specified address.
Definitions for the interface to Wesnoth Markup Language (WML).
std::string get_valid_details()
List of details that can be set for this user_handler.
void check_realname(const std::string &realname)
void check_name(const std::string &name)
void password_reminder(const std::string &name)
Send a password reminder email to the given user.
std::map< std::string, user > users_
GLsizei const GLfloat * value
void set_realname(const std::string &user, const std::string &realname)
time_t get_lastlogin(const std::string &user)
Templates and utility-routines for strings and numbers.
void user_logged_in(const std::string &name)
Executed when the user with the given name logged in.
void set_password(const std::string &user, const std::string &password)
bool user_exists(const std::string &name)
Returns true if a user with the given name exists.
void check_password(const std::string &password)
std::vector< std::string > users()
std::string get_mail(const std::string &user)
Used in send_mail().
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
std::string get_password(const std::string &user)
GLuint const GLchar * name
void set_is_moderator(const std::string &name, const bool &is_moderator)
Mark this user as a moderator.
void set_user_detail(const std::string &user, const std::string &detail, const std::string &value)
Set data for a given user name.
bool user_is_active(const std::string &name)
Returns true if the specified user account is usable for logins.
std::string get_realname(const std::string &user)
void remove_user(const std::string &name)
Removes a user.
A config object defines a single node in a WML file, with access to child nodes.
void add_user(const std::string &name, const std::string &mail, const std::string &password)
Adds a user.
Thrown when a lexical_cast fails.
GLsizei const GLcharARB ** string
std::string user_info(const std::string &name)
Returns a string containing info like the last login of this user.
time_t get_registrationdate(const std::string &user)