b422f5d8802d8f26c4907fa14dd5ceecfd827a9b
[euphorik.git] / js / pageRegister.js
1 // coding: utf-8
2 // Copyright 2008 Grégory Burri
3 //
4 // This file is part of Euphorik.
5 //
6 // Euphorik is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // Euphorik is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with Euphorik. If not, see <http://www.gnu.org/licenses/>.
18
19 euphorik.PageRegister = function(client, formateur, util) {
20 this.nom = "register";
21
22 this.client = client;
23 this.formateur = formateur;
24 this.util = util;
25 };
26
27 euphorik.PageRegister.prototype.contenu = function() {
28 return '<form action="" id="register" >' +
29 ' <table>' +
30 ' <tr>' +
31 ' <td>login</td>' +
32 ' <td><input class="login" type="text" size="20" maxlength="20"/><input class="captcha" name="captcha" type="text" size="12"></input></td>' +
33 ' </tr>' +
34 ' <tr>' +
35 ' <td>password</td>' +
36 ' <td><input class="password" type="password" size="20" maxlength="20"/></td>' +
37 ' </tr>' +
38 ' <tr>' +
39 ' <td>password re</td>' +
40 ' <td><input class="passwordRe" type="password" size="20" maxlength="20"/></td>' +
41 ' </tr>' +
42 ' <tr>' +
43 ' <td></td>' +
44 ' <td><button>valider</button>' +
45 ' </tr>' +
46 ' </table>' +
47 '</form>';
48 };
49
50 euphorik.PageRegister.prototype.charger = function() {
51 $("#page form#register").submit(function(){ return false; });
52
53 var thisPage = this;
54
55 $("#page form#register button").click(
56 function() {
57 if ($("#page form#register input.captcha").val() !== "") {
58 return;
59 }
60
61 var login = $("#page form#register input.login").val().trim();
62 var password = $("#page form#register input.password").val();
63 var passwordRe = $("#page form#register input.passwordRe").val();
64
65 if (login === "") {
66 thisPage.util.messageDialogue("Le login ne doit pas être vide");
67 } else if (password === "" && passwordRe === "") {
68 thisPage.util.messageDialogue("Un mot de passe est obligatoire");
69 } else if (password !== passwordRe) {
70 thisPage.util.messageDialogue("Les mots de passes ne correspondent pas");
71 } else if(thisPage.client.enregistrement(login, thisPage.util.md5(password))) {
72 thisPage.util.messageDialogue("Enregistrement réussi");
73 thisPage.pages.afficherPage("minichat");
74 }
75 }
76 );
77 };