<commit_before>'use strict';

angular.module('arachne.controllers')

/**
 * Register Form Controller.
 * @see partials/register.html.
 */
.controller('RegisterController', [ '$scope', '$http', '$filter', 'message', 'arachneSettings',
function ( $scope, $http, $filter, message, arachneSettings) {

    /**
     * Sends the account registration request to the backend
     * and reports if it was successful. If it was not successful,
     * the callback will get a message with an explanation.
     *
     * @param user the user object.
     * @return callback(isSuccess:boolean,message:string)
     */
    var register= function(user,callback){

        // The original user object will be copied so the original does not get modified.
        // The copy get send to the backend and will contain the md5 encrypted pwd. If that would
        // modify the reference which is bound to the scope
        // and the request would be rejected, the md5 passes would enter
        // the form and upon a successful request it would be encrypted again and as a result
        // unusable as it would be different from what the user entered.
        var newUser= JSON.parse(JSON.stringify(user))

        if (user.password)
            newUser.password = $filter('<PASSWORD>')(user.password);
        if (user.passwordValidation)
            newUser.passwordValidation = $filter('md5')(user.passwordValidation);

        $http.post(arachneSettings.dataserviceUri + "/user/register", newUser, {
            "headers": { "Content-Type": "application/json" }

        }).success(function(data) {
            return callback(true,null);
        }).error(function(data) {
            return callback(false,data.message);
        });
    };


    $scope.submit = function() {
        register($scope.user,
            function(isSuccess,msg){
            if(isSuccess)
                message.addMessageForCode('register_success', 'success');
            else
                message.addMessageForCode(msg, 'danger');
        });
    };
}]);<commit_msg>Improve ux for register by handling messages better.<commit_after>'use strict';

angular.module('arachne.controllers')

/**
 * Register Form Controller.
 * @see partials/register.html.
 *
 * $scope
 *   success set to true to signal success to the view.
 */
.controller('RegisterController', [ '$scope', '$http', '$filter', 'message', 'arachneSettings',
function ( $scope, $http, $filter, message, arachneSettings) {

    /**
     * Sends the account registration request to the backend
     * and reports if it was successful. If it was not successful,
     * the callback will get a message with an explanation.
     *
     * @param user the user object.
     * @return callback(isSuccess:boolean,message:string)
     */
    var register= function(user,callback){

        // The original user object will be copied so the original does not get modified.
        // The copy get send to the backend and will contain the md5 encrypted pwd. If that would
        // modify the reference which is bound to the scope
        // and the request would be rejected, the md5 passes would enter
        // the form and upon a successful request it would be encrypted again and as a result
        // unusable as it would be different from what the user entered.
        var newUser= JSON.parse(JSON.stringify(user))

        if (user.password)
            newUser.password = $filter('md5')(user.password);
        if (user.passwordValidation)
            newUser.passwordValidation = $filter('md5')(user.passwordValidation);

        $http.post(arachneSettings.dataserviceUri + "/user/register", newUser, {
            "headers": { "Content-Type": "application/json" }

        }).success(function(data) {
            return callback(true,null);
        }).error(function(data) {
            return callback(false,data.message);
        });
    };


    $scope.submit = function() {
        register($scope.user,
            function(isSuccess,msg){

                message.clear();
                if(isSuccess) {
                    message.addMessageForCode('register_success', 'success');
                    $scope.success=true;
                }
                else
                    message.addMessageForCode(msg, 'danger', false);
        });
    };
}]);
{'fraction_non_alphanumeric': 0.11095603628750872, 'fraction_numerical': 0.0016282856478250756, 'mean_word_length': 2.4593724859211585, 'pattern_counts': {'":': 4, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, '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': '7628643', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1086, 'n_words': 359}