-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathstormpath-cookie-user-service.js
More file actions
73 lines (58 loc) · 2.06 KB
/
stormpath-cookie-user-service.js
File metadata and controls
73 lines (58 loc) · 2.06 KB
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
import utils from '../utils';
import BaseService from './BaseService';
import RequestPool from './RequestPool';
export default class StormpathCookieUserService extends BaseService {
constructor(endpoints, forceAgentHeader) {
let defaultEndpoints = {
me: '/me',
login: '/login',
register: '/register',
verifyEmail: '/verify',
forgotPassword: '/forgot',
changePassword: '/change',
logout: '/logout'
};
super(utils.mergeObjects(defaultEndpoints, endpoints), forceAgentHeader);
this.meRequestPool = new RequestPool();
}
_unwrapAccountResult(callback) {
return (err, result) => {
if (err) {
return callback(err);
}
callback(null, result.account || result || {});
};
}
me(callback) {
this.meRequestPool.request((resultCallback) => {
this._makeRequest('get', this.endpoints.me, null, null, this._unwrapAccountResult(resultCallback));
}, callback);
}
updateProfile(data, callback) {
this._makeRequest('post', this.endpoints.me, data, null, callback);
}
getLoginViewData(callback) {
this._makeRequest('get', this.endpoints.login, null, null, callback);
}
login(options, callback) {
this._makeRequest('post', this.endpoints.login, options, null, this._unwrapAccountResult(callback));
}
register(options, callback) {
this._makeRequest('post', this.endpoints.register, options, null, this._unwrapAccountResult(callback));
}
getRegisterViewData(callback) {
this._makeRequest('get', this.endpoints.register, null, null, callback);
}
verifyEmail(spToken, callback) {
this._makeRequest('get', this.endpoints.verifyEmail + '?sptoken=' + encodeURIComponent(spToken), null, null, callback);
}
forgotPassword(options, callback) {
this._makeRequest('post', this.endpoints.forgotPassword, options, null, callback);
}
changePassword(options, callback) {
this._makeRequest('post', this.endpoints.changePassword, options, null, callback);
}
logout(callback) {
this._makeRequest('post', this.endpoints.logout, null, null, callback);
}
}