superdesk/superdesk-client-core

View on GitHub
scripts/apps/users/directives/ResetPasswordDirective.ts

Summary

Maintainability
A
0 mins
Test Coverage
import {gettext} from 'core/utils';

ResetPasswordDirective.$inject = ['usersService', 'notify'];
export function ResetPasswordDirective(usersService, notify) {
    return {
        link: function(scope, element) {
            scope.$watch('user', () => {
                scope.oldPasswordInvalid = false;
            });

            /**
             * reset user password
             */
            scope.resetPassword = function() {
                return usersService.resetPassword(scope.user)
                    .then((response) => {
                        scope.oldPasswordInvalid = false;
                        notify.success(gettext('The password has been reset.'), 3000);
                        scope.show.reset_password = false;
                    }, (response) => {
                        scope.oldPasswordInvalid = true;
                    });
            };
        },
    };
}