1 // This may look like C code, but it's really -*- C++ -*-
2 /*
3  * Copyright (C) 2011 Emweb bv, Herent, Belgium.
4  *
5  * See the LICENSE file for terms of use.
6  */
7 
8 #ifndef SESSION_H_
9 #define SESSION_H_
10 
11 #include <vector>
12 
13 #include <Wt/Auth/Login.h>
14 
15 #include <Wt/Dbo/Session.h>
16 #include <Wt/Dbo/ptr.h>
17 #include <Wt/Dbo/backend/Sqlite3.h>
18 
19 #include "User.h"
20 
21 using namespace Wt;
22 
23 typedef Auth::Dbo::UserDatabase<AuthInfo> UserDatabase;
24 
25 class Session
26 {
27 public:
28   static void configureAuth();
29 
30   Session();
31   ~Session();
32 
33   Auth::AbstractUserDatabase& users();
login()34   Auth::Login& login() { return login_; }
35 
36   std::vector<User> topUsers(int limit);
37 
38   /*
39    * These methods deal with the currently logged in user
40    */
41   std::string userName() const;
42   int findRanking();
43   void addToScore(int s);
44 
45   static const Auth::AuthService& auth();
46   static const Auth::AbstractPasswordService& passwordAuth();
47   static const std::vector<const Auth::OAuthService *>& oAuth();
48 
49 private:
50   mutable Dbo::Session session_;
51   std::unique_ptr<UserDatabase> users_;
52   Auth::Login login_;
53 
54   Dbo::ptr<User> user() const;
55 };
56 
57 #endif //SESSION_H_
58