1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import Ember from 'ember';
- import rpc from 'misago/utils/rpc';
- export default Ember.ObjectController.extend({
- isLoading: false,
- password: '',
- actions: {
- submit: function() {
- if (this.get('isLoading')) {
- return;
- }
- var password = Ember.$.trim(this.get('password'));
- if (password === "") {
- this.get('toast').warning(gettext("Enter new password."));
- return;
- }
- this.set('isLoading', true);
- var self = this;
- rpc(this.get('change_password_url'), {
- password: password
- }).then(function() {
- self.send('success');
- }, function(jqXHR) {
- self.send('error', jqXHR);
- }).finally(function() {
- self.set('isLoading', false);
- });
- },
- success: function() {
- this.set('password', '');
- this.send('openLoginModal');
- this.get('toast').success(gettext("Your password has been changed."));
- },
- error: function(jqXHR) {
- var rejection = jqXHR.responseJSON;
- if (jqXHR.status === 400){
- this.get('toast').error(rejection.detail);
- } else {
- if (jqXHR.status === 404) {
- this.get('toast').error(rejection.detail);
- this.transitionTo('forgotten-password');
- } else {
- this.send('toastError', jqXHR);
- }
- }
- }
- }
- });
|