#include <Session.h>
|
static void | configureAuth () |
|
static const Auth::AuthService & | auth () |
|
static const Auth::AbstractPasswordService & | passwordAuth () |
|
static const std::vector< const Auth::OAuthService * > & | oAuth () |
|
Definition at line 25 of file Session.h.
◆ Session()
Definition at line 96 of file Session.C.
98 auto sqlite3 = cpp14::make_unique<Dbo::backend::Sqlite3>(WApplication::instance()->appRoot() +
"hangman.db");
99 sqlite3->setProperty(
"show-queries",
"true");
100 session_.setConnection(std::move(sqlite3));
104 session_.mapClass<AuthInfo::AuthIdentityType>(
"auth_identity");
105 session_.mapClass<AuthInfo::AuthTokenType>(
"auth_token");
109 dbo::Transaction transaction(
session_);
116 Auth::User guestUser =
users_->registerNew();
117 guestUser.addIdentity(Auth::Identity::LoginName,
"guest");
118 myPasswordService.updatePassword(guestUser,
"guest");
120 log(
"info") <<
"Database created";
122 log(
"info") <<
"Using existing database";
125 transaction.commit();
Auth::Dbo::AuthInfo< User > AuthInfo
std::unique_ptr< UserDatabase > users_
◆ ~Session()
◆ addToScore()
void Session::addToScore |
( |
int |
s | ) |
|
Definition at line 156 of file Session.C.
158 dbo::Transaction transaction(
session_);
160 dbo::ptr<User> u =
user();
162 u.modify()->score += s;
163 ++u.modify()->gamesPlayed;
164 u.modify()->lastGame = WDateTime::currentDateTime();
167 transaction.commit();
Dbo::ptr< User > user() const
◆ auth()
const Auth::AuthService & Session::auth |
( |
| ) |
|
|
static |
Definition at line 213 of file Session.C.
215 return myAuthService;
◆ configureAuth()
void Session::configureAuth |
( |
| ) |
|
|
static |
Definition at line 73 of file Session.C.
75 myAuthService.setAuthTokensEnabled(
true,
"hangmancookie");
76 myAuthService.setEmailVerificationEnabled(
true);
78 std::unique_ptr<Auth::PasswordVerifier> verifier
79 = cpp14::make_unique<Auth::PasswordVerifier>();
80 verifier->addHashFunction(cpp14::make_unique<Auth::BCryptHashFunction>(7));
85 verifier->addHashFunction(cpp14::make_unique<UnixCryptHashFunction>());
88 myPasswordService.setVerifier(std::move(verifier));
89 myPasswordService.setStrengthValidator(cpp14::make_unique<Auth::PasswordStrengthValidator>());
90 myPasswordService.setAttemptThrottlingEnabled(
true);
92 if (Auth::GoogleService::configured())
93 myOAuthServices.push_back(
new Auth::GoogleService(myAuthService));
◆ findRanking()
int Session::findRanking |
( |
| ) |
|
Definition at line 192 of file Session.C.
194 dbo::Transaction transaction(
session_);
196 dbo::ptr<User> u =
user();
200 ranking =
session_.query<
int>(
"select distinct count(score) from user")
201 .where(
"score > ?").bind(u->score);
203 transaction.commit();
Dbo::ptr< User > user() const
◆ login()
Auth::Login& Session::login |
( |
| ) |
|
|
inline |
◆ oAuth()
const std::vector< const Auth::OAuthService * > & Session::oAuth |
( |
| ) |
|
|
static |
Definition at line 223 of file Session.C.
225 return myOAuthServices;
◆ passwordAuth()
const Auth::AbstractPasswordService & Session::passwordAuth |
( |
| ) |
|
|
static |
Definition at line 218 of file Session.C.
220 return myPasswordService;
◆ topUsers()
std::vector< User > Session::topUsers |
( |
int |
limit | ) |
|
Definition at line 170 of file Session.C.
172 dbo::Transaction transaction(
session_);
176 std::vector<User> result;
177 for (Users::const_iterator i = top.begin(); i != top.end(); ++i) {
178 dbo::ptr<User>
user = *i;
179 result.push_back(*
user);
181 dbo::ptr<AuthInfo>
auth = *
user->authInfos.begin();
182 std::string name =
auth->identity(Auth::Identity::LoginName).toUTF8();
184 result.back().name = name;
187 transaction.commit();
dbo::collection< dbo::ptr< User > > Users
static const Auth::AuthService & auth()
Dbo::ptr< User > user() const
◆ user()
dbo::ptr< User > Session::user |
( |
| ) |
const |
|
private |
Definition at line 132 of file Session.C.
135 dbo::ptr<AuthInfo> authInfo =
users_->find(
login_.user());
136 dbo::ptr<User>
user = authInfo->user();
140 authInfo.modify()->setUser(
user);
145 return dbo::ptr<User>();
Dbo::ptr< User > user() const
std::unique_ptr< UserDatabase > users_
◆ userName()
std::string Session::userName |
( |
| ) |
const |
Definition at line 148 of file Session.C.
151 return login_.user().identity(Auth::Identity::LoginName).toUTF8();
153 return std::string();
◆ users()
Auth::AbstractUserDatabase & Session::users |
( |
| ) |
|
Definition at line 208 of file Session.C.
std::unique_ptr< UserDatabase > users_
◆ login_
Auth::Login Session::login_ |
|
private |
◆ session_
Dbo::Session Session::session_ |
|
mutableprivate |
◆ users_
The documentation for this class was generated from the following files:
- /builddir/build/BUILD/wt-4.0.2/examples/hangman/Session.h
- /builddir/build/BUILD/wt-4.0.2/examples/hangman/Session.C