00001 /* $Id: user_handler.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */ 00002 /* 00003 Copyright (C) 2008 - 2012 by Thomas Baumhauer <thomas.baumhauer@NOSPAMgmail.com> 00004 Part of the Battle for Wesnoth Project http://www.wesnoth.org/ 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY. 00012 00013 See the COPYING file for more details. 00014 */ 00015 00016 #ifndef USER_HANDLER_HPP_INCLUDED 00017 #define USER_HANDLER_HPP_INCLUDED 00018 00019 class config; 00020 00021 #include "../exceptions.hpp" 00022 #include "../global.hpp" 00023 00024 #include <string> 00025 00026 /** 00027 * An interface class to handle nick registration 00028 * To activate it put a [user_handler] section into the 00029 * server configuration file 00030 */ 00031 class user_handler { 00032 00033 // public functions are called by the server 00034 // 00035 // private functions are for convenience as they 00036 // will probably be the same for all user_handler 00037 // implementations 00038 00039 public: 00040 user_handler() 00041 { 00042 } 00043 00044 virtual ~user_handler() 00045 { 00046 } 00047 00048 /** 00049 * Adds a user. 00050 * 00051 * Throws an error containing the error message if adding fails 00052 * (e.g. because a user with the same name already exists). 00053 */ 00054 virtual void add_user(const std::string& name, const std::string& mail, const std::string& password) =0; 00055 00056 /** 00057 * Removes a user. 00058 * 00059 * Throws an error containing the error message if removing fails 00060 * (e.g. no user with the given name exists). 00061 */ 00062 virtual void remove_user(const std::string& name) =0; 00063 00064 /** 00065 * Called by the server once a day. 00066 * 00067 * Could for example be used for removing users that have not logged in 00068 * for a certain amount of time. 00069 */ 00070 virtual void clean_up() =0; 00071 00072 /** 00073 * Send a password reminder email to the given user. 00074 * 00075 * Should throw user_handler::error if sending fails 00076 * (e.g. because we cannot send email). 00077 */ 00078 virtual void password_reminder(const std::string& name) =0; 00079 00080 /** 00081 * Return true if the given password matches the password for the given user. 00082 * 00083 * Password could also be a hash 00084 * Seed is not needed for clear text log ins 00085 * Currently the login procedure in the server and client code is hardcoded 00086 * for the forum_user_handler implementation 00087 */ 00088 virtual bool login(const std::string& name, const std::string& password, const std::string& seed) =0; 00089 00090 /** Executed when the user with the given name logged in. */ 00091 virtual void user_logged_in(const std::string& name) =0; 00092 00093 /** 00094 * Returns a string containing info like the last login of this user. 00095 * 00096 * Formatted for user readable output. 00097 */ 00098 virtual std::string user_info(const std::string& name) =0; 00099 00100 /** 00101 * Set data for a given user name. 00102 * 00103 * Should throw an error on invalid data. 00104 */ 00105 virtual void set_user_detail(const std::string& user, const std::string& detail, const std::string& value) =0; 00106 00107 /** List of details that can be set for this user_handler. */ 00108 virtual std::string get_valid_details() =0; 00109 00110 /** Returns true if a user with the given name exists. */ 00111 virtual bool user_exists(const std::string& name) =0; 00112 00113 /** Returns true if the specified user account is usable for logins. */ 00114 virtual bool user_is_active(const std::string& name) =0; 00115 00116 /** Returns true if this user is a moderator on this server */ 00117 virtual bool user_is_moderator(const std::string& name) =0; 00118 00119 /** Mark this user as a moderator */ 00120 virtual void set_is_moderator(const std::string& name, const bool& is_moderator) =0; 00121 00122 struct error : public game::error { 00123 error(const std::string& message) : game::error(message) {} 00124 }; 00125 00126 /** Initiate the mailer object. */ 00127 void init_mailer(const config &c); 00128 00129 /** Create a random string of digits for password encryption. */ 00130 std::string create_salt(int length =8); 00131 00132 /** 00133 * Create custom salt. 00134 * 00135 * If not needed let it return and empty string or whatever you feel like. 00136 */ 00137 virtual std::string create_pepper(const std::string& username) =0; 00138 00139 /** 00140 * Does this user_handler want passwords passed encrypted using phpbb's algorithm? 00141 * 00142 * Let it return true if it does and false if it does not. 00143 */ 00144 virtual bool use_phpbb_encryption() const =0; 00145 00146 protected: 00147 00148 /** 00149 * Sends an email to the specified address. Requires access to an SMTP server. 00150 * 00151 * Throws an error if the mail could not be sent. 00152 */ 00153 bool send_mail(const std::string& to_user, const std::string& subject, const std::string& message); 00154 00155 /** 00156 * Used in send_mail(). 00157 * 00158 * Should return an empty string when not used. 00159 */ 00160 virtual std::string get_mail(const std::string& user) =0; 00161 }; 00162 00163 #endif //USER_HANDLER_HPP_INCLUDED
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:10 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |