-
Notifications
You must be signed in to change notification settings - Fork 3
/
reset.js
110 lines (80 loc) · 2.91 KB
/
reset.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
Wu.Reset = Wu.Class.extend({
options : {
title : 'Reset your password',
message : 'Please create a strong password',
sent : 'Please check your email for further instructions.',
button : 'Reset',
api : '/v2/users/password'
},
initialize : function (options) {
// set options
this.setOptions(options);
// init container
this._initContainer();
// init content
this._initContent();
},
setOptions : function (options) {
// set options
Wu.setOptions(this, options);
// get token
this._token = this.getParams('token');
// get email
this._email = this.getParams('email');
},
getParams : function (name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null
},
_initContainer : function () {
this._container = Wu.DomUtil.get(this.options.container);
},
_initContent : function () {
// logo
this._createLogo();
// wrapper
this._centralWrapper = Wu.DomUtil.create('div', 'central', this._container);
// login
this._createForgot();
},
_createLogo : function () {
// wrap
var logo_wrap = Wu.DomUtil.create('div', 'logo-wrap', this._container);
// logo
var logo_img = window.systemapicConfigOptions.logos.clientLogo;
logo_wrap.style.backgroundImage = logo_img.backgroundImage;
logo_wrap.style.backgroundRepeat = "no-repeat";
logo_wrap.style.backgroundPosition = "center";
},
_createForgot : function () {
// login wrapper
var wrapper = Wu.DomUtil.create('div', 'center', this._centralWrapper);
// label
var label = Wu.DomUtil.create('div', 'top-label', wrapper, this.options.title);
// text
var textWrapper = Wu.DomUtil.create('div', 'text-wrapper', wrapper);
this._text = Wu.DomUtil.create('div', 'text-content', textWrapper);
this._text.innerHTML = this.options.message;
// wrapper
this._inputs = Wu.DomUtil.create('form', 'input-wrapper', wrapper);
this._inputs.setAttribute('action', this.options.api);
this._inputs.setAttribute('method', 'post');
// email label
this._emailDiv = Wu.DomUtil.create('input', 'input reset', this._inputs, 'Email Address');
this._emailDiv.setAttribute('name', 'email');
this._emailDiv.value = this._email;
this._emailDiv.setAttribute('readonly', 'readonly');
// password label
this._password = Wu.DomUtil.create('input', 'input forgot', this._inputs, 'Create a strong password');
this._password.setAttribute('name', 'password');
this._password.setAttribute('type', 'password');
// pass token to POST
this._tokenInput = Wu.DomUtil.create('input', 'input forgot', this._inputs);
this._tokenInput.setAttribute('name', 'token');
this._tokenInput.style.display = 'none';
this._tokenInput.value = this._token;
// button
var button = Wu.DomUtil.create('button', 'button', this._inputs, this.options.button);
button.setAttribute('type', 'submit');
button.setAttribute('name', 'login');
},
});