forked from geokrety/geokrety-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadduser.js
180 lines (164 loc) · 5.35 KB
/
adduser.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
var img_exclamation = '<img src="templates/exclamation.gif" border="0" />';
//var img_accept = '<img src="templates/accept.gif" border="0" />';
var img_accept = '';
function validateLogin(e) {
if (e) {
var KeyID = (window.event)
? event.keyCode
: e.keyCode;
if (KeyID == 9 || (KeyID >= 16 && KeyID <= 20) || (KeyID >= 33 && KeyID <= 40))
return;
}
var obj = document.getElementById('login');
var img = document.getElementById('login_img');
if (obj.value == "") {
img.innerHTML = img_exclamation;
setBorderColorRed(obj);
return false;
}
img.innerHTML = img_accept;
setBorderColorGreen(obj);
return true;
}
window['validateLogin'] = validateLogin;
function validatePassword1(e) {
if (e) {
var KeyID = (window.event)
? event.keyCode
: e.keyCode;
if (KeyID == 9 || (KeyID >= 16 && KeyID <= 20) || (KeyID >= 33 && KeyID <= 40))
return;
}
var haslo1 = document.getElementById('haslo1');
var img1 = document.getElementById('haslo1_img');
if (haslo1.value.length < 5) {
img1.innerHTML = img_exclamation;
setBorderColorRed(haslo1);
return false;
}
img1.innerHTML = img_accept;
setBorderColorGreen(haslo1);
var haslo2 = document.getElementById('haslo2');
var img2 = document.getElementById('haslo2_img');
if (haslo2.value.length >= 5) {
if ((haslo1.value != haslo2.value)) {
img2.innerHTML = img_exclamation;
setBorderColorRed(haslo2);
return false;
} else {
img2.innerHTML = img_accept;
setBorderColorGreen(haslo2);
}
}
return true;
}
window['validatePassword1'] = validatePassword1;
function validatePassword2(e) {
if (e) {
var KeyID = (window.event)
? event.keyCode
: e.keyCode;
if (KeyID == 9 || (KeyID >= 16 && KeyID <= 20) || (KeyID >= 33 && KeyID <= 40))
return;
}
var haslo1 = document.getElementById('haslo1');
var haslo2 = document.getElementById('haslo2');
var img1 = document.getElementById('haslo1_img');
var img2 = document.getElementById('haslo2_img');
if ((haslo1.value.length < 5) || (haslo2.value.length < 5) || (haslo1.value != haslo2.value)) {
img2.innerHTML = img_exclamation;
setBorderColorRed(haslo2);
return false;
}
//img1.innerHTML = img_accept;
setBorderColorGreen(haslo1);
img2.innerHTML = img_accept;
setBorderColorGreen(haslo2);
return true;
}
window['validatePassword2'] = validatePassword2;
function validateEmail(e) {
if (e) {
var KeyID = (window.event)
? event.keyCode
: e.keyCode;
if (KeyID == 9 || (KeyID >= 16 && KeyID <= 20) || (KeyID >= 33 && KeyID <= 40))
return;
}
var regex = /^[\S]+\@([\S]+\.)+[A-Za-z]{2,4}$/;
var obj = document.getElementById('email');
var img = document.getElementById('email_img');
var email = obj.value;
email = email.replace(/^\s\s*/, '');
email = email.replace(/\s\s*$/, '');
obj.value = email;
if (email.length <= 5 || !email.match(regex)) {
img.innerHTML = img_exclamation;
setBorderColorRed(obj);
return false;
}
img.innerHTML = img_accept;
setBorderColorGreen(obj);
return true;
}
window['validateEmail'] = validateEmail;
function validateCaptcha(e) {
if (e) {
var KeyID = (window.event)
? event.keyCode
: e.keyCode;
if (KeyID == 9 || (KeyID >= 16 && KeyID <= 20) || (KeyID >= 33 && KeyID <= 40))
return;
}
var obj = document.getElementById('captcha');
var img = document.getElementById('captcha_img');
if (obj.value == "") {
img.innerHTML = img_exclamation;
setBorderColorRed(obj);
return false;
}
img.innerHTML = img_accept;
setBorderColorGreen(obj);
return true;
}
window['validateCaptcha'] = validateCaptcha;
function setBorderColorRed(obj) {
obj.setAttribute('style', 'border-color: #FF0000;')
//obj.style.border-color = '#FF0000';
}
window['setBorderColorRed'] = setBorderColorRed;
function setBorderColorGreen(obj) {
//obj.setAttribute('style', 'border-color: #00FF00;')
obj.setAttribute('style', 'border-color: #666666;')
}
window['setBorderColorGreen'] = setBorderColorGreen;
function validateAddUser(thisForm) {
var ret = false;
ret = !validateLogin(null) || ret;
ret = !validatePassword1(null) || ret;
ret = !validatePassword2(null) || ret;
ret = !validateEmail(null) || ret;
ret = !validateCaptcha(null) || ret;
return !ret;
}
window['validateAddUser'] = validateAddUser;
function passwordChanged() {
var strength = document.getElementById('strength');
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var enoughRegex = new RegExp("(?=.{5,}).*", "g");
var klucz = ' <img src="https://cdn.geokrety.org/images/icons/key.png" alt="key"/> ';
var pwd = document.getElementById("haslo1");
if (pwd.value.length == 0) {
strength.innerHTML = '';
} else if (false == enoughRegex.test(pwd.value)) {
strength.innerHTML = '';
} else if (strongRegex.test(pwd.value)) {
strength.innerHTML = klucz + klucz + klucz + '<span style="color:green">Strong!</span>';
} else if (mediumRegex.test(pwd.value)) {
strength.innerHTML = klucz + klucz + '<span style="color:orange">Medium!</span>';
} else {
strength.innerHTML = klucz + '<span style="color:red">Weak!</span>';
}
}
window['passwordChanged'] = passwordChanged;