<commit_before>(function(window){
    define(["jquery"],function($){

        /*
            AccountError is used to report errors through error callback function
            (see details below ). Example usage:

            new AccountError("password","<PASSWORD>")

        */

        var AccountError = function(fieldName, errorDescription){
            return {
                getFieldName : function(){
                    return fieldName;
                },

                getErrorDescription : function(){
                    return errorDescription;
                }
            };
        };


        /*

            Password Setup Id Provider is used to provide ids
            for confirmSetupPassword and setupPassword functions

        */

        var PasswordSetupIdProvider = {
            getId : function(){
                //get query string parameter by name
                return (function(name)
                {
                    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
                    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
                    var results = regex.exec(window.location.search);
                    if(results){
                        return decodeURIComponent(results[1].replace(/\+/g, " "));
                    }
                })("id");
            }
        };


        /*
            Every method accepts 0 or more data values and two callbacks (success and error)

            Success callback spec:

                function success(data){
                    // data includes any additonal data you want to pass back
                }

            Error callback spec:

                function error(errors){
                    // errors is a list of AccountError instances
                }

        */


        return {

            AccountError : AccountError,

            isValidDomain : function(domain){

                //check for the trailing dash
                var d = domain || "", ds = d.split(".codenvy.com");

                if(ds.length === 2){

                    var name = ds[0];

                    if(name[name.length-1] === '-'){
                        return false;
                    }
                }

                return (
                    /^[a-z]{1}[a-z0-9\-]{0,19}\.codenvy\.com/g
                ).exec(domain) !== null ;
            },

            login : function(email,password,domain,success,error){

                // most of the stuff copied from https://github.com/codenvy/cloud-ide/blob/master/cloud-ide-war/src/main/webapp/js/chrome_app.js
                // !! Note :
                //  putting sensitive data (e.g. passwords) as GET parameters is a VERY bad idea
                //  please fix this ASAP and transport this data through POST

                var loginUrl =  "/sso/server/gen" +
                                "?username=" +
                                email +
                                "&password=" +
                                password +
                                "&redirectTenantName=" +
                                domain +
                                "&authType=jaas";

                success({ loginUrl : loginUrl });
            },

            createTenant : function(email,domain,success,error){

                var tenantServiceUrl = "/cloud-admin/rest/cloud-admin/public-tenant-service/create-with-confirm";
                var createTenantUrl = tenantServiceUrl + "/" + encodeURIComponent(domain) + "/" + email;

                var request = $.ajax({
                    url : createTenantUrl,
                    type : "POST",
                    success : function(output, status, xhr){
                        success({url: 'thank-you.jsp'});
                    },
                    error : function(xhr, status, err){
                        error([
                            new AccountError(null,xhr.responseText)
                        ]);
                    }
                });
            },

            recoverPassword : function(email,success,error){
                //implementation based on this:
                //https://github.com/codenvy/cloud-ide/blob/master/cloud-ide-war/src/main/webapp/js/recover-password.js

                // !! Note :
                //  security concern here: flashing email address in GET. should be moved to POST

                var passwordRecoveryService = "/rest/password/recover/",
                    passwordRecoveryUri = passwordRecoveryService + email;

                var request = $.ajax({
                    url : passwordRecoveryUri,
                    type : "POST",
                    success : function(output, status, xhr){
                        success({message: xhr.responseText});
                    },
                    error : function(xhr, status, err){
                        error([
                            new AccountError(null,xhr.responseText)
                        ]);
                    }
                });
            },

            confirmSetupPassword : function(success,error){
                // implementation based on this:
                // https://github.com/codenvy/cloud-ide/blob/master/cloud-ide-war/src/main/webapp/js/setup-password.js
                // just like with setupPassword, we expect the id to be in the url:
                // https://codenvy.com/setup-password.jsp?id=<PASSWORD>9-<PASSWORD>

                var confirmSetupPasswordUrl = "/rest/password/setup-confirmed",
                    id = PasswordSetupIdProvider.getId();

                if(typeof id === 'undefined'){
                    error([
                        new AccountError(null,"Invalid password reset url")<commit_msg>updated account.js to use post requests<commit_after>(function(window){
    define(["jquery"],function($){

        /*
            AccountError is used to report errors through error callback function
            (see details below ). Example usage:

            new AccountError("password","<PASSWORD>")

        */

        var AccountError = function(fieldName, errorDescription){
            return {
                getFieldName : function(){
                    return fieldName;
                },

                getErrorDescription : function(){
                    return errorDescription;
                }
            };
        };


        /*

            Password Setup Id Provider is used to provide ids
            for confirmSetupPassword and setupPassword functions

        */

        var PasswordSetupIdProvider = {
            getId : function(){
                //get query string parameter by name
                return (function(name)
                {
                    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
                    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
                    var results = regex.exec(window.location.search);
                    if(results){
                        return decodeURIComponent(results[1].replace(/\+/g, " "));
                    }
                })("id");
            }
        };


        /*
            Every method accepts 0 or more data values and two callbacks (success and error)

            Success callback spec:

                function success(data){
                    // data includes any additonal data you want to pass back
                }

            Error callback spec:

                function error(errors){
                    // errors is a list of AccountError instances
                }

        */


        return {

            AccountError : AccountError,

            isValidDomain : function(domain){

                //check for the trailing dash
                var d = domain || "", ds = d.split(".codenvy.com");

                if(ds.length === 2){

                    var name = ds[0];

                    if(name[name.length-1] === '-'){
                        return false;
                    }
                }

                return (
                    /^[a-z]{1}[a-z0-9\-]{0,19}\.codenvy\.com/g
                ).exec(domain) !== null ;
            },

            login : function(email,password,domain,success,error){

                // most of the stuff copied from https://github.com/codenvy/cloud-ide/blob/master/cloud-ide-war/src/main/webapp/js/chrome_app.js

                var loginUrl =  "/sso/server/gen";

                var request = $.ajax({
                    url : loginUrl,
                    type : "POST",
                    data: { username: email, password: password, redirectTenantName: domain, oauthType: "jaas" },
                    success : function(output, status, xhr){
                        success({url: 'thank-you.jsp'});
                    },
                    error : function(xhr, status, err){
                        error([
                            new AccountError(null,xhr.responseText)
                        ]);
                    }
                });



            },

            createTenant : function(email,domain,success,error){

                var tenantServiceUrl = "/cloud-admin/rest/cloud-admin/public-tenant-service/create-with-confirm";

                var request = $.ajax({
                    url : tenantServiceUrl,
                    type : "POST",
                    data: { domain: encodeURIComponent(domain), email: email },
                    success : function(output, status, xhr){
                        success({url: 'thank-you.jsp'});
                    },
                    error : function(xhr, status, err){
                        error([
                            new AccountError(null,xhr.responseText)
                        ]);
                    }
                });
            },

            recoverPassword : function(email,success,error){
                //implementation based on this:
                //https://github.com/codenvy/cloud-ide/blob/master/cloud-ide-war/src/main/webapp/js/recover-password.js

                var passwordRecoveryUrl = "/rest/password/recover/";

                var request = $.ajax({
                    url : passwordRecoveryUrl,
                    type : "POST",
                    data: {email : email},
                    success : function(output, status, xhr){
                        success({message: xhr.responseText});
                    },
                    error : function(xhr, status, err){
                        error([
                            new AccountError(null,xhr.responseText)
                        ]);
                    }
                });
            },

            confirmSetupPassword : function(success,error){
                // implementation based on this:
                // https://github.com/codenvy/cloud-ide/blob/master/cloud-ide-war/src/main/webapp/js/setup-password.js
                // just like with setupPassword, we expect the id to be in the url:
                // https://codenvy.com/setup-password.jsp?id=<PASSWORD>-<PASSWORD>-<PASSWORD>

                var confirmSetupPasswordUrl = "/rest/password/setup-confirmed",
                    id = PasswordSetupIdProvider.getId();

                if(typeof id === 'undefined'){
                    error([
                        new AccountError(null,"Invalid password reset url")
{'fraction_non_alphanumeric': 0.10836267605633802, 'fraction_numerical': 0.0020246478873239436, 'mean_word_length': 1.1347237880496055, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, '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': '1050866', 'n_tokens_mistral': 2779, 'n_tokens_neox': 2505, 'n_words': 583}