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. | |
| void | remove_user (const std::string &name) |
| Removes a user. | |
| void | clean_up () |
| Called by the server once a day. | |
| 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 | user_logged_in (const std::string &name) |
| Executed when the user with the given name logged in. | |
| void | password_reminder (const std::string &name) |
| Send a password reminder email to the given user. | |
| bool | user_exists (const std::string &name) |
| Returns true if a user with the given name exists. | |
| bool | user_is_active (const std::string &name) |
| Returns true if the specified user account is usable for logins. | |
| bool | user_is_moderator (const std::string &name) |
| Returns true if this user is a moderator on this server. | |
| void | set_is_moderator (const std::string &name, const bool &is_moderator) |
| Mark this user as a moderator. | |
| std::string | user_info (const std::string &name) |
| Returns a string containing info like the last login of this user. | |
| void | set_user_detail (const std::string &user, const std::string &detail, const std::string &value) |
| Set data for a given user name. | |
| std::string | get_valid_details () |
| List of details that can be set for this user_handler. | |
| std::string | create_pepper (const std::string &) |
| Create custom salt. | |
| bool | use_phpbb_encryption () const |
| Does this user_handler want passwords passed encrypted using phpbb's algorithm? | |
Private Member Functions | |
| std::string | get_mail (const std::string &user) |
| Used in send_mail(). | |
| 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_ |
An example of how to implement user_handler.
If you use this on anything real, you are insane.
Definition at line 30 of file sample_user_handler.hpp.
| suh::suh | ( | config | c | ) |
Definition at line 24 of file sample_user_handler.cpp.
References user_expiration_.
| void suh::add_user | ( | const std::string & | name, | |
| const std::string & | mail, | |||
| const std::string & | password | |||
| ) | [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 41 of file sample_user_handler.cpp.
References error(), set_mail(), set_password(), user_exists(), user_logged_in(), and users_.

| void suh::check_mail | ( | const std::string & | ) | [private] |
Definition at line 162 of file sample_user_handler.cpp.
Referenced by set_mail().

| void suh::check_name | ( | const std::string & | name | ) | [private] |
Definition at line 151 of file sample_user_handler.cpp.
References error(), and utils::isvalid_username().

| void suh::check_password | ( | const std::string & | password | ) | [private] |
Definition at line 166 of file sample_user_handler.cpp.
References error(), and utils::isvalid_username().
Referenced by set_password().


| void suh::check_realname | ( | const std::string & | realname | ) | [private] |
Definition at line 172 of file sample_user_handler.cpp.
References error().
Referenced by set_realname().


| void suh::clean_up | ( | ) | [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 179 of file sample_user_handler.cpp.
References get_lastlogin(), remove_user(), user_expiration_, and users().

| std::string suh::create_pepper | ( | const std::string & | username | ) | [inline, virtual] |
Create custom salt.
If not needed let it return and empty string or whatever you feel like.
Implements user_handler.
Definition at line 71 of file sample_user_handler.hpp.
| time_t suh::get_lastlogin | ( | const std::string & | user | ) | [private] |
Definition at line 141 of file sample_user_handler.cpp.
References users_.
Referenced by clean_up(), and user_info().

| std::string suh::get_mail | ( | const std::string & | user | ) | [private, virtual] |
Used in send_mail().
Should return an empty string when not used.
Implements user_handler.
Definition at line 129 of file sample_user_handler.cpp.
References users_.
| std::string suh::get_password | ( | const std::string & | user | ) | [private] |
Definition at line 133 of file sample_user_handler.cpp.
References users_.
Referenced by login(), and password_reminder().

| std::string suh::get_realname | ( | const std::string & | user | ) | [private] |
Definition at line 137 of file sample_user_handler.cpp.
References users_.
Referenced by user_info().

| time_t suh::get_registrationdate | ( | const std::string & | user | ) | [private] |
Definition at line 145 of file sample_user_handler.cpp.
References users_.
Referenced by user_info().

| std::string suh::get_valid_details | ( | ) | [virtual] |
List of details that can be set for this user_handler.
Implements user_handler.
Definition at line 89 of file sample_user_handler.cpp.
Referenced by set_user_detail().

| bool suh::login | ( | const std::string & | name, | |
| const std::string & | password, | |||
| const std::string & | seed | |||
| ) | [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 204 of file sample_user_handler.cpp.
References get_password().

| void suh::password_reminder | ( | const std::string & | name | ) | [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 212 of file sample_user_handler.cpp.
References get_password(), and user_handler::send_mail().

| void suh::remove_user | ( | const std::string & | name | ) | [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 52 of file sample_user_handler.cpp.
References error(), user_exists(), and users_.
Referenced by clean_up().


| void suh::set_is_moderator | ( | const std::string & | name, | |
| const bool & | is_moderator | |||
| ) | [virtual] |
Mark this user as a moderator.
Implements user_handler.
Definition at line 99 of file sample_user_handler.cpp.
References user_exists(), and users_.

| void suh::set_lastlogin | ( | const std::string & | user, | |
| const time_t & | lastlogin | |||
| ) | [private] |
Definition at line 123 of file sample_user_handler.cpp.
References users_.
Referenced by user_logged_in().

| void suh::set_mail | ( | const std::string & | user, | |
| const std::string & | ||||
| ) | [private] |
Definition at line 104 of file sample_user_handler.cpp.
References check_mail(), and users_.
Referenced by add_user(), and set_user_detail().


| void suh::set_password | ( | const std::string & | user, | |
| const std::string & | password | |||
| ) | [private] |
Definition at line 109 of file sample_user_handler.cpp.
References check_password(), and users_.
Referenced by add_user(), and set_user_detail().


| void suh::set_realname | ( | const std::string & | user, | |
| const std::string & | realname | |||
| ) | [private] |
Definition at line 114 of file sample_user_handler.cpp.
References check_realname(), and users_.
Referenced by set_user_detail().


| void suh::set_user_detail | ( | const std::string & | user, | |
| const std::string & | detail, | |||
| const std::string & | value | |||
| ) | [virtual] |
Set data for a given user name.
Should throw an error on invalid data.
Implements user_handler.
Definition at line 77 of file sample_user_handler.cpp.
References error(), get_valid_details(), set_mail(), set_password(), and set_realname().

| bool suh::use_phpbb_encryption | ( | ) | const [inline, virtual] |
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 72 of file sample_user_handler.hpp.
| bool suh::user_exists | ( | const std::string & | name | ) | [virtual] |
Returns true if a user with the given name exists.
Implements user_handler.
Definition at line 58 of file sample_user_handler.cpp.
References users_.
Referenced by add_user(), remove_user(), set_is_moderator(), user_info(), and user_is_moderator().

| std::string suh::user_info | ( | const std::string & | name | ) | [virtual] |
Returns a string containing info like the last login of this user.
Formatted for user readable output.
Implements user_handler.
Definition at line 218 of file sample_user_handler.cpp.
References error(), get_lastlogin(), get_realname(), get_registrationdate(), lg::info, user_exists(), and user_is_active().

| bool suh::user_is_active | ( | const std::string & | name | ) | [virtual] |
Returns true if the specified user account is usable for logins.
Implements user_handler.
Definition at line 64 of file sample_user_handler.cpp.
Referenced by user_info().

| bool suh::user_is_moderator | ( | const std::string & | name | ) | [virtual] |
Returns true if this user is a moderator on this server.
Implements user_handler.
Definition at line 94 of file sample_user_handler.cpp.
References user_exists(), and users_.

| void suh::user_logged_in | ( | const std::string & | name | ) | [virtual] |
Executed when the user with the given name logged in.
Implements user_handler.
Definition at line 208 of file sample_user_handler.cpp.
References set_lastlogin().
Referenced by add_user().


| std::vector< std::string > suh::users | ( | ) | [private] |
Definition at line 69 of file sample_user_handler.cpp.
References users_.
Referenced by clean_up().

int suh::user_expiration_ [private] |
Definition at line 92 of file sample_user_handler.hpp.
Referenced by clean_up(), and suh().
std::map<std::string,user> suh::users_ [private] |
Definition at line 94 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().
| Generated by doxygen 1.7.1 on Thu May 24 2012 01:16:05 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |