+function hashResponse(password1, password2, hasConfirmation, doAuth) {
+ var pw1 = $('[name=' + password1 + ']').val();
+ var pw2;
+
+ if (hasConfirmation) {
+ pw2 = $('[name=' + password2 + ']').val();
+ if (pw1 !== pw2) {
+ alert("\nErreur : les deux champs ne sont pas identiques !");
+ return false;
+ }
+ $('[name=' + password2 + ']').val('');
+ } else if (pw1 === '********') {
+ return true;
+ }
+
+ if (pw1.length < 6) {
+ alert("\nErreur : le nouveau mot de passe doit faire au moins 6 caractères !");
+ return false;
+ }
+ if (!differentTypes(pw1)) {
+ alert ("\nErreur : le nouveau mot de passe doit comporter au moins deux types de caractères parmi les suivants : lettres minuscules, lettres majuscules, chiffres, caractères spéciaux.");
+ return false;
+ }
+
+ alert("Le mot de passe va être chiffré avant de nous parvenir par Internet ! Ainsi il ne circulera pas en clair.");
+ $('[name=' + password1 + ']').val('');
+ $('[name=pwhash]').val(hash_encrypt(pw1));
+
+ if (doAuth) {
+ $('[name=password]').val(pw1);
+ doChallengeResponse();
+ }
+
+ return true;
+}
+
+function correctUserName() {
+ var u = document.forms.login.username;
+ var mots;
+
+ // login with no space
+ if (!u.value.contains(' ')) {
+ return true;
+ }
+ mots = u.value.split(' ');
+ // jean paul.du pont -> jean-paul.du-pont
+ if (u.value.contains('.')) {
+ u.value = mots.join('-');
+ return true;
+ }
+ // jean dupont -> jean.dupont
+ if (mots.length === 2) {
+ u.value = mots[0] + "." + mots[1];
+ return true;
+ }
+ // jean dupont 2001 -> jean.dupont.2001
+ if (mots.length === 3 && mots[2] > 1920 && mots[2] < 3000) {
+ u.value = mots.join('.');
+ return true;
+ }
+ // jean de la vallee -> jean.de-la-vallee
+ if (mots[1].toUpperCase() === 'DE') {
+ u.value = mots[0] + "." + mots.join('-').substr(mots[0].length+1);
+ return true;
+ }
+ // jean paul dupont -> jean-paul.dupont
+ if (mots.length === 3 && mots[0].toUpperCase() === 'JEAN') {
+ u.value = mots[0] + "-" + mots[1] + "." + mots[2];
+ return true;
+ }
+
+ alert('Ton email ne doit pas contenir de blanc.\nLe format standard est\n\nprenom.nom.promotion\n\nSi ton nom ou ton prenom est composé,\nsépare les mots par des -');
+
+ return false;
+}
+
+function doChallengeResponse() {
+ var new_pass, old_pass, str;
+
+ if (!correctUserName()) {
+ return false;
+ }
+
+ new_pass = hash_encrypt(document.forms.login.password.value);
+ old_pass = hash_encrypt(document.forms.login.password.value.substr(0, 10));
+
+ str = document.forms.login.username.value + ":" +
+ new_pass + ":" +
+ document.forms.loginsub.challenge.value;
+
+ document.forms.loginsub.response.value = hash_encrypt(str);
+ if (new_pass !== old_pass) {
+ document.forms.loginsub.xorpass.value = hash_xor(new_pass, old_pass);
+ }
+ document.forms.loginsub.username.value = document.forms.login.username.value;
+ document.forms.loginsub.remember.value = document.forms.login.remember.checked;
+ document.forms.loginsub.domain.value = document.forms.login.domain.value;
+ document.forms.login.password.value = "";
+ document.forms.loginsub.submit();
+}
+
+function doChallengeResponseLogged() {
+ var str = document.forms.loginsub.username.value + ":" +
+ hash_encrypt(document.forms.login.password.value) + ":" +
+ document.forms.loginsub.challenge.value;
+
+ document.forms.loginsub.response.value = hash_encrypt(str);
+ document.forms.loginsub.remember.value = document.forms.login.remember.checked;
+ document.forms.login.password.value = "";
+ document.forms.loginsub.submit();
+}
+
+// }}}
+// {{{ send test email
+
+function sendTestEmail(token, hruid)
+{
+ var url = 'emails/test';
+ var msg = "Un email a été envoyé avec succès";
+ if (hruid) {
+ url += '/' + hruid;
+ msg += " sur l'adresse de " + hruid + ".";
+ } else {
+ msg += " sur ton addresse.";
+ }
+ $('#mail_sent').successMessage(url + '?token=' + token, msg);
+ return false;
+}
+
+// }}}
+// {{{ jQuery object extension
+
+(function($) {
+ /* Add new functions to jQuery namesapce */
+ $.extend({
+ /* The goal of the following functions is to provide an AJAX API that
+ * take a different callback in case of HTTP success code (2XX) and in
+ * other cases.
+ */
+
+ xajax: function(source, method, data, onSuccess, onError, type) {
+ /* Shift argument */
+ if ($.isFunction(data)) {
+ type = type || onError;
+ onError = onSuccess;
+ onSuccess = data;
+ data = null;
+ }
+ if (onError != null && !$.isFunction(onError)) {
+ type = type || onError;
+ onError = null;
+ }
+
+ function ajaxHandler(data, textStatus, xhr) {
+ if (textStatus == 'success') {
+ if (onSuccess) {
+ onSuccess(data, textStatus, xhr);
+ }
+ } else if (textStatus == 'error') {
+ if (onError) {
+ onError(data, textStatus, xhr);
+ } else {
+ alert("Une error s'est produite lors du traitement de la requête.\n"
+ + "Ta session a peut-être expiré");
+ }
+ }
+ }
+ return $.ajax({
+ url: source,
+ type: method,
+ success: ajaxHandler,
+ data : data,
+ dataType: type
+ });
+ },
+
+ xget: function(source, data, onSuccess, onError, type) {
+ return $.xajax(source, 'GET', data, onSuccess, onError, type);
+ },
+
+ xgetJSON: function(source, data, onSuccess, onError) {
+ return $.xget(source, data, onSuccess, onError, 'json');
+ },
+
+ xgetScript: function(source, onSuccess, onError) {
+ return $.xget(source, null, onSuccess, onError, 'script');
+ },
+
+ xgetText: function(source, data, onSuccess, onError) {
+ return $.xget(source, data, onSuccess, onError, 'text');
+ },
+
+ xpost: function(source, data, onSuccess, onError, type) {
+ return $.xajax(source, 'POST', data, onSuccess, onError, type);
+ }
+ });
+
+ /* Add new functions to jQuery objects */
+ $.fn.extend({
+ tmpMessage: function(message, success) {
+ if (success) {
+ this.html("<img src='images/icons/wand.gif' alt='' /> " + message)
+ .css('color', 'green');
+ } else {
+ this.html("<img src='images/icons/error.gif' alt='' /> " + message)
+ .css('color', 'red');
+ }
+ return this.css('fontWeight', 'bold')
+ .show()
+ .delay(1000)
+ .fadeOut(500);
+ },
+
+ updateHtml: function(source, callback) {
+ var elements = this;
+ function handler(data) {
+ elements.html(data);
+ if (callback) {
+ callback(data);
+ }
+ }
+ $.xget(source, handler, 'text');
+ return this;
+ },
+
+ successMessage: function(source, message) {
+ var elements = this;
+ $.xget(source, function() {
+ elements.tmpMessage(message, true);
+ });
+ return this;
+ },
+
+ wiki: function(text, withTitle) {
+ if (text == '') {
+ return this.html('');
+ }
+ var url = 'wiki_preview';
+ if (!withTitle) {
+ url += '/notitile';
+ }
+ var $this = this;
+ $.post(url, { text: text },
+ function (data) {
+ $this.html(data);
+ }, 'text');
+ return this;
+ },
+
+ popWin: function(w, h) {
+ return this.click(function() {
+ window.open(this.href, '_blank',
+ 'toolbar=0,location=0,directories=0,status=0,'
+ +'menubar=0,scrollbars=1,resizable=1,'
+ +'width='+w+',height='+h);
+ return false;
+ });
+ }
+ });
+})(jQuery);
+
+// }}}
+// {{{ preview wiki
+
+function previewWiki(idFrom, idTo, withTitle, idShow)
+{
+ $('#' + idTo).wiki($('#' + idFrom).val(), withTitle);
+ if (idShow != null) {
+ $('#' + idShow).show();
+ }
+}
+
+// }}}
+// {{{ send test email
+
+function sendTestEmail(token, hruid)
+{
+ var url = 'emails/test';
+ var msg = "Un email a été envoyé avec succès";
+ if (hruid != null) {
+ url += '/' + hruid;
+ msg += " sur l'adresse de " + hruid + ".";
+ } else {
+ msg += " sur ton addresse.";
+ }
+ $('#mail_sent').successMessage($url + '?token=' + token, msg);
+ return false;
+}
+