-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.js
46 lines (40 loc) · 1.27 KB
/
user.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
import {partials, sessionInfo} from './helper.js'
import {put, post, get, del} from './requester.js'
export const user = {
login: function () {
this.loadPartials(partials)
.partial('./templates/auth/login.hbs')
},
postLogin: function (ctx) {
const { username, password } = ctx.params
post('user', 'login', { username, password }, 'Basic')
.then(data => {
sessionInfo(data)
ctx.loadPartials(partials)
.partial('./templates/home/home.hbs')
ctx.redirect('#/')
})
.catch(console.error);
},
register: function () {
this.loadPartials(partials)
.partial('./templates/auth/register.hbs')
},
postRegister: function (ctx) {
const {username, password, rePassword} = ctx.params
post('user', '', {username, password, rePassword}, 'Basic')
.then(data=>{
sessionInfo(data)
ctx.redirect('#/')
})
.catch(console.error);
},
logout: function (ctx) {
post('user', '_logout', {}, 'Kinvey')
.then(() => {
sessionStorage.clear();
ctx.redirect('#/');
})
.catch(console.error);
}
}