Older/WebApplication/model/User.h

60 lines
1.6 KiB
C
Raw Normal View History

2024-11-01 19:05:20 +08:00
#ifndef __USER_H__
#define __USER_H__
2024-11-02 00:30:14 +08:00
#include "Post.h"
#include "Token.h"
2024-11-01 19:05:20 +08:00
#include <Wt/Dbo/WtSqlTraits.h>
#include <Wt/WDateTime.h>
#include <Wt/WGlobal.h>
#include <Wt/WString.h>
2024-11-02 00:30:14 +08:00
using Tokens = Wt::Dbo::collection<Wt::Dbo::ptr<Token>>;
2024-11-01 19:05:20 +08:00
class User {
public:
enum Role {
Visitor = 0,
Admin = 1,
};
User();
static Wt::Dbo::dbo_traits<User>::IdType stringToId(const std::string &s);
2024-11-02 00:30:14 +08:00
Posts latestPosts(int count = 10) const;
Posts allPosts(Post::State state) const;
2024-11-01 19:05:20 +08:00
Wt::WString name;
Role role;
2024-11-03 22:31:23 +08:00
std::string password;
std::string passwordMethod;
std::string passwordSalt;
2024-11-01 19:05:20 +08:00
int failedLoginAttempts;
Wt::WDateTime lastLoginAttempt;
2024-11-03 22:31:23 +08:00
2024-11-01 19:05:20 +08:00
std::string oAuthId;
std::string oAuthProvider;
2024-11-02 00:30:14 +08:00
Tokens authTokens;
Comments comments;
Posts posts;
2024-11-01 19:05:20 +08:00
template <class Action>
void persist(Action &a) {
Wt::Dbo::field(a, name, "name");
2024-11-03 22:31:23 +08:00
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");
2024-11-01 19:05:20 +08:00
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");
2024-11-02 00:30:14 +08:00
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");
2024-11-01 19:05:20 +08:00
}
};
DBO_EXTERN_TEMPLATES(User)
#endif // __USER_H__