server/forum_user_handler.hpp

Go to the documentation of this file.
00001 /* $Id: forum_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 FORUM_USER_HANDLER_HPP_INCLUDED
00017 #define FORUM_USER_HANDLER_HPP_INCLUDED
00018 
00019 #include "user_handler.hpp"
00020 
00021 #include <vector>
00022 
00023 #include <mysql/mysql.h>
00024 
00025 // The [user_handler] section in the server configuration
00026 // file could look like this:
00027 //
00028 //[user_handler]
00029 //  db_name=phpbb3
00030 //  db_host=localhost
00031 //  db_user=root
00032 //  db_password=secret
00033 //  db_users_table=users
00034 //  db_extra_table=extra_data
00035 //[/user_handler]
00036 
00037 /**
00038  * A user_handler implementation to link the server with a phpbb3 forum.
00039  */
00040 class fuh : public user_handler {
00041     public:
00042         fuh(const config& c);
00043         ~fuh();
00044 
00045         // Throws user_handler::error
00046         void add_user(const std::string& name, const std::string& mail, const std::string& password);
00047 
00048         // Throws user_handler::error
00049         void remove_user(const std::string& name);
00050 
00051         void clean_up() {}
00052 
00053         bool login(const std::string& name, const std::string& password, const std::string& seed);
00054 
00055         /**
00056          * Needed because the hashing algorithm used by phpbb requires some info
00057          * from the original hash to recreate the same hash
00058          *
00059          * Return an empty string if an error occurs
00060          */
00061         std::string create_pepper(const std::string& name);
00062 
00063         void user_logged_in(const std::string& name);
00064 
00065         bool user_exists(const std::string& name);
00066 
00067         bool user_is_active(const std::string& name);
00068 
00069         bool user_is_moderator(const std::string& name);
00070         void set_is_moderator(const std::string& name, const bool& is_moderator);
00071 
00072         // Throws user_handler::error
00073         void password_reminder(const std::string& name);
00074 
00075         // Throws user_handler::error
00076         std::string user_info(const std::string& name);
00077 
00078         // Throws user_handler::error
00079         void set_user_detail(const std::string& user, const std::string& detail, const std::string& value);
00080         std::string get_valid_details();
00081 
00082         bool use_phpbb_encryption() const { return true; }
00083 
00084     private:
00085         std::string get_hash(const std::string& user);
00086         std::string get_mail(const std::string& user);
00087         /*std::vector<std::string> get_friends(const std::string& user);
00088         std::vector<std::string> get_ignores(const std::string& user);*/
00089         time_t get_lastlogin(const std::string& user);
00090         time_t get_registrationdate(const std::string& user);
00091         bool is_inactive(const std::string& user);
00092 
00093         void set_lastlogin(const std::string& user, const time_t& lastlogin);
00094 
00095         std::string db_name_, db_host_, db_user_, db_password_, db_users_table_, db_extra_table_;
00096 
00097         // Throws user_handler::error
00098         MYSQL_RES* db_query(const std::string& query);
00099 
00100         // Throws user_handler::error via db_query()
00101         std::string db_query_to_string(const std::string& query);
00102         MYSQL *conn;
00103 
00104         // Query a detail for a particular user from the database
00105         std::string get_detail_for_user(const std::string& name, const std::string& detail);
00106         std::string get_writable_detail_for_user(const std::string& name, const std::string& detail);
00107 
00108         // Write something to the write table
00109         void write_detail(const std::string& name, const std::string& detail, const std::string& value);
00110 
00111         // Same as user_exists() but checks if we have a row for this user in the extra table
00112         bool extra_row_exists(const std::string& name);
00113 };
00114 
00115 #endif //FORUM_USER_HANDLER_HPP_INCLUDED
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:09 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs