Subversion Repositories Applications.reseau

Rev

Rev 56 | Rev 72 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 56 Rev 68
1
$(document).ready(function() {
1
$(document).ready(function() {
2
	// infobulles
2
	// infobulles
3
	$('[data-toggle="tooltip"]').tooltip();
3
	$('[data-toggle="tooltip"]').tooltip();
4
 
4
 
5
	// trucage ordre des champs pour passer du login au mdp sans passer
5
	// trucage ordre des champs pour passer du login au mdp sans passer
6
	// par le lien "oublié ?" => pas standard, c'est mal - @TODO faire mieux
6
	// par le lien "oublié ?" => pas standard, c'est mal - @TODO faire mieux
7
	// Ordre : login => mdp => oublie => s'inscrire
7
	// Ordre : login => mdp => oublie => s'inscrire
8
	$('#login').keypress(function(e) {
8
	$('#login').keypress(function(e) {
9
		if(e.keyCode == 9) {
9
		if(e.keyCode == 9) {
10
			if(! e.shiftKey) {
10
			if(! e.shiftKey) {
11
				$('#mdp').focus();
11
				$('#mdp').focus();
12
				return false;
12
				return false;
13
			}
13
			}
14
		}
14
		}
15
	});
15
	});
16
	$('#mdp').keypress(function(e) {
16
	$('#mdp').keypress(function(e) {
17
		if(e.keyCode == 9) {
17
		if(e.keyCode == 9) {
18
			if(e.shiftKey) {
18
			if(e.shiftKey) {
19
				$('#login').focus();
19
				$('#login').focus();
20
			} else {
20
			} else {
21
				$('#mdp-oublie').focus();
21
				$('#mdp-oublie').focus();
22
			}
22
			}
23
			return false;
23
			return false;
24
		}
24
		}
25
	});
25
	});
26
	$('#mdp-oublie').keypress(function(e) {
26
	$('#mdp-oublie').keypress(function(e) {
27
		if(e.keyCode == 9) {
27
		if(e.keyCode == 9) {
28
			if(e.shiftKey) {
28
			if(e.shiftKey) {
29
				$('#mdp').focus();
29
				$('#mdp').focus();
30
			} else {
30
			} else {
31
				$('#lien-inscription').focus();
31
				$('#lien-inscription').focus();
32
			}
32
			}
33
		}
33
		}
34
		return false;
34
		return false;
35
	});
35
	});
36
	$('#lien-inscription').keypress(function(e) {
36
	$('#lien-inscription').keypress(function(e) {
37
		if(e.keyCode == 9) {
37
		if(e.keyCode == 9) {
38
			if(e.shiftKey) {
38
			if(e.shiftKey) {
39
				$('#mdp-oublie').focus();
39
				$('#mdp-oublie').focus();
40
				return false;
40
				return false;
41
			}
41
			}
42
		}
42
		}
43
	});
43
	});
44
 
44
 
45
	// partenaire avec lequel se connecter
45
	// partenaire avec lequel se connecter
46
	$('#liste-fournisseurs ul li a').click(function() {
46
	$('#liste-fournisseurs ul li a').click(function() {
47
		$('#liste-fournisseurs ul li a').attr('data-focus', 'false');
47
		$('#liste-fournisseurs ul li a').attr('data-focus', 'false');
48
		$(this).attr('data-focus', 'true');
48
		$(this).attr('data-focus', 'true');
49
		var nomPartenaire = $(this).data('nom-partenaire');
49
		var nomPartenaire = $(this).data('nom-partenaire');
50
		$('#nom-partenaire').html(nomPartenaire);
50
		$('#nom-partenaire').html(nomPartenaire);
51
	});
51
	});
52
 
52
 
53
	// Connexion au SSO
53
	// Connexion au SSO
54
	$('#formulaire-identification').submit(function() {
54
	$('#formulaire-identification').submit(function() {
-
 
55
		connecterUtilisateur();
-
 
56
		return false;
-
 
57
	});
-
 
58
 
-
 
59
	// Déconnexion du SSO
-
 
60
	$('#deconnexion').click(function() {
-
 
61
		deconnecterUtilisateur();
-
 
62
		return false;
-
 
63
	});
-
 
64
 
-
 
65
	// vérification de l'état au chargement
-
 
66
	var urlAuth = baseUrlAuth + '/identite';
-
 
67
	$.ajax({
-
 
68
	    url: urlAuth,
-
 
69
	    type: "GET",
-
 
70
	    dataType: 'json',
-
 
71
	    xhrFields: {
-
 
72
	         withCredentials: true
-
 
73
	    }
-
 
74
	}).done(function(data) {
-
 
75
		// connecté
-
 
76
		definirUtilisateur(data.token);
-
 
77
		afficherPanneauBienvenue();
-
 
78
	})
-
 
79
	.fail(function(error) {
-
 
80
		// non connecté
-
 
81
		afficherPanneauIdentification();
-
 
82
	});
-
 
83
 
-
 
84
	// exécuter une action si définie (par ex: déconnexion)
-
 
85
	executerAction();
-
 
86
});
-
 
87
 
-
 
88
/**
-
 
89
 * Connecte l'utilisateur au SSO
-
 
90
 */
-
 
91
function connecterUtilisateur() {
55
		var login = $('#login').val(),
92
	var login = $('#login').val(),
56
			mdp = $('#mdp').val();
93
		mdp = $('#mdp').val();
57
		if (login == '' || mdp == '') {
94
	if (login == '' || mdp == '') {
58
			alert('Veuillez entrer votre login et votre mot de passe');
95
		alert('Veuillez entrer votre login et votre mot de passe');
59
		} else {
96
	} else {
60
			var urlAuth = baseUrlAuth + '/connexion?login=' + login + '&password=' + mdp;
97
		var urlAuth = baseUrlAuth + '/connexion?login=' + login + '&password=' + mdp;
61
			$.ajax({
98
		$.ajax({
62
			    url: urlAuth,
99
		    url: urlAuth,
63
			    type: "GET",
100
		    type: "GET",
64
			    dataType: 'json',
101
		    dataType: 'json',
65
			    xhrFields: {
102
		    xhrFields: {
66
			         withCredentials: true
103
		         withCredentials: true
67
			    }
104
		    }
68
			})
105
		})
69
			.done(function(data) {
106
		.done(function(data) {
-
 
107
			rediriger();
70
				definirUtilisateur(data.token);
108
			definirUtilisateur(data.token);
71
				afficherPanneauBienvenue();
109
			afficherPanneauBienvenue();
72
				masquerErreurs();
110
			masquerErreurs();
73
			})
111
		})
74
			.fail(function(error) {
112
		.fail(function(error) {
75
				afficherErreurLogin();
113
			afficherErreurLogin();
76
			});
114
		});
77
		}
115
	}
78
		return false;
-
 
79
	});
116
}
-
 
117
 
80
 
118
/**
-
 
119
 * Déconnecte l'utilisateur du SSO
81
	// Déconnexion du SSO
120
 */
82
	$('#deconnexion').click(function() {
121
function deconnecterUtilisateur() {
83
		var urlAuth = baseUrlAuth + '/deconnexion';
122
	var urlAuth = baseUrlAuth + '/deconnexion';
84
		$.ajax({
123
	$.ajax({
85
		    url: urlAuth,
124
	    url: urlAuth,
86
		    type: "GET",
125
	    type: "GET",
87
		    dataType: 'json',
126
	    dataType: 'json',
88
		    xhrFields: {
127
	    xhrFields: {
89
		         withCredentials: true
128
	         withCredentials: true
90
		    }
129
	    }
91
		})
130
	})
92
		.done(function(data) {
131
	.done(function(data) {
-
 
132
		rediriger();
93
			definirUtilisateur();
133
		definirUtilisateur();
94
			afficherPanneauIdentification();
134
		afficherPanneauIdentification();
95
			masquerErreurs();
135
		masquerErreurs();
96
		})
136
	})
97
		.fail(function(error) {
137
	.fail(function(error) {
98
			// @TODO gérer l'affichage de l'erreur, mais pas facile à placer
138
		// @TODO gérer l'affichage de l'erreur, mais pas facile à placer
99
			// dans l'interface actuelle sans que ce soit moche
139
		// dans l'interface actuelle sans que ce soit moche
100
			//afficherErreurServeur();
140
		//afficherErreurServeur();
101
		});
141
	});
102
		return false;
-
 
103
	});
142
}
-
 
143
 
104
 
144
/**
105
	// vérification de l'état au chargement
145
 * Si la variable "action" est définie (provenant du paramètre GET "origine"),
106
	var urlAuth = baseUrlAuth + '/identite';
146
 * exécute l'action associée (par ex: déconnexion)
-
 
147
 */
107
	$.ajax({
148
function executerAction() {
108
	    url: urlAuth,
149
	switch (action) {
109
	    type: "GET",
150
		case "deconnexion":
-
 
151
			deconnecterUtilisateur();
110
	    dataType: 'json',
152
			break;
111
	    xhrFields: {
153
		default :
-
 
154
			// on ne fait rien
112
	         withCredentials: true
155
	}
113
	    }
-
 
114
	}).done(function(data) {
-
 
115
		// connecté
-
 
116
		definirUtilisateur(data.token);
-
 
117
		afficherPanneauBienvenue();
-
 
118
	})
-
 
119
	.fail(function(error) {
-
 
120
		// non connecté
-
 
121
		afficherPanneauIdentification();
-
 
122
	});
156
}
123
 
157
 
124
	function definirUtilisateur(jeton) {
158
function definirUtilisateur(jeton) {
125
		var nomComplet = '';
159
	var nomComplet = '';
126
		if (jeton != undefined) {
160
	if (jeton != undefined) {
127
			// décodage jeton
161
		// décodage jeton
128
			var jetonDecode = decoderJeton(jeton);
162
		var jetonDecode = decoderJeton(jeton);
129
			nomComplet = jetonDecode.intitule;
163
		nomComplet = jetonDecode.intitule;
130
		}
164
	}
131
		// affichage
165
	// affichage
132
		$('#nom-complet').html(nomComplet);
166
	$('#nom-complet').html(nomComplet);
133
	}
167
}
134
 
168
 
135
    /**
169
/**
136
     * Décodage à l'arrache d'un jeton JWT, ATTENTION CONSIDERE QUE LE
170
 * Décodage à l'arrache d'un jeton JWT, ATTENTION CONSIDERE QUE LE
137
     * JETON EST VALIDE, ne pas décoder n'importe quoi - pas trouvé de lib simple
171
 * JETON EST VALIDE, ne pas décoder n'importe quoi - pas trouvé de lib simple
138
     * Si pb de cross-browser, tenter ceci : https://code.google.com/p/javascriptbase64/
172
 * Si pb de cross-browser, tenter ceci : https://code.google.com/p/javascriptbase64/
139
     * ou ceci : https://code.google.com/p/crypto-js
173
 * ou ceci : https://code.google.com/p/crypto-js
140
     */
174
 */
141
    function decoderJeton(jeton) {
175
function decoderJeton(jeton) {
142
        parts = jeton.split('.');
176
	parts = jeton.split('.');
143
        payload = parts[1];
177
	payload = parts[1];
144
        payload = atob(payload);
178
	payload = atob(payload);
145
        payload = JSON.parse(payload, true);
179
	payload = JSON.parse(payload, true);
146
 
180
 
147
        return payload;
181
	return payload;
148
    }
182
}
-
 
183
 
-
 
184
/**
-
 
185
 * Si la variable "origine" est définie (provenant du paramètre GET "origine"),
-
 
186
 * redirige l'utilisateur vers cette page
-
 
187
 */
-
 
188
function rediriger() {
-
 
189
	if (origine != '') {
-
 
190
		window.location.href = origine;
-
 
191
	}
-
 
192
}
149
 
193
 
150
	function afficherPanneauIdentification() {
194
function afficherPanneauIdentification() {
151
		$('#panneau-identification').show();
195
	$('#panneau-identification').show();
152
		$('#panneau-bienvenue').hide();
196
	$('#panneau-bienvenue').hide();
153
	}
197
}
154
 
198
 
155
	function afficherPanneauBienvenue() {
199
function afficherPanneauBienvenue() {
156
		$('#panneau-identification').hide();
200
	$('#panneau-identification').hide();
157
		$('#panneau-bienvenue').show();
201
	$('#panneau-bienvenue').show();
158
	}
202
}
159
 
203
 
160
	function afficherErreurLogin() {
204
function afficherErreurLogin() {
161
		$('#info-erreur-login').show();
205
	$('#info-erreur-login').show();
162
	}
206
}
163
 
207
 
164
	function afficherErreurServeur() {
208
function afficherErreurServeur() {
165
		$('#info-erreur-serveur').show();
209
	$('#info-erreur-serveur').show();
166
	}
210
}
167
 
211
 
168
	function masquerErreurs() {
212
function masquerErreurs() {
169
		$('.info-erreur').hide();
213
	$('.info-erreur').hide();
170
	}
214
}
171
});
-
 
172
215