forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV: Update confirm-email flows to use central 2fa and ember rendering (
discourse#25404) These routes were previously rendered using Rails, and had a fairly fragile 2fa implementation in vanilla-js. This commit refactors the routes to be handled in the Ember app, removes the custom vanilla-js bundles, and leans on our centralized 2fa implementation. It also introduces a set of system specs for the behavior.
- Loading branch information
1 parent
27301ae
commit 283fe48
Showing
20 changed files
with
445 additions
and
521 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
app/assets/javascripts/confirm-new-email/confirm-new-email.js
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
app/assets/javascripts/discourse/app/controllers/confirm-new-email.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { tracked } from "@glimmer/tracking"; | ||
import Controller from "@ember/controller"; | ||
import { action } from "@ember/object"; | ||
import { inject as service } from "@ember/service"; | ||
import { ajax } from "discourse/lib/ajax"; | ||
import { popupAjaxError } from "discourse/lib/ajax-error"; | ||
import I18n from "discourse-i18n"; | ||
|
||
export default class ConfirmNewEmailController extends Controller { | ||
@service dialog; | ||
@service router; | ||
|
||
@tracked loading; | ||
|
||
@action | ||
async confirm() { | ||
this.loading = true; | ||
try { | ||
await ajax(`/u/confirm-new-email/${this.model.token}.json`, { | ||
type: "PUT", | ||
}); | ||
} catch (error) { | ||
const nonce = error.jqXHR?.responseJSON?.second_factor_challenge_nonce; | ||
if (nonce) { | ||
this.router.transitionTo("second-factor-auth", { | ||
queryParams: { nonce }, | ||
}); | ||
} else { | ||
popupAjaxError(error); | ||
} | ||
return; | ||
} finally { | ||
this.loading = false; | ||
} | ||
|
||
await new Promise((resolve) => | ||
this.dialog.dialog({ | ||
message: I18n.t("user.change_email.confirm_success"), | ||
type: "alert", | ||
didConfirm: resolve, | ||
}) | ||
); | ||
|
||
this.router.transitionTo("/my/preferences/account"); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/assets/javascripts/discourse/app/controllers/confirm-old-email.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { tracked } from "@glimmer/tracking"; | ||
import Controller from "@ember/controller"; | ||
import { action } from "@ember/object"; | ||
import { inject as service } from "@ember/service"; | ||
import { ajax } from "discourse/lib/ajax"; | ||
import { popupAjaxError } from "discourse/lib/ajax-error"; | ||
import I18n from "discourse-i18n"; | ||
|
||
export default class ConfirmOldEmailController extends Controller { | ||
@service dialog; | ||
@service router; | ||
|
||
@tracked loading; | ||
|
||
@action | ||
async confirm() { | ||
this.loading = true; | ||
try { | ||
await ajax(`/u/confirm-old-email/${this.model.token}.json`, { | ||
type: "PUT", | ||
}); | ||
} catch (error) { | ||
popupAjaxError(error); | ||
return; | ||
} finally { | ||
this.loading = false; | ||
} | ||
|
||
await new Promise((resolve) => | ||
this.dialog.dialog({ | ||
message: I18n.t("user.change_email.authorizing_old.confirm_success"), | ||
type: "alert", | ||
didConfirm: resolve, | ||
}) | ||
); | ||
|
||
this.router.transitionTo("/my/preferences/account"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
app/assets/javascripts/discourse/app/routes/confirm-new-email.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ajax } from "discourse/lib/ajax"; | ||
import DiscourseRoute from "discourse/routes/discourse"; | ||
import I18n from "discourse-i18n"; | ||
|
||
export default class ConfirmNewEmailRoute extends DiscourseRoute { | ||
titleToken() { | ||
return I18n.t("user.change_email.title"); | ||
} | ||
|
||
model(params) { | ||
return ajax(`/u/confirm-new-email/${params.token}.json`); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/assets/javascripts/discourse/app/routes/confirm-old-email.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ajax } from "discourse/lib/ajax"; | ||
import DiscourseRoute from "discourse/routes/discourse"; | ||
import I18n from "discourse-i18n"; | ||
|
||
export default class ConfirmOldEmailRoute extends DiscourseRoute { | ||
titleToken() { | ||
return I18n.t("user.change_email.title"); | ||
} | ||
|
||
model(params) { | ||
return ajax(`/u/confirm-old-email/${params.token}.json`); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
app/assets/javascripts/discourse/app/templates/confirm-new-email.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<div id="simple-container"> | ||
<div class="confirm-new-email"> | ||
<h2>{{i18n "user.change_email.title"}}</h2> | ||
<p> | ||
{{#if this.model.old_email}} | ||
{{i18n "user.change_email.authorizing_new.description"}} | ||
{{else}} | ||
{{i18n "user.change_email.authorizing_new.description_add"}} | ||
{{/if}} | ||
</p> | ||
<p>{{this.model.new_email}}</p> | ||
<DButton | ||
@translatedLabel={{i18n "user.change_email.confirm"}} | ||
class="btn-primary" | ||
@action={{this.confirm}} | ||
/> | ||
</div> | ||
</div> |
31 changes: 31 additions & 0 deletions
31
app/assets/javascripts/discourse/app/templates/confirm-old-email.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<div id="simple-container"> | ||
<div class="confirm-old-email"> | ||
<h2>{{i18n "user.change_email.authorizing_old.title"}}</h2> | ||
<p> | ||
{{#if this.model.old_email}} | ||
{{i18n "user.change_email.authorizing_old.description"}} | ||
{{else}} | ||
{{i18n "user.change_email.authorizing_old.description_add"}} | ||
{{/if}} | ||
</p> | ||
{{#if this.model.old_email}} | ||
<p> | ||
{{i18n | ||
"user.change_email.authorizing_old.old_email" | ||
email=this.model.old_email | ||
}} | ||
</p> | ||
{{/if}} | ||
<p> | ||
{{i18n | ||
"user.change_email.authorizing_old.new_email" | ||
email=this.model.new_email | ||
}} | ||
</p> | ||
<DButton | ||
@translatedLabel={{i18n "user.change_email.confirm"}} | ||
class="btn-primary" | ||
@action={{this.confirm}} | ||
/> | ||
</div> | ||
</div> |
Oops, something went wrong.