The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sample_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 SAMPLE_USER_HANDLER_HPP_INCLUDED
16 #define SAMPLE_USER_HANDLER_HPP_INCLUDED
17 
18 #include "user_handler.hpp"
19 
20 #include <map>
21 #include <vector>
22 
23 #include <ctime>
24 
25 /**
26  * An example of how to implement user_handler.
27  * If you use this on anything real, you are insane.
28  */
29 class suh : public user_handler {
30  public:
31  suh(config c);
32 
33  void add_user(const std::string& name, const std::string& mail, const std::string& password);
34  void remove_user(const std::string& name);
35 
36  void clean_up();
37 
38  bool login(const std::string& name, const std::string& password, const std::string&);
39  void user_logged_in(const std::string& name);
40 
41  void password_reminder(const std::string& name);
42 
43  bool user_exists(const std::string& name);
44  bool user_is_active(const std::string& name);
45 
46  bool user_is_moderator(const std::string& name);
47  void set_is_moderator(const std::string& name, const bool& is_moderator);
48 
49  std::string user_info(const std::string& name);
50 
51  struct user {
52  user() :
53  password(),
54  realname(),
55  mail(),
56  lastlogin(time(nullptr)),
57  registrationdate(time(nullptr)),
58  is_moderator(false) {}
62  time_t lastlogin;
65  };
66 
67  void set_user_detail(const std::string& user, const std::string& detail, const std::string& value);
69 
70  std::string create_pepper(const std::string&) { return ""; }
71  bool use_phpbb_encryption() const { return false; }
72 
73  private:
74  std::string get_mail(const std::string& user);
76  std::string get_realname(const std::string& user) ;
77  time_t get_lastlogin(const std::string& user);
78  time_t get_registrationdate(const std::string& user);
79 
80  void check_name(const std::string& name);
81  void check_mail(const std::string& mail);
82  void check_password(const std::string& password);
83  void check_realname(const std::string& realname);
84 
85  void set_mail(const std::string& user, const std::string& mail);
86  void set_password(const std::string& user, const std::string& password);
87  void set_realname(const std::string& user, const std::string& realname);
88 
89  void set_lastlogin(const std::string& user, const time_t& lastlogin);
90 
92 
93  std::map <std::string,user> users_;
94  std::vector<std::string> users();
95 };
96 
97 #endif //SAMPLE_USER_HANDLER_HPP_INCLUDED
void set_mail(const std::string &user, const std::string &mail)
void check_mail(const std::string &mail)
bool user_is_moderator(const std::string &name)
Returns true if this user is a moderator on this server.
void clean_up()
Called by the server once a day.
const GLfloat * c
Definition: glew.h:12741
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.
std::string create_pepper(const std::string &)
Create custom salt.
void set_lastlogin(const std::string &user, const time_t &lastlogin)
suh(config c)
An example of how to implement user_handler.
std::string get_valid_details()
List of details that can be set for this user_handler.
void check_realname(const std::string &realname)
void check_name(const std::string &name)
void password_reminder(const std::string &name)
Send a password reminder email to the given user.
std::map< std::string, user > users_
GLsizei const GLfloat * value
Definition: glew.h:1817
std::string password
void set_realname(const std::string &user, const std::string &realname)
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)
void user_logged_in(const std::string &name)
Executed when the user with the given name logged in.
void set_password(const std::string &user, const std::string &password)
bool user_exists(const std::string &name)
Returns true if a user with the given name exists.
void check_password(const std::string &password)
std::vector< std::string > users()
std::string get_mail(const std::string &user)
Used in send_mail().
bool use_phpbb_encryption() const
Does this user_handler want passwords passed encrypted using phpbb's algorithm?
std::string get_password(const std::string &user)
GLuint const GLchar * name
Definition: glew.h:1782
void set_is_moderator(const std::string &name, const bool &is_moderator)
Mark this user as a moderator.
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 mail
bool user_is_active(const std::string &name)
Returns true if the specified user account is usable for logins.
std::string get_realname(const std::string &user)
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
void add_user(const std::string &name, const std::string &mail, const std::string &password)
Adds a user.
int user_expiration_
GLsizei const GLcharARB ** string
Definition: glew.h:4503
std::string realname
std::string user_info(const std::string &name)
Returns a string containing info like the last login of this user.
time_t get_registrationdate(const std::string &user)