<commit_before>/*
 * Licensed to the Sakai Foundation (SF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The SF licenses this file
 * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */


/*global Config, $ */


var sakai = sakai || {};

sakai.newaccount = function(){


    /*global checkUserName */

    /////////////////////////////
    // Configuration variables //
    /////////////////////////////

    var defaultUserType = "default";
    var pagestemplate = "defaultuser";

    // Links and labels
    var checkUserNameLink = "#checkUserName ";
    var buttonsContainer = ".create_account_button_bar";
    var successMessage = "#success_message";

    // Input fields
    var username = "username";
    var firstName = "firstName";
    var lastName = "lastName";
    var email = "email";
    var password = "password";
    var passwordRepeat = "<PASSWORD>";
    var captcha = "<PASSWORD>";
    var usernameField = "#" + username;
    var firstNameField = "#" + firstName;
    var lastNameField = "#" + lastName;
    var emailField = "#" + email;
    var passwordField = "#" + password;
    var passwordRepeatField = "#" + passwordRepeat;
    var captchaField = "#" + captcha;

    // Error fields
    var usernameTaken = usernameField + "_taken";
    var usernameShort = usernameField + "_short";
    var usernameSpaces = usernameField + "_spaces";
    var usernameNoGroup = usernameField + "_no_group";
    var usernameEmpty = usernameField + "_empty";
    var firstNameEmpty = firstNameField + "_empty";
    var lastNameEmpty = lastNameField + "_empty";
    var emailEmpty = emailField + "_empty";
    var emailInvalid = emailField + "_invalid";
    var passwordEmpty = passwordField + "_empty";
    var passwordShort = passwordField + "_short";
    var passwordRepeatEmpty = passwordRepeatField + "_empty";
    var passwordRepeatNoMatch = passwordRepeatField + "_nomatch";
    var captchaEmpty = captchaField + "_empty";
    var captchaNoMatch = captchaField + "_nomatch";
    var errorFields = ".create_account_error_msg";
    var usernameLabel = "#username_label";
    var inputFields = ".create_account_input";
    var usernameAvailable = "#username_available";

    //CSS Classes
    var invalidFieldClass = "invalid";
    var formContainer = "#create_account_form";
    var inputFieldHoverClass = "input_field_hover";

    // Contains executable errors
    var errObj = [];

    ///////////////////////
    // Utility functions //
    ///////////////////////

    /**
     * Function that will check whether an email address is valid
     * @param String email
     *  The email address we want to check
     * @return boolean
     *  true:  the email address is valid.
     *  false: the email address is invalid.
     */
    var echeck = function(email) {
        var at="@";
        var dot=".";
        var lat=email.indexOf(at);
        var lstr=email.length;
        var ldot=email.indexOf(dot);

        // Check whether there is an @ sign in the email address, whether the first letter
        // is an @ sign or whether the last character of the email address is an @ sign
        if (email.indexOf(at)===-1 || email.indexOf(at)===0 || email.indexOf(at)===lstr){
           return false;
        }

        // Check whether there is a . sign in the email address, whether the first letter
        // is a . sign or whether the last character of the email address is a . sign
        if (email.indexOf(dot)===-1 || email.indexOf(dot)===0 || email.indexOf(dot)===lstr){
            return false;
        }

        // Check whether there is only 1 @ sign
        if (email.indexOf(at,(lat+1))!==-1){
            return false;
        }

        // Check whether there is no . directly behind the @ sign
        if (email.substring(lat-1,lat)===dot || email.substring(lat+1,lat+2)===dot){
            return false;
        }

        // Check whether there is a . sign behind the @ sign somewhere
        if (email.indexOf(dot,(lat+2))===-1){
            return false;
        }

        // Check whether there are no spaces in the email address
        if (email.indexOf(" ")!==-1){
            return false;
         }

         return true;
    };

    /**
     * Function that will check whether a field is empty or contains spaces only
     * @param String field
     *  ID of the field we would like to check
     * @return boolean
     *  true:  the field is empty or contains spaces only
     *  false: the field contains real input
     */
    var checkEmpty = function(field){
        var value = $(field).val();
        if (!value || value.replace(/ /g,"") === ""){
            return true;
        } else {
            return false;
        }
    };

    /**
     * Get all of the values out of the form fields. This will return
     * a JSON object where the keys are the names of all of the form fields, and the values are
     * the values entered by the user in those fields.
     */
    var getFormValues = function(){
        // Get the values from the form.
        var values = sakai.api.UI.Forms.form2json($(formContainer));

        // Get the values from the captcha form.
        var captchaValues = sakai.captcha.getProperties();

        // Add them to the form values.
        jQuery.extend(values, captchaValues);

        return values;
    };


    ////////////////////
    // Error handling //
    ////////////////////

    var resetErrorFields = function(){
        $("input").removeClass(invalidFieldClass);
        $(errorFields).hide();
        $(usernameAvailable).hide();
    };

    /**
     * Function that will visually mark a form field as an<commit_msg>SAKIII-649 Escaping unicode characters in create account screen<commit_after>/*
 * Licensed to the Sakai Foundation (SF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The SF licenses this file
 * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */


/*global Config, $ */


var sakai = sakai || {};

sakai.newaccount = function(){


    /*global checkUserName */

    /////////////////////////////
    // Configuration variables //
    /////////////////////////////

    var defaultUserType = "default";
    var pagestemplate = "defaultuser";

    // Links and labels
    var checkUserNameLink = "#checkUserName ";
    var buttonsContainer = ".create_account_button_bar";
    var successMessage = "#success_message";

    // Input fields
    var username = "username";
    var firstName = "firstName";
    var lastName = "lastName";
    var email = "email";
    var password = "password";
    var passwordRepeat = "<PASSWORD>";
    var captcha = "<PASSWORD>";
    var usernameField = "#" + username;
    var firstNameField = "#" + firstName;
    var lastNameField = "#" + lastName;
    var emailField = "#" + email;
    var passwordField = "#" + password;
    var passwordRepeatField = "#" + passwordRepeat;
    var captchaField = "#" + captcha;

    // Error fields
    var usernameTaken = usernameField + "_taken";
    var usernameShort = usernameField + "_short";
    var usernameSpaces = usernameField + "_spaces";
    var usernameNoGroup = usernameField + "_no_group";
    var usernameEmpty = usernameField + "_empty";
    var firstNameEmpty = firstNameField + "_empty";
    var lastNameEmpty = lastNameField + "_empty";
    var emailEmpty = emailField + "_empty";
    var emailInvalid = emailField + "_invalid";
    var passwordEmpty = passwordField + "_empty";
    var passwordShort = passwordField + "_short";
    var passwordRepeatEmpty = passwordRepeatField + "_empty";
    var passwordRepeatNoMatch = passwordRepeatField + "_nomatch";
    var captchaEmpty = captchaField + "_empty";
    var captchaNoMatch = captchaField + "_nomatch";
    var errorFields = ".create_account_error_msg";
    var usernameLabel = "#username_label";
    var inputFields = ".create_account_input";
    var usernameAvailable = "#username_available";

    //CSS Classes
    var invalidFieldClass = "invalid";
    var formContainer = "#create_account_form";
    var inputFieldHoverClass = "input_field_hover";

    // Contains executable errors
    var errObj = [];

    ///////////////////////
    // Utility functions //
    ///////////////////////

    /**
     * Function that will check whether an email address is valid
     * @param String email
     *  The email address we want to check
     * @return boolean
     *  true:  the email address is valid.
     *  false: the email address is invalid.
     */
    var echeck = function(email) {
        var at="@";
        var dot=".";
        var lat=email.indexOf(at);
        var lstr=email.length;
        var ldot=email.indexOf(dot);

        // Check whether there is an @ sign in the email address, whether the first letter
        // is an @ sign or whether the last character of the email address is an @ sign
        if (email.indexOf(at)===-1 || email.indexOf(at)===0 || email.indexOf(at)===lstr){
           return false;
        }

        // Check whether there is a . sign in the email address, whether the first letter
        // is a . sign or whether the last character of the email address is a . sign
        if (email.indexOf(dot)===-1 || email.indexOf(dot)===0 || email.indexOf(dot)===lstr){
            return false;
        }

        // Check whether there is only 1 @ sign
        if (email.indexOf(at,(lat+1))!==-1){
            return false;
        }

        // Check whether there is no . directly behind the @ sign
        if (email.substring(lat-1,lat)===dot || email.substring(lat+1,lat+2)===dot){
            return false;
        }

        // Check whether there is a . sign behind the @ sign somewhere
        if (email.indexOf(dot,(lat+2))===-1){
            return false;
        }

        // Check whether there are no spaces in the email address
        if (email.indexOf(" ")!==-1){
            return false;
         }

         return true;
    };

    /**
     * Function that will check whether a field is empty or contains spaces only
     * @param String field
     *  ID of the field we would like to check
     * @return boolean
     *  true:  the field is empty or contains spaces only
     *  false: the field contains real input
     */
    var checkEmpty = function(field){
        var value = $(field).val();
        if (!value || value.replace(/ /g,"") === ""){
            return true;
        } else {
            return false;
        }
    };

    /**
     * Get all of the values out of the form fields. This will return
     * a JSON object where the keys are the names of all of the form fields, and the values are
     * the values entered by the user in those fields.
     */
    var getFormValues = function(){
        // Get the values from the form.
        var values = sakai.api.UI.Forms.form2json($(formContainer));

        for (var i in values){
            values[i] = escape(values[i]);
        };

        // Get the values from the captcha form.
        var captchaValues = sakai.captcha.getProperties();

        // Add them to the form values.
        jQuery.extend(values, captchaValues);

        return values;
    };


    ////////////////////
    // Error handling //
    ////////////////////

    var resetErrorFields = function(){
        $("input").removeClass(invalidFieldClass);
        $(errorFields).hide();
        $(usernameAvailable).hide();
    };

    /**
     * Function that will visually mark a form field as an
{'fraction_non_alphanumeric': 0.1252973830293418, 'fraction_numerical': 0.003092783505154639, 'mean_word_length': 2.28325956782088, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '651923', 'n_tokens_mistral': 3342, 'n_tokens_neox': 3261, 'n_words': 1209}