60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
#ifndef __USER_H__
|
|
#define __USER_H__
|
|
|
|
#include "Post.h"
|
|
#include "Token.h"
|
|
#include <Wt/Dbo/WtSqlTraits.h>
|
|
#include <Wt/WDateTime.h>
|
|
#include <Wt/WGlobal.h>
|
|
#include <Wt/WString.h>
|
|
|
|
using Tokens = Wt::Dbo::collection<Wt::Dbo::ptr<Token>>;
|
|
|
|
class User {
|
|
public:
|
|
enum Role {
|
|
Visitor = 0,
|
|
Admin = 1,
|
|
};
|
|
User();
|
|
|
|
static Wt::Dbo::dbo_traits<User>::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 <class Action>
|
|
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__
|