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
|
/* Password validation */
var acceptedNewPwd = false;
var acceptedRepeatedPwd = false;
function emptyField(inputId){
var id = document.getElementById(inputId);
if(id.value.match(/^\s*$/)){
return true;
}
else return false;
}
/* Checks input field for invalid characters */
function pwdValidCharacters(inputId){
var id = document.getElementById(inputId);
if(id.value.match(/^[A-Öa-ö0-9 _]*[A-Öa-ö0-9][A-Öa-ö0-9 _]*$/)){
return true;
}
else return false;
}
/* Checks input field for minimum amount of characters(6) */
function pwdMininumValue(inputId){
var id = document.getElementById(inputId);
if(id.value.length > 5){
return true;
}
else return false;
}
/* Checks if newPwd and repeatPwd are the same */
function pwdMatch(){
var firstPwd = document.getElementById("newPwd").value;
var secondPwd = document.getElementById("repeatPwd").value;
if(firstPwd == secondPwd){
return true;
}
else return false;
}
function validNewPwd(){
var empty = emptyField("newPwd");
var validchar = pwdValidCharacters("newPwd");
var minimumchar = pwdMininumValue("newPwd");
if (empty==false && validchar==true && minimumchar==true){
document.getElementById("newPwd").className="Valid";
$('.errorMessage[name="newPwd"]').animate({opacity:0}, 0);
acceptedNewPwd=true;
}
else if(empty==true){
acceptedNewPwd=false;
document.getElementById("newPwd").className="";
$('.errorMessage[name="newPwd"]').animate({opacity:0}, 0);
}
else if(empty==false && validchar==false || minimumchar==false){
document.getElementById("newPwd").className="notValid";
$('.errorMessage[name="newPwd"]').animate({opacity:1}, 0);
acceptedNewPwd=false;
}
}
function validRepeatedPwd(){
var empty = emptyField("repeatPwd");
var match = pwdMatch("repeatPwd");
if(validNewPwd){
if(empty==true){
document.getElementById("repeatPwd").className="";
$('.errorMessage[name="repeatPwd"]').animate({opacity:0}, 0);
acceptedRepeatedPwd=false;
}
else if(empty==false && match==false){
document.getElementById("repeatPwd").className="notValid";
$('.errorMessage[name="repeatPwd"]').animate({opacity:1}, 0);
acceptedRepeatedPwd=false;
}
else if(empty==false && match==true){
document.getElementById("repeatPwd").className="Valid";
$('.errorMessage[name="repeatPwd"]').animate({opacity:0}, 0);
acceptedRepeatedPwd=true;
}
}
else{
document.getElementById("repeatPwd").className="";
}
}
/* baseURL skickas med som parameter */
function confirm(baseURL){
if(acceptedNewPwd && acceptedRepeatedPwd){
changePwd(baseURL);
}
else{
alert("WRONG WRONG WRONG!! FILL OUT THE FORM AGAIN YOU FKIN PIECE OF SHIT!");
return false;
}
}
function changePwd(baseURL)
{
var currentPwd = document.getElementById("currentPwd").value;
var newPwd = document.getElementById("newPwd").value;
var hintPwd = document.getElementById("hintPwd").value;
$.ajax({
type: 'POST',
url: baseURL+'ajax/pwdchange',
data: {
currentPwd : currentPwd,
newPwd : newPwd,
hintPwd : hintPwd
},
success: function(result){
var resultObject = JSON.parse(result);
if(resultObject.status==true){
alert('Password change is successful!');
$('#formContainer').fadeOut(300);
$('#passwordChanger').fadeOut(300);
$('body *').animate({
opacity:1}, 400);
$('#changePassword')[0].reset();
}
else{
alert('Wrong password!');
}
}
});
}
function passwordHint(baseURL){
var userName = $("#username").val();
$.ajax({
type: 'POST',
url: baseURL+'ajax/pwdhint',
data: {
hintPwd : userName
},
success: function(result){
var resultObject = JSON.parse(result);
var hinttext = document.getElementById('hinttext');
if(resultObject.hint.length>0){
hinttext.innerHTML = resultObject.hint;
}
else{
hinttext.innerHTML = "User does not exist!";
}
}
});
}
|