-
Notifications
You must be signed in to change notification settings - Fork 1
/
auth.C
executable file
·79 lines (64 loc) · 2.04 KB
/
auth.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/************************************************************************
FileName: auth.C
Description: Holds the definition of class for Authentication widget
Details:
auth.C files contains a definition of class named AuthForm that is inherited
from WContainer widget, this class is then used in main WApplication for creating
an auth form.
Author: Gauravjeet Singh, Shaina Sabarwal, Inderpreet Singh
License: GNU GPL V3
**************************************************************************/
#include "auth.h"
#include "admin/dashboard.h"
#include <Wt/WDateTime>
AuthForm::AuthForm(WContainerWidget *parent)
:WContainerWidget(parent)
{
setLogin = false;
session_.login().changed().connect(this,&AuthForm::authEvent);
authEvent();
authWidget = new Wt::Auth::AuthWidget(Session::auth(), session_.users(),
session_.login());
authWidget->model()->addPasswordAuth(&Session::passwordAuth());
authWidget->processEnvironment();
registerAdmin();
this->addWidget(authWidget);
}
void AuthForm::authEvent() {
if(session_.login().loggedIn()){
Wt::log("notice") << "User" << session_.login().user().id()
<<"logged in.";
dashContainer = new WContainerWidget(this);
new dashboard(dashContainer);
setLogin = true;
}
else {
Wt::log("notice") << "User logged out.";
if(setLogin)
{
cout<<setLogin;
dashContainer->clear();
}
}
}
void AuthForm :: registerAdmin()
{
try{
{
dbo::Transaction t(session_);
dbo::ptr<User> admin = session_.find<User>().where("name=?").bind("admin");
std::string adminString = admin->name;
t.commit();
}
}
catch(exception& e){
{
dbo::Transaction t(session_);
User *newUser = new User();
newUser->name = "admin";
dbo::ptr<User> newAdmin = session_.add(newUser);
t.commit();
}
authWidget->registerNewUser();
}
}