An example of how to implement user_handler. More...
#include <sample_user_handler.hpp>
Classes | |
struct | user |
Public Member Functions | |
suh (config c) | |
void | add_user (const std::string &name, const std::string &mail, const std::string &password) |
Adds a user. More... | |
void | remove_user (const std::string &name) |
Removes a user. More... | |
void | clean_up () |
Called by the server once a day. More... | |
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. More... | |
void | user_logged_in (const std::string &name) |
Executed when the user with the given name logged in. More... | |
void | password_reminder (const std::string &name) |
Send a password reminder email to the given user. More... | |
bool | user_exists (const std::string &name) |
Returns true if a user with the given name exists. More... | |
bool | user_is_active (const std::string &name) |
Returns true if the specified user account is usable for logins. More... | |
bool | user_is_moderator (const std::string &name) |
Returns true if this user is a moderator on this server. More... | |
void | set_is_moderator (const std::string &name, const bool &is_moderator) |
Mark this user as a moderator. More... | |
std::string | user_info (const std::string &name) |
Returns a string containing info like the last login of this user. More... | |
void | set_user_detail (const std::string &user, const std::string &detail, const std::string &value) |
Set data for a given user name. More... | |
std::string | get_valid_details () |
List of details that can be set for this user_handler. More... | |
std::string | create_pepper (const std::string &) |
Create custom salt. More... | |
bool | use_phpbb_encryption () const |
Does this user_handler want passwords passed encrypted using phpbb's algorithm? More... | |
Public Member Functions inherited from user_handler | |
user_handler () | |
virtual | ~user_handler () |
void | init_mailer (const config &c) |
Initiate the mailer object. More... | |
std::string | create_salt (int length=8) |
Create a random string of digits for password encryption. More... | |
Private Member Functions | |
std::string | get_mail (const std::string &user) |
Used in send_mail(). More... | |
std::string | get_password (const std::string &user) |
std::string | get_realname (const std::string &user) |
time_t | get_lastlogin (const std::string &user) |
time_t | get_registrationdate (const std::string &user) |
void | check_name (const std::string &name) |
void | check_mail (const std::string &mail) |
void | check_password (const std::string &password) |
void | check_realname (const std::string &realname) |
void | set_mail (const std::string &user, const std::string &mail) |
void | set_password (const std::string &user, const std::string &password) |
void | set_realname (const std::string &user, const std::string &realname) |
void | set_lastlogin (const std::string &user, const time_t &lastlogin) |
std::vector< std::string > | users () |
Private Attributes | |
int | user_expiration_ |
std::map< std::string, user > | users_ |
Additional Inherited Members | |
Protected Member Functions inherited from user_handler | |
bool | send_mail (const std::string &to_user, const std::string &subject, const std::string &message) |
Sends an email to the specified address. More... | |
An example of how to implement user_handler.
If you use this on anything real, you are insane.
Definition at line 29 of file sample_user_handler.hpp.
suh::suh | ( | config | c | ) |
Definition at line 23 of file sample_user_handler.cpp.
References user_expiration_.
|
virtual |
Adds a user.
Throws an error containing the error message if adding fails (e.g. because a user with the same name already exists).
Implements user_handler.
Definition at line 40 of file sample_user_handler.cpp.
References error(), set_mail(), set_password(), user_exists(), user_logged_in(), and users_.
|
private |
Definition at line 161 of file sample_user_handler.cpp.
Referenced by set_mail().
|
private |
Definition at line 150 of file sample_user_handler.cpp.
References error(), and utils::isvalid_username().
|
private |
Definition at line 165 of file sample_user_handler.cpp.
References error(), and utils::isvalid_username().
Referenced by set_password().
|
private |
Definition at line 171 of file sample_user_handler.cpp.
References error().
Referenced by set_realname().
|
virtual |
Called by the server once a day.
Could for example be used for removing users that have not logged in for a certain amount of time.
Implements user_handler.
Definition at line 178 of file sample_user_handler.cpp.
References get_lastlogin(), remove_user(), user_expiration_, and users().
|
inlinevirtual |
Create custom salt.
If not needed let it return and empty string or whatever you feel like.
Implements user_handler.
Definition at line 70 of file sample_user_handler.hpp.
|
private |
Definition at line 140 of file sample_user_handler.cpp.
References users_.
Referenced by clean_up(), and user_info().
|
privatevirtual |
Used in send_mail().
Should return an empty string when not used.
Implements user_handler.
Definition at line 128 of file sample_user_handler.cpp.
References users_.
|
private |
Definition at line 132 of file sample_user_handler.cpp.
References users_.
Referenced by login(), and password_reminder().
|
private |
Definition at line 136 of file sample_user_handler.cpp.
References users_.
Referenced by user_info().
|
private |
Definition at line 144 of file sample_user_handler.cpp.
References users_.
Referenced by user_info().
|
virtual |
List of details that can be set for this user_handler.
Implements user_handler.
Definition at line 88 of file sample_user_handler.cpp.
Referenced by set_user_detail().
|
virtual |
Return true if the given password matches the password for the given user.
Password could also be a hash Seed is not needed for clear text log ins Currently the login procedure in the server and client code is hardcoded for the forum_user_handler implementation
Implements user_handler.
Definition at line 203 of file sample_user_handler.cpp.
References get_password().
|
virtual |
Send a password reminder email to the given user.
Should throw user_handler::error if sending fails (e.g. because we cannot send email).
Implements user_handler.
Definition at line 211 of file sample_user_handler.cpp.
References get_password(), game_logic::msg(), and user_handler::send_mail().
|
virtual |
Removes a user.
Throws an error containing the error message if removing fails (e.g. no user with the given name exists).
Implements user_handler.
Definition at line 51 of file sample_user_handler.cpp.
References error(), user_exists(), and users_.
Referenced by clean_up().
|
virtual |
Mark this user as a moderator.
Implements user_handler.
Definition at line 98 of file sample_user_handler.cpp.
References user_exists(), and users_.
|
private |
Definition at line 122 of file sample_user_handler.cpp.
References users_.
Referenced by user_logged_in().
|
private |
Definition at line 103 of file sample_user_handler.cpp.
References check_mail(), and users_.
Referenced by add_user(), and set_user_detail().
|
private |
Definition at line 108 of file sample_user_handler.cpp.
References check_password(), preferences::prv::password, and users_.
Referenced by add_user(), and set_user_detail().
|
private |
Definition at line 113 of file sample_user_handler.cpp.
References check_realname(), and users_.
Referenced by set_user_detail().
|
virtual |
Set data for a given user name.
Should throw an error on invalid data.
Implements user_handler.
Definition at line 76 of file sample_user_handler.cpp.
References error(), get_valid_details(), set_mail(), set_password(), and set_realname().
|
inlinevirtual |
Does this user_handler want passwords passed encrypted using phpbb's algorithm?
Let it return true if it does and false if it does not.
Implements user_handler.
Definition at line 71 of file sample_user_handler.hpp.
|
virtual |
Returns true if a user with the given name exists.
Implements user_handler.
Definition at line 57 of file sample_user_handler.cpp.
References users_.
Referenced by add_user(), remove_user(), set_is_moderator(), user_info(), and user_is_moderator().
|
virtual |
Returns a string containing info like the last login of this user.
Formatted for user readable output.
Implements user_handler.
Definition at line 217 of file sample_user_handler.cpp.
References error(), get_lastlogin(), get_realname(), get_registrationdate(), lg::info(), user_exists(), and user_is_active().
|
virtual |
Returns true if the specified user account is usable for logins.
Implements user_handler.
Definition at line 63 of file sample_user_handler.cpp.
Referenced by user_info().
|
virtual |
Returns true if this user is a moderator on this server.
Implements user_handler.
Definition at line 93 of file sample_user_handler.cpp.
References user_exists(), and users_.
|
virtual |
Executed when the user with the given name logged in.
Implements user_handler.
Definition at line 207 of file sample_user_handler.cpp.
References set_lastlogin().
Referenced by add_user().
|
private |
|
private |
Definition at line 91 of file sample_user_handler.hpp.
Referenced by clean_up(), and suh().
|
private |
Definition at line 93 of file sample_user_handler.hpp.
Referenced by add_user(), get_lastlogin(), get_mail(), get_password(), get_realname(), get_registrationdate(), remove_user(), set_is_moderator(), set_lastlogin(), set_mail(), set_password(), set_realname(), user_exists(), user_is_moderator(), and users().