/
WelcomeController.js
87 lines (80 loc) · 1.93 KB
/
WelcomeController.js
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
80
81
82
83
84
85
86
87
module.exports = {
/**
* Welcome page ( / )
* @method index
* @param {} req
* @param {} res
* @param {} next
* @return
*/
index: function(req, res, next) {
gladys.utils.sql('SELECT * FROM user;').then(function(users) {
var signupAllowed = users.length === 0;
res.view('welcome/homepage', {
layout: null,
signupActive: signupAllowed
});
});
},
/**
* Login Page ( /login )
* @method index
* @param {} req
* @param {} res
* @param {} next
* @return
*/
login: function(req, res, next) {
res.view('welcome/index', {
layout: null,
signupActive: sails.config.signup.active
});
},
loginBlockstack: function(req, res, next) {
res.view('welcome/login-blockstack', {
layout: null,
signupActive: sails.config.signup.active
});
},
forgotPassword: function(req, res, next) {
res.view('welcome/forgotpassword', {
layout: null,
done: false,
resetPasswordFailed: req.query.error == 'true'
});
},
postForgotPassword: function(req, res, next) {
// we catch any errors, we don't want to tell if a user exist or not
gladys.user
.forgotPassword({ email: req.body.email })
.catch(() => null)
.then(() => {
res.view('welcome/forgotpassword', {
layout: null,
done: true
});
});
},
resetPassword: function(req, res, next) {
res.view('welcome/resetpassword', {
layout: null,
token: req.query.token
});
},
postResetPassword: function(req, res, next) {
gladys.user
.resetPassword(req.body.password, req.body.token)
.then(() => {
return res.redirect('/login');
})
.catch(err => {
sails.log.error(err);
return res.redirect('/forgotpassword?error=true');
});
},
installation: function(req, res, next) {
res.view('installation/index', {
layout: null
});
}
};