| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #ifndef GUARD_DB_USER_HH |
|---|
| 21 | #define GUARD_DB_USER_HH |
|---|
| 22 | |
|---|
| 23 | #include "password_handler.hh" |
|---|
| 24 | #include "../server.hh" |
|---|
| 25 | |
|---|
| 26 | #include <boost/enable_shared_from_this.hpp> |
|---|
| 27 | #include <boost/noncopyable.hpp> |
|---|
| 28 | #include <boost/shared_ptr.hpp> |
|---|
| 29 | #include <set> |
|---|
| 30 | #include <string> |
|---|
| 31 | |
|---|
| 32 | namespace db |
|---|
| 33 | { |
|---|
| 34 | class db; |
|---|
| 35 | class group; |
|---|
| 36 | class msg; |
|---|
| 37 | class role; |
|---|
| 38 | |
|---|
| 39 | class user : public boost::noncopyable |
|---|
| 40 | , public boost::enable_shared_from_this<user> |
|---|
| 41 | { |
|---|
| 42 | std::string userid; |
|---|
| 43 | std::string display_name; |
|---|
| 44 | std::string display_email; |
|---|
| 45 | std::string delivery_email; |
|---|
| 46 | bool do_allow_cleartext_password; |
|---|
| 47 | bool delivery_email_verified; |
|---|
| 48 | std::string delivery_email_cookie; |
|---|
| 49 | |
|---|
| 50 | boost::shared_ptr<db> dbase; |
|---|
| 51 | boost::shared_ptr<password_handler> pwh; |
|---|
| 52 | |
|---|
| 53 | std::set< boost::shared_ptr<role> > roles; |
|---|
| 54 | |
|---|
| 55 | std::set<std::string> read_msgids; |
|---|
| 56 | |
|---|
| 57 | bool is_group_moderator(std::string) const; |
|---|
| 58 | |
|---|
| 59 | friend class db; |
|---|
| 60 | public: |
|---|
| 61 | typedef boost::shared_ptr<user> ptr; |
|---|
| 62 | typedef boost::shared_ptr<const user> const_ptr; |
|---|
| 63 | |
|---|
| 64 | user(std::string userid, |
|---|
| 65 | boost::shared_ptr<db> dbase, |
|---|
| 66 | boost::shared_ptr<password_handler> pwh); |
|---|
| 67 | |
|---|
| 68 | std::string get_userid() const { return userid; } |
|---|
| 69 | |
|---|
| 70 | std::string get_display_name() const { return display_name; } |
|---|
| 71 | void set_display_name(std::string); |
|---|
| 72 | |
|---|
| 73 | std::string get_display_email() const { return display_email; } |
|---|
| 74 | void set_display_email(std::string); |
|---|
| 75 | |
|---|
| 76 | std::string get_delivery_email() const { |
|---|
| 77 | return delivery_email; |
|---|
| 78 | } |
|---|
| 79 | bool set_delivery_email(std::string); |
|---|
| 80 | |
|---|
| 81 | bool is_delivery_email_verified() const { |
|---|
| 82 | return delivery_email_verified; |
|---|
| 83 | } |
|---|
| 84 | void send_delivery_email_cookie(server::conn_cb cb, |
|---|
| 85 | std::string request_ip); |
|---|
| 86 | bool verify_delivery_email(std::string cookie, |
|---|
| 87 | server::conn_cb cb); |
|---|
| 88 | |
|---|
| 89 | bool allow_cleartext_password() const { |
|---|
| 90 | return do_allow_cleartext_password; |
|---|
| 91 | } |
|---|
| 92 | void set_allow_cleartext_password(bool); |
|---|
| 93 | |
|---|
| 94 | bool verify_password(std::string s) const { |
|---|
| 95 | return pwh->verify_password(userid, s); |
|---|
| 96 | } |
|---|
| 97 | void set_password(std::string s) { |
|---|
| 98 | pwh->set_password(userid, s); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | const std::set<boost::shared_ptr<role> > &get_roles() const { |
|---|
| 102 | return roles; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | void add_role(boost::shared_ptr<role> r); |
|---|
| 106 | |
|---|
| 107 | void delete_role(boost::shared_ptr<role> r); |
|---|
| 108 | |
|---|
| 109 | bool has_read(std::string msgid) const { |
|---|
| 110 | return read_msgids.find(msgid) != read_msgids.end(); |
|---|
| 111 | } |
|---|
| 112 | void mark_read(std::string msgid); |
|---|
| 113 | void unmark_read(std::string msgid); |
|---|
| 114 | |
|---|
| 115 | bool is_moderator(boost::shared_ptr<const group> gr) const; |
|---|
| 116 | bool is_moderator(boost::shared_ptr<const msg> m) const; |
|---|
| 117 | |
|---|
| 118 | static std::string passwd_problems(std::string pw) { |
|---|
| 119 | std::string err; |
|---|
| 120 | if (pw.length() < 6) err += "Password is too short. "; |
|---|
| 121 | if (pw.find_first_of(" \t") != std::string::npos) |
|---|
| 122 | err += "Password contains a space or a tab. "; |
|---|
| 123 | return err; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | boost::shared_ptr<db> get_db() const { return dbase; }; |
|---|
| 127 | }; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | #endif |
|---|