<commit_before>namespace common.services.auth {

    export const namespace = 'common.services.auth';

    export class AuthService {

        public initialisedPromise:ng.IPromise<any>;

        static $inject:string[] = ['ngJwtAuthService', '$q', '$location', '$timeout', '$mdDialog', '$state', '$mdToast'];

        constructor(private ngJwtAuthService:NgJwtAuth.NgJwtAuthService,
                    private $q:ng.IQService,
                    private $location:ng.ILocationService,
                    private $timeout:ng.ITimeoutService,
                    private $mdDialog:ng.material.IDialogService,
                    private $state:ng.ui.IStateService,
                    private $mdToast:ng.material.IToastService
        ) {

            this.initialisedPromise = this.initialiseJwtAuthService().finally(() => {

                return this.$q.all([
                    this.processQueryToken(),
                    this.processPasswordResetToken()
                ]);

            }).catch((e) => {
                console.error("Auth Initialisation failed: ", e);
            });

        }

        /**
         * Initialise the NgJwtAuthService
         * @returns {ng.IPromise<any>}
         */
        private initialiseJwtAuthService() {

            return this.ngJwtAuthService
                .registerUserFactory((subClaim: string, tokenData: global.JwtAuthClaims): ng.IPromise<common.models.User> => {
                    return this.$q.when(new common.models.User(tokenData._user));
                })
                .registerLoginPromptFactory((deferredCredentials:ng.IDeferred<NgJwtAuth.ICredentials>, loginSuccessPromise:ng.IPromise<NgJwtAuth.IUser>, currentUser:NgJwtAuth.IUser): ng.IPromise<any> => {

                    let dialogConfig:ng.material.IDialogOptions = {
                        templateUrl: 'templates/app/guest/login/login-dialog.tpl.html',
                        controller: 'app.guest.login.controller',
                        controllerAs: 'LoginController',
                        clickOutsideToClose: true,
                        locals : {
                            deferredCredentials: deferredCredentials,
                            loginSuccess: {
                                promise: loginSuccessPromise //nest the promise in a function as otherwise material will try to wait for it to resolve
                            },
                        }
                    };

                    return this.$timeout(_.noop) //first do an empty timeout to allow the controllers to init if login prompt is fired from within a .run() phase
                        .then(() => this.$mdDialog.show(dialogConfig));

                })
                .init(); //initialise the auth service (kicks off the timers etc)

        }

        /**
         * Check the address bar for a new jwt token to process
         * @returns {any}
         */
        private processQueryToken():ng.IPromise<any> {

            this.removeFacebookHash();
            let queryParams = this.$location.search();
            if (queryParams.jwtAuthToken) {

                let queryTokenPromise = this.ngJwtAuthService.processNewToken(queryParams.jwtAuthToken);

                this.$location.search('jwtAuthToken', null);

                return queryTokenPromise;
            }

            return this.$q.when(true); //immediately resolve

        }

        /**
         * Removes the facebook return hash `#_=_`
         */
        private removeFacebookHash():void {

            if (this.$location.hash() == '_=_'){
                this.$location.hash('');
            }

        }

        /**
         * Check the url for password reset token and process it
         * @returns {any}
         */
        private processPasswordResetToken():ng.IPromise<any> {

            let queryParams = this.$location.search();
            if (_.isEmpty(queryParams.passwordResetToken)) {
                return this.$q.when(true); //immediately resolve
            }

            let token = queryParams.passwordResetToken;
            this.$location.search('passwordResetToken', null);

            return this.ngJwtAuthService.exchangeToken(token)
                .catch((err) => {
                    this.$mdToast.show(
                        this.$mdToast.simple()
                            .hideDelay(2000)
                            .position('top right')
                            .content("Sorry, you have already tried to reset your password using this link")
                    );
                });
        }

    }

    angular.module(namespace, [])
        .service('authService', AuthService);

}

<commit_msg>Updating auth service to use notification service.<commit_after>namespace common.services.auth {

    export const namespace = 'common.services.auth';

    export class AuthService {

        public initialisedPromise:ng.IPromise<any>;

        static $inject:string[] = ['ngJwtAuthService', '$q', '$location', '$timeout', '$mdDialog', '$state', 'notificationService'];

        constructor(private ngJwtAuthService:NgJwtAuth.NgJwtAuthService,
                    private $q:ng.IQService,
                    private $location:ng.ILocationService,
                    private $timeout:ng.ITimeoutService,
                    private $mdDialog:ng.material.IDialogService,
                    private $state:ng.ui.IStateService,
                    private notificationService:common.services.notification.NotificationService
        ) {

            this.initialisedPromise = this.initialiseJwtAuthService().finally(() => {

                return this.$q.all([
                    this.processQueryToken(),
                    this.processPasswordResetToken()
                ]);

            }).catch((e) => {
                console.error("Auth Initialisation failed: ", e);
            });

        }

        /**
         * Initialise the NgJwtAuthService
         * @returns {ng.IPromise<any>}
         */
        private initialiseJwtAuthService() {

            return this.ngJwtAuthService
                .registerUserFactory((subClaim: string, tokenData: global.JwtAuthClaims): ng.IPromise<common.models.User> => {
                    return this.$q.when(new common.models.User(tokenData._user));
                })
                .registerLoginPromptFactory((deferredCredentials:ng.IDeferred<NgJwtAuth.ICredentials>, loginSuccessPromise:ng.IPromise<NgJwtAuth.IUser>, currentUser:NgJwtAuth.IUser): ng.IPromise<any> => {

                    let dialogConfig:ng.material.IDialogOptions = {
                        templateUrl: 'templates/app/guest/login/login-dialog.tpl.html',
                        controller: 'app.guest.login.controller',
                        controllerAs: 'LoginController',
                        clickOutsideToClose: true,
                        locals : {
                            deferredCredentials: deferredCredentials,
                            loginSuccess: {
                                promise: loginSuccessPromise //nest the promise in a function as otherwise material will try to wait for it to resolve
                            },
                        }
                    };

                    return this.$timeout(_.noop) //first do an empty timeout to allow the controllers to init if login prompt is fired from within a .run() phase
                        .then(() => this.$mdDialog.show(dialogConfig));

                })
                .init(); //initialise the auth service (kicks off the timers etc)

        }

        /**
         * Check the address bar for a new jwt token to process
         * @returns {any}
         */
        private processQueryToken():ng.IPromise<any> {

            this.removeFacebookHash();
            let queryParams = this.$location.search();
            if (queryParams.jwtAuthToken) {

                let queryTokenPromise = this.ngJwtAuthService.processNewToken(queryParams.jwtAuthToken);

                this.$location.search('jwtAuthToken', null);

                return queryTokenPromise;
            }

            return this.$q.when(true); //immediately resolve

        }

        /**
         * Removes the facebook return hash `#_=_`
         */
        private removeFacebookHash():void {

            if (this.$location.hash() == '_=_'){
                this.$location.hash('');
            }

        }

        /**
         * Check the url for password reset token and process it
         * @returns {any}
         */
        private processPasswordResetToken():ng.IPromise<any> {

            let queryParams = this.$location.search();
            if (_.isEmpty(queryParams.passwordResetToken)) {
                return this.$q.when(true); //immediately resolve
            }

            let token = queryParams.passwordResetToken;
            this.$location.search('passwordResetToken', null);

            return this.ngJwtAuthService.exchangeToken(token)
                .catch((err) => {
                    this.notificationService.toast('Sorry, you have already tried to reset your password using this link').options({position:'top right'}).pop();
                });
        }

    }

    angular.module(namespace, [])
        .service('authService', AuthService);

}


{'fraction_non_alphanumeric': 0.10356335450532889, 'fraction_numerical': 0.00043061685865001615, 'mean_word_length': 1.6369571388021573, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4253114', 'n_tokens_mistral': 2339, 'n_tokens_neox': 2206, 'n_words': 456}