mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-25 09:03:12 +03:00
refactor reset password screen to use ember-concurrency (#502)
refs https://github.com/TryGhost/Ghost/issues/7865 - swap promise based action for an ember-concurrency task
This commit is contained in:
parent
170f8d29fe
commit
74b020e0e3
@ -1,14 +1,13 @@
|
||||
import Controller from 'ember-controller';
|
||||
import computed from 'ember-computed';
|
||||
import injectService from 'ember-service/inject';
|
||||
|
||||
import ValidationEngine from 'ghost-admin/mixins/validation-engine';
|
||||
import {task} from 'ember-concurrency';
|
||||
|
||||
export default Controller.extend(ValidationEngine, {
|
||||
newPassword: '',
|
||||
ne2Password: '',
|
||||
token: '',
|
||||
submitting: false,
|
||||
flowErrors: '',
|
||||
|
||||
validationType: 'reset',
|
||||
@ -33,40 +32,44 @@ export default Controller.extend(ValidationEngine, {
|
||||
});
|
||||
},
|
||||
|
||||
actions: {
|
||||
submit() {
|
||||
let credentials = this.getProperties('newPassword', 'ne2Password', 'token');
|
||||
resetPassword: task(function* () {
|
||||
let credentials = this.getProperties('newPassword', 'ne2Password', 'token');
|
||||
let authUrl = this.get('ghostPaths.url').api('authentication', 'passwordreset');
|
||||
|
||||
this.set('flowErrors', '');
|
||||
this.get('hasValidated').addObjects(['newPassword', 'ne2Password']);
|
||||
this.validate().then(() => {
|
||||
let authUrl = this.get('ghostPaths.url').api('authentication', 'passwordreset');
|
||||
this.toggleProperty('submitting');
|
||||
this.get('ajax').put(authUrl, {
|
||||
this.set('flowErrors', '');
|
||||
this.get('hasValidated').addObjects(['newPassword', 'ne2Password']);
|
||||
|
||||
try {
|
||||
yield this.validate();
|
||||
try {
|
||||
let resp = yield this.get('ajax').put(authUrl, {
|
||||
data: {
|
||||
passwordreset: [credentials]
|
||||
}
|
||||
}).then((resp) => {
|
||||
this.toggleProperty('submitting');
|
||||
this.get('notifications').showAlert(resp.passwordreset[0].message, {type: 'warn', delayed: true, key: 'password.reset'});
|
||||
this.get('session').authenticate('authenticator:oauth2', this.get('email'), credentials.newPassword);
|
||||
}).catch((error) => {
|
||||
this.get('notifications').showAPIError(error, {key: 'password.reset'});
|
||||
this.toggleProperty('submitting');
|
||||
});
|
||||
}).catch((error) => {
|
||||
if (this.get('errors.newPassword')) {
|
||||
this.set('flowErrors', this.get('errors.newPassword')[0].message);
|
||||
}
|
||||
this.get('notifications').showAlert(resp.passwordreset[0].message, {type: 'warn', delayed: true, key: 'password.reset'});
|
||||
this.get('session').authenticate('authenticator:oauth2', this.get('email'), credentials.newPassword);
|
||||
} catch (error) {
|
||||
this.get('notifications').showAPIError(error, {key: 'password.reset'});
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.get('errors.newPassword')) {
|
||||
this.set('flowErrors', this.get('errors.newPassword')[0].message);
|
||||
}
|
||||
|
||||
if (this.get('errors.ne2Password')) {
|
||||
this.set('flowErrors', this.get('errors.ne2Password')[0].message);
|
||||
}
|
||||
if (this.get('errors.ne2Password')) {
|
||||
this.set('flowErrors', this.get('errors.ne2Password')[0].message);
|
||||
}
|
||||
|
||||
if (this.get('errors.length') === 0) {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
if (error && this.get('errors.length') === 0) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}).drop(),
|
||||
|
||||
actions: {
|
||||
submit() {
|
||||
this.get('resetPassword').perform();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -9,7 +9,7 @@
|
||||
{{gh-input ne2Password type="password" name="ne2password" placeholder="Confirm Password" class="password" autocorrect="off" autofocus="autofocus" update=(action (mut ne2Password))}}
|
||||
{{/gh-form-group}}
|
||||
|
||||
{{#gh-spin-button class="btn btn-blue btn-block" type="submit" submitting=submitting autoWidth="false"}}Reset Password{{/gh-spin-button}}
|
||||
{{#gh-task-button task=resetPassword class="btn btn-blue btn-block" type="submit" autoWidth="false"}}Reset Password{{/gh-task-button}}
|
||||
</form>
|
||||
|
||||
<p class="main-error">{{{flowErrors}}}</p>
|
||||
|
Loading…
Reference in New Issue
Block a user