mirror of
https://github.com/discourse/discourse.git
synced 2025-03-24 07:35:46 +08:00
automatically redirect when password reset completes successfully
This commit is contained in:
parent
be9230cba2
commit
8643620172
app/assets/javascripts/discourse
test/javascripts/acceptance
@ -1,5 +1,6 @@
|
||||
import { default as computed } from 'ember-addons/ember-computed-decorators';
|
||||
import getUrl from 'discourse-common/lib/get-url';
|
||||
import DiscourseURL from 'discourse/lib/url';
|
||||
import { ajax } from 'discourse/lib/ajax';
|
||||
import PasswordValidation from "discourse/mixins/password-validation";
|
||||
|
||||
@ -9,12 +10,18 @@ export default Ember.Controller.extend(PasswordValidation, {
|
||||
errorMessage: null,
|
||||
successMessage: null,
|
||||
requiresApproval: false,
|
||||
redirected: false,
|
||||
|
||||
@computed()
|
||||
continueButtonText() {
|
||||
return I18n.t('password_reset.continue', {site_name: this.siteSettings.title});
|
||||
},
|
||||
|
||||
@computed('redirectTo')
|
||||
redirectHref(redirectTo) {
|
||||
return Discourse.getURL(redirectTo || '/');
|
||||
},
|
||||
|
||||
lockImageUrl: getUrl('/images/lock.svg'),
|
||||
|
||||
actions: {
|
||||
@ -31,6 +38,9 @@ export default Ember.Controller.extend(PasswordValidation, {
|
||||
this.set('redirectTo', result.redirect_to);
|
||||
if (result.requires_approval) {
|
||||
this.set('requiresApproval', true);
|
||||
} else {
|
||||
this.set('redirected', true);
|
||||
DiscourseURL.redirectTo(result.redirect_to || '/');
|
||||
}
|
||||
} else {
|
||||
if (result.errors && result.errors.password && result.errors.password.length > 0) {
|
||||
@ -47,7 +57,8 @@ export default Ember.Controller.extend(PasswordValidation, {
|
||||
},
|
||||
|
||||
done() {
|
||||
window.location.pathname = this.get('redirectTo') || Discourse.getURL("/");
|
||||
this.set('redirected', true);
|
||||
DiscourseURL.redirectTo(this.get('redirectTo') || '/');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -10,7 +10,9 @@
|
||||
{{#if requiresApproval}}
|
||||
<p>{{i18n 'login.not_approved'}}</p>
|
||||
{{else}}
|
||||
<a class="btn" href="{{redirectTo}}" {{action "done"}}>{{continueButtonText}}</a>
|
||||
{{#unless redirected}}
|
||||
<a class="btn" href="{{redirectHref}}" {{action "done"}}>{{continueButtonText}}</a>
|
||||
{{/unless}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
<form>
|
||||
|
@ -57,7 +57,6 @@ test("Password Reset Page", () => {
|
||||
click('.password-reset form button');
|
||||
andThen(() => {
|
||||
ok(!exists(".password-reset form"), "form is gone");
|
||||
ok(exists(".password-reset .btn"), "button is shown");
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user