The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
forum_user_handler.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Thomas Baumhauer <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef FORUM_USER_HANDLER_HPP_INCLUDED
16 #define FORUM_USER_HANDLER_HPP_INCLUDED
17 
18 #include "user_handler.hpp"
19 
20 #include <vector>
21 #include <memory>
22 
23 #include <mysql/mysql.h>
24 
25 // The [user_handler] section in the server configuration
26 // file could look like this:
27 //
28 //[user_handler]
29 // db_name=phpbb3
30 // db_host=localhost
31 // db_user=root
32 // db_password=secret
33 // db_users_table=users
34 // db_extra_table=extra_data
35 //[/user_handler]
36 
37 /**
38  * A user_handler implementation to link the server with a phpbb3 forum.
39  */
40 class fuh : public user_handler {
41  public:
42  fuh(const config& c);
43  ~fuh();
44 
45  // Throws user_handler::error
46  void add_user(const std::string& name, const std::string& mail, const std::string& password);
47 
48  // Throws user_handler::error
49  void remove_user(const std::string& name);
50 
51  void clean_up() {}
52 
53  bool login(const std::string& name, const std::string& password, const std::string& seed);
54 
55  /**
56  * Needed because the hashing algorithm used by phpbb requires some info
57  * from the original hash to recreate the same hash
58  *
59  * Return an empty string if an error occurs
60  */
62 
63  void user_logged_in(const std::string& name);
64 
65  bool user_exists(const std::string& name);
66 
67  bool user_is_active(const std::string& name);
68 
69  bool user_is_moderator(const std::string& name);
70  void set_is_moderator(const std::string& name, const bool& is_moderator);
71 
72  // Throws user_handler::error
73  void password_reminder(const std::string& name);
74 
75  // Throws user_handler::error
76  std::string user_info(const std::string& name);
77 
78  // Throws user_handler::error
79  void set_user_detail(const std::string& user, const std::string& detail, const std::string& value);
81 
82  bool use_phpbb_encryption() const { return true; }
83 
84  private:
85  std::string get_hash(const std::string& user);
86  std::string get_mail(const std::string& user);
87  /*std::vector<std::string> get_friends(const std::string& user);
88  std::vector<std::string> get_ignores(const std::string& user);*/
89  time_t get_lastlogin(const std::string& user);
90  time_t get_registrationdate(const std::string& user);
91  bool is_inactive(const std::string& user);
92 
93  void set_lastlogin(const std::string& user, const time_t& lastlogin);
94 
96 
97  typedef std::unique_ptr<MYSQL_RES, decltype(&mysql_free_result)> mysql_result;
98 
99  // Throws user_handler::error
100  mysql_result db_query(const std::string& query);
101 
102  // Throws user_handler::error via db_query()
104  MYSQL *conn;
105 
106  // Query a detail for a particular user from the database
109 
110  // Write something to the write table
111  void write_detail(const std::string& name, const std::string& detail, const std::string& value);
112 
113  // Same as user_exists() but checks if we have a row for this user in the extra table
114  bool extra_row_exists(const std::string& name);
115 };
116 
117 #endif //FORUM_USER_HANDLER_HPP_INCLUDED
std::string get_hash(const std::string &user)
std::string db_query_to_string(const std::string &query)
void password_reminder(const std::string &name)
Send a password reminder email to the given 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 create_pepper(const std::string &name)
Needed because the hashing algorithm used by phpbb requires some info from the original hash to recre...
const GLfloat * c
Definition: glew.h:12741
std::unique_ptr< MYSQL_RES, decltype(&mysql_free_result)> mysql_result
std::string db_host_
bool is_inactive(const std::string &user)
void user_logged_in(const std::string &name)
Executed when the user with the given name logged in.
void clean_up()
Called by the server once a day.
std::string db_name_
void set_lastlogin(const std::string &user, const time_t &lastlogin)
void add_user(const std::string &name, const std::string &mail, const std::string &password)
Adds a user.
std::string user_info(const std::string &name)
Returns a string containing info like the last login of this user.
bool user_exists(const std::string &name)
Returns true if a user with the given name exists.
void set_is_moderator(const std::string &name, const bool &is_moderator)
Mark this user as a moderator.
fuh(const config &c)
mysql_result db_query(const std::string &query)
A user_handler implementation to link the server with a phpbb3 forum.
bool extra_row_exists(const std::string &name)
std::string get_writable_detail_for_user(const std::string &name, const std::string &detail)
bool use_phpbb_encryption() const
Does this user_handler want passwords passed encrypted using phpbb's algorithm?
GLsizei const GLfloat * value
Definition: glew.h:1817
An interface class to handle nick registration To activate it put a [user_handler] section into the s...
time_t get_lastlogin(const std::string &user)
std::string db_password_
bool login(const std::string &name, const std::string &password, const std::string &seed)
Return true if the given password matches the password for the given user.
std::string db_extra_table_
bool user_is_active(const std::string &name)
Returns true if the specified user account is usable for logins.
time_t get_registrationdate(const std::string &user)
~fuh()
std::string db_users_table_
bool user_is_moderator(const std::string &name)
Returns true if this user is a moderator on this server.
std::string db_user_
GLuint const GLchar * name
Definition: glew.h:1782
void write_detail(const std::string &name, const std::string &detail, const std::string &value)
std::string get_mail(const std::string &user)
Used in send_mail().
MYSQL * conn
void remove_user(const std::string &name)
Removes a user.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
std::string get_valid_details()
List of details that can be set for this user_handler.
GLenum query
Definition: glew.h:4185
GLsizei const GLcharARB ** string
Definition: glew.h:4503
std::string get_detail_for_user(const std::string &name, const std::string &detail)