register.js

来自「在线编辑器」· JavaScript 代码 · 共 119 行

JS
119
字号
/* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1 * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. * See the License for the specific language governing rights and * limitations under the License. * * The Original Code is Bespin. * * The Initial Developer of the Original Code is Mozilla. * Portions created by the Initial Developer are Copyright (C) 2009 * the Initial Developer. All Rights Reserved. * * Contributor(s): *   Bespin Team (bespin@mozilla.com) * * ***** END LICENSE BLOCK ***** */ dojo.provide("bespin.user.register"); // Login, logout and registration functions for the Bespin front page.     (function(){    var svr = new bespin.client.Server();     var utils = bespin.user.utils;         dojo.mixin(bespin.user, {        login: function() {            if (utils.showingBrowserCompatScreen()) return;            if (dojo.byId("username").value && dojo.byId("password").value) {                // try to find the httpSessionId                var cookies = document.cookie.split(';');                var foundValue = "";                for (var i = 0; i < cookies.length; i++) {                    var cookie = cookies[i];                    while (cookie.charAt(0) == ' ') cookie = cookie.substring(1, cookie.length);                    if (cookie.indexOf("anticsrf=") == 0) {                        foundValue = cookie.substring(dwr.engine._sessionCookieName.length + 1, cookie.length);                        break;                    }                }                svr.login(dojo.byId("username").value, dojo.byId("password").value,                     foundValue,                     utils.whenLoginSucceeded,                    utils.whenLoginFailed);            } else {                utils.showStatus("Please give me both a username and a password");            }        },        logout: function() {            svr.logout();             dojo.style('logged_in', 'display', 'none');            dojo.style('not_logged_in', 'display', 'block');        }        });         dojo.mixin(bespin.user.register, {        checkUsername:function() {            var username_error = [];            var username = dojo.byId("register_username").value;            if (username.length < 4) {                username_error.push("Usernames must be at least 4 characters long");               }            if (/[<>| '"]/.test(username)) {                username_error.push("Usernames must not contain any of: <>| '\"");               }            dojo.byId('register_username_error').innerHTML = username_error.join(", ");        },        checkPassword:function() {            dojo.byId('register_password_error').innerHTML = (dojo.byId('register_password').value.length < 6) ? "Passwords must be at least 6 characters long" : "";        },        checkConfirm:function() {            dojo.byId('register_confirm_error').innerHTML = (dojo.byId('register_password').value != dojo.byId('register_confirm').value) ? "Passwords do not match" : "";        },        checkEmail:function() {            dojo.byId('register_email_error').innerHTML = (!utils.validateEmail(dojo.byId('register_email').value)) ? "Invalid email address" : "";        },        showForm:function() {            if (utils.showingBrowserCompatScreen()) return;            dojo.style('logged_in', 'display', 'none');            dojo.style('not_logged_in', 'display', 'none');            dojo.style('opaque', 'display', 'block');            dojo.style('register_border', 'display', 'block');                        utils.centerOnScreen(dojo.byId('register_border'));          },        hideForm:function() {                                             dojo.style('opaque', 'display', 'none');             dojo.style('register_border', 'display', 'none');            svr.currentuser(utils.whenAlreadyLoggedIn, utils.whenNotAlreadyLoggedIn);        },        send:function() {            this.hideForm();            svr.signup(dojo.byId("register_username").value,                 dojo.byId("register_password").value,                 dojo.byId('register_email').value,                 utils.whenLoginSucceeded,                 utils.whenLoginFailed,                 utils.whenUsernameInUse);        },        cancel:function() {             this.hideForm();        }    });              dojo.addOnLoad(function(){        bespin.displayVersion();        svr.currentuser(utils.whenAlreadyLoggedIn, utils.whenNotAlreadyLoggedIn);    });})();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?