/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk
64.1.1 by b11johgu
ExamplesController:
1
/* Password validation */
2
var acceptedNewPwd = false;
3
var acceptedRepeatedPwd = false;
4
5
function emptyField(inputId){
6
	var id = document.getElementById(inputId);
7
	if(id.value.match(/^\s*$/)){
8
		return true;
9
	}
10
	else return false;
11
}
12
13
/* Checks input field for invalid characters */
14
function pwdValidCharacters(inputId){
15
	var id = document.getElementById(inputId);
16
	if(id.value.match(/^[A-Öa-ö0-9 _]*[A-Öa-ö0-9][A-Öa-ö0-9 _]*$/)){
17
		return true;
18
	}
19
	else return false;
20
}
21
22
/* Checks input field for minimum amount of characters(6) */
23
function pwdMininumValue(inputId){
24
	var id = document.getElementById(inputId);
25
	if(id.value.length > 5){
26
		return true;
27
	}
28
	else return false;
29
}
30
31
/* Checks if newPwd and repeatPwd are the same */
32
function pwdMatch(){
33
	var firstPwd = document.getElementById("newPwd").value;
34
	var secondPwd = document.getElementById("repeatPwd").value;
35
	if(firstPwd == secondPwd){
36
		return true;
37
	}
38
	else return false;
39
}
40
41
function validNewPwd(){
42
	var empty = emptyField("newPwd");
43
	var validchar = pwdValidCharacters("newPwd");
44
	var minimumchar = pwdMininumValue("newPwd");
45
46
	if (empty==false && validchar==true && minimumchar==true){
47
		document.getElementById("newPwd").className="Valid";
48
		$('.errorMessage[name="newPwd"]').animate({opacity:0}, 0);
49
		acceptedNewPwd=true;
50
	}
51
	else if(empty==true){
52
		acceptedNewPwd=false;
53
		document.getElementById("newPwd").className="";
54
		$('.errorMessage[name="newPwd"]').animate({opacity:0}, 0);
55
	}
56
	else if(empty==false && validchar==false || minimumchar==false){
57
		document.getElementById("newPwd").className="notValid";
58
		$('.errorMessage[name="newPwd"]').animate({opacity:1}, 0);
59
		acceptedNewPwd=false;
60
	}
61
}
62
63
function validRepeatedPwd(){
64
	var empty = emptyField("repeatPwd");
65
	var match = pwdMatch("repeatPwd");
66
	
67
	if(validNewPwd){
68
		if(empty==true){
69
			document.getElementById("repeatPwd").className="";
70
			$('.errorMessage[name="repeatPwd"]').animate({opacity:0}, 0);
71
			acceptedRepeatedPwd=false;
72
		}
73
		else if(empty==false && match==false){
74
			document.getElementById("repeatPwd").className="notValid";
75
			$('.errorMessage[name="repeatPwd"]').animate({opacity:1}, 0);
76
			acceptedRepeatedPwd=false;
77
		}
78
		else if(empty==false && match==true){
79
			document.getElementById("repeatPwd").className="Valid";
80
			$('.errorMessage[name="repeatPwd"]').animate({opacity:0}, 0);
81
			acceptedRepeatedPwd=true;
82
		}
83
	}
84
	else{
85
		document.getElementById("repeatPwd").className="";
86
	}
87
}
88
89
/* baseURL skickas med som parameter */
90
function confirm(baseURL){
91
	if(acceptedNewPwd && acceptedRepeatedPwd){
92
		changePwd(baseURL);
93
	}
94
	else{
95
		alert("WRONG WRONG WRONG!! FILL OUT THE FORM AGAIN YOU FKIN PIECE OF SHIT!");
96
		return false;
97
	}
98
}
99
100
function changePwd(baseURL)
101
{
102
	var currentPwd = document.getElementById("currentPwd").value;
103
	var newPwd = document.getElementById("newPwd").value;
104
	var hintPwd = document.getElementById("hintPwd").value;
105
106
	$.ajax({
107
		type: 'POST',
108
		url: baseURL+'ajax/pwdchange',
109
		data: { 
110
			currentPwd : currentPwd,
111
			newPwd : newPwd,
112
			hintPwd : hintPwd
113
		},
114
		success:  function(result){
115
			var resultObject = JSON.parse(result);
116
			if(resultObject.status==true){
117
				alert('Password change is successful!');
118
				$('#formContainer').fadeOut(300);
119
				$('#passwordChanger').fadeOut(300);
120
				$('body *').animate({
121
				opacity:1}, 400);
122
				$('#changePassword')[0].reset();
123
			}
124
			else{
125
				alert('Wrong password!');
126
				}
127
			}
128
	});
129
}
130
131
function passwordHint(baseURL){
132
	var userName = $("#username").val();
133
	
134
	$.ajax({
135
		type: 'POST',
136
		url: baseURL+'ajax/pwdhint',
137
		data: { 
138
			hintPwd : userName
139
		},
140
		success:  function(result){
141
			var resultObject = JSON.parse(result);
142
			var hinttext = document.getElementById('hinttext');
143
144
			if(resultObject.hint.length>0){
145
146
				hinttext.innerHTML = resultObject.hint;
147
			}
148
			else{
149
				hinttext.innerHTML = "User does not exist!";
150
				}
151
			}
152
	});
153
}