The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
suh Class Reference

An example of how to implement user_handler. More...

#include <sample_user_handler.hpp>

Inheritance diagram for suh:
Inheritance graph

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::stringusers ()
 

Private Attributes

int user_expiration_
 
std::map< std::string, userusers_
 

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

suh::suh ( config  c)

Definition at line 23 of file sample_user_handler.cpp.

References user_expiration_.

Member Function Documentation

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 40 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 mail)
private

Definition at line 161 of file sample_user_handler.cpp.

Referenced by set_mail().

void suh::check_name ( const std::string name)
private

Definition at line 150 of file sample_user_handler.cpp.

References error(), and utils::isvalid_username().

void suh::check_password ( const std::string password)
private

Definition at line 165 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 171 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 178 of file sample_user_handler.cpp.

References get_lastlogin(), remove_user(), user_expiration_, and users().

std::string suh::create_pepper ( const std::string username)
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.

time_t suh::get_lastlogin ( const std::string user)
private

Definition at line 140 of file sample_user_handler.cpp.

References users_.

Referenced by clean_up(), and user_info().

std::string suh::get_mail ( const std::string user)
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_.

std::string suh::get_password ( const std::string user)
private

Definition at line 132 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 136 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 144 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 88 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 203 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 211 of file sample_user_handler.cpp.

References get_password(), game_logic::msg(), 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 51 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 98 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 122 of file sample_user_handler.cpp.

References users_.

Referenced by user_logged_in().

void suh::set_mail ( const std::string user,
const std::string mail 
)
private

Definition at line 103 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 108 of file sample_user_handler.cpp.

References check_password(), preferences::prv::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 113 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 76 of file sample_user_handler.cpp.

References error(), get_valid_details(), set_mail(), set_password(), and set_realname().

bool suh::use_phpbb_encryption ( ) const
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.

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 57 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 217 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 63 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 93 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 207 of file sample_user_handler.cpp.

References set_lastlogin().

Referenced by add_user().

std::vector< std::string > suh::users ( )
private

Definition at line 68 of file sample_user_handler.cpp.

References users_.

Referenced by clean_up().

Member Data Documentation

int suh::user_expiration_
private

Definition at line 91 of file sample_user_handler.hpp.

Referenced by clean_up(), and suh().

std::map<std::string,user> suh::users_
private

The documentation for this class was generated from the following files: