Older/WebApplication/model/User.h
amass e1273a3eb9
Some checks failed
Deploy / PullDocker (push) Successful in 6s
Deploy / Build (push) Failing after 50s
Deploy Docker Images / Docusaurus build and Server deploy (push) Successful in 18s
add code.
2024-11-03 22:31:23 +08:00

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__