#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 98 of file Session.C.
100 auto sqlite3 = cpp14::make_unique<Dbo::backend::Sqlite3>(WApplication::instance()->appRoot() +
"hangman.db");
101 sqlite3->setProperty(
"show-queries",
"true");
102 session_.setConnection(std::move(sqlite3));
106 session_.mapClass<AuthInfo::AuthIdentityType>(
"auth_identity");
107 session_.mapClass<AuthInfo::AuthTokenType>(
"auth_token");
111 dbo::Transaction transaction(
session_);
118 Auth::User guestUser =
users_->registerNew();
119 guestUser.addIdentity(Auth::Identity::LoginName,
"guest");
120 myPasswordService.updatePassword(guestUser,
"guest");
122 log(
"info") <<
"Database created";
124 log(
"info") <<
"Using existing database";
127 transaction.commit();
Auth::Dbo::AuthInfo< User > AuthInfo
std::unique_ptr< UserDatabase > users_
◆ ~Session()
◆ addToScore()
void Session::addToScore |
( |
int |
s | ) |
|
Definition at line 158 of file Session.C.
160 dbo::Transaction transaction(
session_);
162 dbo::ptr<User> u =
user();
164 u.modify()->score += s;
165 ++u.modify()->gamesPlayed;
166 u.modify()->lastGame = WDateTime::currentDateTime();
169 transaction.commit();
Dbo::ptr< User > user() const
◆ auth()
const Auth::AuthService & Session::auth |
( |
| ) |
|
|
static |
Definition at line 215 of file Session.C.
217 return myAuthService;
◆ configureAuth()
void Session::configureAuth |
( |
| ) |
|
|
static |
Definition at line 75 of file Session.C.
77 myAuthService.setAuthTokensEnabled(
true,
"hangmancookie");
78 myAuthService.setEmailVerificationEnabled(
true);
80 std::unique_ptr<Auth::PasswordVerifier> verifier
81 = cpp14::make_unique<Auth::PasswordVerifier>();
82 verifier->addHashFunction(cpp14::make_unique<Auth::BCryptHashFunction>(7));
87 verifier->addHashFunction(cpp14::make_unique<UnixCryptHashFunction>());
90 myPasswordService.setVerifier(std::move(verifier));
91 myPasswordService.setStrengthValidator(cpp14::make_unique<Auth::PasswordStrengthValidator>());
92 myPasswordService.setAttemptThrottlingEnabled(
true);
94 if (Auth::GoogleService::configured())
95 myOAuthServices.push_back(
new Auth::GoogleService(myAuthService));
◆ findRanking()
int Session::findRanking |
( |
| ) |
|
Definition at line 194 of file Session.C.
196 dbo::Transaction transaction(
session_);
198 dbo::ptr<User> u =
user();
202 ranking =
session_.query<
int>(
"select distinct count(score) from user")
203 .where(
"score > ?").bind(u->score);
205 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 225 of file Session.C.
227 return myOAuthServices;
◆ passwordAuth()
const Auth::AbstractPasswordService & Session::passwordAuth |
( |
| ) |
|
|
static |
Definition at line 220 of file Session.C.
222 return myPasswordService;
◆ topUsers()
std::vector< User > Session::topUsers |
( |
int |
limit | ) |
|
Definition at line 172 of file Session.C.
174 dbo::Transaction transaction(
session_);
178 std::vector<User> result;
179 for (Users::const_iterator i = top.begin(); i != top.end(); ++i) {
180 dbo::ptr<User>
user = *i;
181 result.push_back(*
user);
183 dbo::ptr<AuthInfo>
auth = *
user->authInfos.begin();
184 std::string name =
auth->identity(Auth::Identity::LoginName).toUTF8();
186 result.back().name = name;
189 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 134 of file Session.C.
137 dbo::ptr<AuthInfo> authInfo =
users_->find(
login_.user());
138 dbo::ptr<User>
user = authInfo->user();
142 authInfo.modify()->setUser(
user);
147 return dbo::ptr<User>();
Dbo::ptr< User > user() const
std::unique_ptr< UserDatabase > users_
◆ userName()
std::string Session::userName |
( |
| ) |
const |
Definition at line 150 of file Session.C.
153 return login_.user().identity(Auth::Identity::LoginName).toUTF8();
155 return std::string();
◆ users()
Auth::AbstractUserDatabase & Session::users |
( |
| ) |
|
Definition at line 210 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.1.0/examples/hangman/Session.h
- /builddir/build/BUILD/wt-4.1.0/examples/hangman/Session.C