-
-
Notifications
You must be signed in to change notification settings - Fork 927
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor recovery codes to switch everything to stimulus clipboard
- Loading branch information
1 parent
bd5a7f3
commit 4ae91b5
Showing
28 changed files
with
142 additions
and
381 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
export default class extends Controller { | ||
static values = { | ||
confirm: { type: String, default: "Leave without copying recovery codes?" } | ||
} | ||
|
||
connect() { | ||
this.copied = false; | ||
window.addEventListener("beforeunload", this.popUp); | ||
} | ||
|
||
popUp(e) { | ||
e.preventDefault(); | ||
e.returnValue = ""; | ||
} | ||
|
||
copy() { | ||
if (!this.copied) { | ||
this.copied = true; | ||
window.removeEventListener("beforeunload", this.popUp); | ||
} | ||
} | ||
|
||
submit(e) { | ||
e.preventDefault(); | ||
|
||
if (!this.element.checkValidity()) { | ||
this.element.reportValidity(); | ||
return; | ||
} | ||
|
||
if (this.copied || confirm(this.confirmValue)) { | ||
window.removeEventListener("beforeunload", this.popUp); | ||
// Don't include the form data in the URL. | ||
window.location.href = this.element.action; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,18 +1,25 @@ | ||
<% @title = t(".title") %> | ||
<div class="t-body"> | ||
<%= tag.div( | ||
class: "t-body", | ||
data: { | ||
controller: "clipboard", | ||
clipboard_success_content_value: t('copied') | ||
} | ||
) do %> | ||
<p><%= t ".note_html" %></p> | ||
|
||
<ul id="recovery-code-list"> | ||
<% @mfa_recovery_codes.each do |code| %> | ||
<li class="recovery-code-list__item"><%= code %></li> | ||
<% end %> | ||
</ul> | ||
<%# This tag contains the recovery codes and should not be a part of the form %> | ||
<%= text_area_tag "source", "#{@mfa_recovery_codes.join("\n")}\n", class: "recovery-code-list", rows: @mfa_recovery_codes.size + 1, cols: @mfa_recovery_codes.first.length + 1, readonly: true, data: { clipboard_target: "source" } %> | ||
<p><%= link_to t(".copy"), "#/", class: "t-link--bold recovery__copy__icon", data: { "clipboard-target": "#recovery-code-list" } %></p> | ||
<div class = "form__checkbox__item"> | ||
<%= check_box_tag "checked", "ack", false, class: "form__checkbox__input" %> | ||
<%= label_tag "checked", t(".saved"), class: "form__checkbox__label" %> | ||
</div> | ||
<%= button_to t(".continue"), @continue_path, method: "get", class: "form__submit form__submit--no-hover", disabled: true %> | ||
</div> | ||
<%= form_tag(@continue_path, method: "get", class: "form", data: { controller: "recovery", recovery_confirm_value: t(".confirm_dialog"), action: "recovery#submit" }) do %> | ||
<p><%= link_to t("copy_to_clipboard"), "#/", class: "t-link--bold recovery__copy__icon", data: { action: "clipboard#copy recovery#copy", clipboard_target: "button" } %></p> | ||
|
||
<div class = "form__checkbox__item"> | ||
<%= check_box_tag "checked", "ack", false, required: true, class: "form__checkbox__input" %> | ||
<%= label_tag "checked", t(".saved"), class: "form__checkbox__label" %> | ||
</div> | ||
|
||
<%= button_tag t(".continue"), class: "form__submit form__submit--no-hover" %> | ||
<% end %> | ||
<% end %> |
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
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
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
Oops, something went wrong.