#ifndef __USER_H__ #define __USER_H__ #include "Post.h" #include "Token.h" #include #include #include #include using Tokens = Wt::Dbo::collection>; class User { public: enum Role { Visitor = 0, Admin = 1, }; User(); static Wt::Dbo::dbo_traits::IdType stringToId(const std::string &s); Posts latestPosts(int count = 10) const; Posts allPosts(Post::State state) const; Wt::WString name; Role role; std::string password; std::string passwordMethod; std::string passwordSalt; int failedLoginAttempts; Wt::WDateTime lastLoginAttempt; std::string oAuthId; std::string oAuthProvider; Tokens authTokens; Comments comments; Posts posts; template void persist(Action &a) { Wt::Dbo::field(a, name, "name"); Wt::Dbo::field(a, password, "password"); Wt::Dbo::field(a, passwordMethod, "password_method"); Wt::Dbo::field(a, passwordSalt, "password_salt"); Wt::Dbo::field(a, role, "role"); Wt::Dbo::field(a, failedLoginAttempts, "failed_login_attempts"); Wt::Dbo::field(a, lastLoginAttempt, "last_login_attempt"); Wt::Dbo::field(a, oAuthId, "oauth_id"); Wt::Dbo::field(a, oAuthProvider, "oauth_provider"); Wt::Dbo::hasMany(a, comments, Wt::Dbo::ManyToOne, "author"); Wt::Dbo::hasMany(a, posts, Wt::Dbo::ManyToOne, "author"); Wt::Dbo::hasMany(a, authTokens, Wt::Dbo::ManyToOne, "user"); } }; DBO_EXTERN_TEMPLATES(User) #endif // __USER_H__