<commit_before>/**
 * http://www.privacyidea.org
 * (c) <NAME>, <EMAIL>
 *
 * 2015-01-11 <NAME>, <<EMAIL>>
 *
 * This code is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
angular.module("privacyideaAuth", [])
    .factory("AuthFactory", function (inform, $state) {
        /*
        Each service - just like this service factory - is a singleton.
        Here we just store the username of the authenticated user and his
        auth_token.
         */
        var user = {};

        return {
            setUser: function (username, realm, auth_token, role, rights, menus) {
                user.username = username;
                user.realm = realm;
                user.auth_token = auth_token;
                user.role = role;
                user.rights = rights;
                user.menus = menus;
            },
            authError: function(error) {
                var authErrorCodes = Array(403, 4031, 4032, 4033, 4034, 4035, 4036);
                inform.add(error.result.error.message, {type: "danger", ttl: 10000});
                if (authErrorCodes.indexOf(error.result.error.code) >= 0) {
                    if ($state.current.controller === "registerController" ) {
                        $state.go('register');
                    } else if ($state.current.controller === "recoveryController") {
                        $state.go('recovery');
                    } else {
                        $state.go('login');
                    }
                }<commit_msg>Display error messages in case of 404<commit_after>/**
 * http://www.privacyidea.org
 * (c) <NAME>, <EMAIL>
 *
 * 2015-01-11 <NAME>, <<EMAIL>>
 *
 * This code is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
angular.module("privacyideaAuth", [])
    .factory("AuthFactory", function (inform, gettextCatalog, $state) {
        /*
        Each service - just like this service factory - is a singleton.
        Here we just store the username of the authenticated user and his
        auth_token.
         */
        var user = {};

        return {
            setUser: function (username, realm, auth_token, role, rights, menus) {
                user.username = username;
                user.realm = realm;
                user.auth_token = auth_token;
                user.role = role;
                user.rights = rights;
                user.menus = menus;
            },
            authError: function(error) {
                var authErrorCodes = Array(403, 4031, 4032, 4033, 4034, 4035, 4036);
                if (typeof (error) === "string") {
                    inform.add(gettextCatalog.getString("Failed to get a valid JSON response from the privacyIDEA server."),
                        {type: "danger", ttl: 10000});
                } else {
                    inform.add(error.result.error.message, {type: "danger", ttl: 10000});
                    if (authErrorCodes.indexOf(error.result.error.code) >= 0) {
                        if ($state.current.controller === "registerController" ) {
                            $state.go('register');
                        } else if ($state.current.controller === "recoveryController") {
                            $state.go('recovery');
                        } else {
                            $state.go('login');
                        }
                    }
                }
{'fraction_non_alphanumeric': 0.10220264317180616, 'fraction_numerical': 0.02026431718061674, 'mean_word_length': 1.8310473815461346, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '6956060', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1133, 'n_words': 405}