GnuCashew ~ GnuCash Enabled Web
GCW
Auth.cpp
Go to the documentation of this file.
1 #line 2 "src/Dbo/Users/Auth.cpp"
2 
3 #include <Wt/Auth/Dbo/UserDatabase.h>
4 #include <Wt/Auth/AuthService.h>
5 #include <Wt/Auth/HashFunction.h>
6 #include <Wt/Auth/PasswordService.h>
7 #include <Wt/Auth/PasswordStrengthValidator.h>
8 #include <Wt/Auth/PasswordVerifier.h>
9 #include <Wt/Auth/GoogleService.h>
10 #include <Wt/Auth/FacebookService.h>
11 #include <Wt/Auth/Dbo/AuthInfo.h>
12 
13 #include "Auth.h"
14 
15 namespace
16 {
17  Wt::Auth::AuthService myAuthService ;
18  Wt::Auth::PasswordService myPasswordService( myAuthService ) ;
19  std::vector< std::unique_ptr< Wt::Auth::OAuthService > > myOAuthServices ;
20 }
21 
22 auto
24 mapClasses( Wt::Dbo::Session & _session )-> void
25 {
26  _session.mapClass< GCW::Dbo::Users::Item >( "gcw_users" );
27  _session.mapClass< AuthInfo >( "gcw_info" );
28  _session.mapClass< AuthInfo::AuthIdentityType >( "gcw_identity" );
29  _session.mapClass< AuthInfo::AuthTokenType >( "gcw_token" );
30 
31 } // endmapClasses( Wt::Dbo::Session & session )-> void
32 
33 auto
35 postCreateTables( Wt::Dbo::Session & session )-> void
36 {
37 #ifdef NEVER
38  /*
39  ** we will create a single default 'admin' user in the system
40  ** that can be used to log in to the interface.
41  **
42  */
43  typedef Wt::Auth::Dbo::UserDatabase<AuthInfo> UserDatabase;
44 
45  Wt::Dbo::Transaction t(session);
46  UserDatabase users( session, &Wtx::Sys::Auth::service() );
47 
48  auto authUser = users.registerNew();
49  authUser.addIdentity( Wt::Auth::Identity::LoginName, "admin" );
50  authUser.setEmail( "mark@lorimarksolutions.com" );
51  passwordService().updatePassword( authUser, "ABC123!!!" );
52 #endif
53 
54 } // endpostCreateTables( Wt::Dbo::Session & session )-> void
55 
56 auto
58 configure()-> void
59 {
60  myAuthService.setAuthTokensEnabled( true, "logincookie" );
61  myAuthService.setEmailVerificationEnabled( true );
62  myAuthService.setEmailVerificationRequired( true );
63  myAuthService.setIdentityPolicy( Wt::Auth::IdentityPolicy::EmailAddress );
64 
65  auto verifier
66  = std::make_unique<Wt::Auth::PasswordVerifier>();
67  verifier->addHashFunction( std::make_unique<Wt::Auth::BCryptHashFunction>(7) );
68  myPasswordService.setVerifier( std::move(verifier) );
69  myPasswordService.setAttemptThrottlingEnabled( true );
70  myPasswordService.setStrengthValidator( std::make_unique<Wt::Auth::PasswordStrengthValidator>() );
71 
72  if( Wt::Auth::GoogleService::configured() )
73  myOAuthServices.push_back( std::make_unique<Wt::Auth::GoogleService>( myAuthService ) );
74 
75  if( Wt::Auth::FacebookService::configured() )
76  myOAuthServices.push_back( std::make_unique<Wt::Auth::FacebookService>( myAuthService ) );
77 
78  for( unsigned i = 0; i < myOAuthServices.size(); ++i )
79  myOAuthServices[i]-> generateRedirectEndpoint();
80 
81 } // endconfigure()-> void
82 
83 auto
85 service()-> const Wt::Auth::AuthService &
86 {
87  return myAuthService;
88 
89 } // endservice()-> const Wt::Auth::AuthService &
90 
91 auto
93 passwordService()-> const Wt::Auth::PasswordService &
94 {
95  return myPasswordService;
96 
97 } // endpasswordService()-> const Wt::Auth::PasswordService &
98 
99 auto
101 oService()-> const std::vector<const Wt::Auth::OAuthService *>
102 {
103  std::vector<const Wt::Auth::OAuthService *> result;
104 
105  for( auto & auth : myOAuthServices )
106  result.push_back( auth.get() );
107 
108  return result;
109 
110 } // endoService()-> const std::vector<const Wt::Auth::OAuthService *>
111 
112 
auto configure() -> void
Definition: Auth.cpp:58
auto passwordService() -> const Wt::Auth::PasswordService &
Definition: Auth.cpp:93
auto postCreateTables(Wt::Dbo::Session &session) -> void
Definition: Auth.cpp:35
Wt::Auth::Dbo::UserDatabase< AuthInfo > UserDatabase
Definition: Auth.h:18
auto service() -> const Wt::Auth::AuthService &
Definition: Auth.cpp:85
Wt::Auth::Dbo::AuthInfo< GCW::Dbo::Users::Item > AuthInfo
Definition: Auth.h:17
auto mapClasses(Wt::Dbo::Session &session) -> void
Definition: Auth.cpp:24
auto oService() -> const std::vector< const Wt::Auth::OAuthService * >
Definition: Auth.cpp:101