-
Notifications
You must be signed in to change notification settings - Fork 655
[Feature - Reset Password Flow] #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
milos-dukic
wants to merge
1
commit into
basecamp:main
Choose a base branch
from
milos-dukic:feature-reset-passwrod-flow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,55 @@ | ||
| class Sessions::PasswordResetsController < ApplicationController | ||
| allow_unauthenticated_access | ||
|
|
||
| before_action :require_smpt | ||
|
|
||
| def index | ||
| end | ||
| def new | ||
| end | ||
|
|
||
| def show | ||
| @password_reset_id = params[:id] | ||
| @user = User.find_by_password_reset_id(@password_reset_id) | ||
|
|
||
| redirect_to root_url unless @user | ||
| end | ||
|
|
||
| def update | ||
| @user = User.find_by_password_reset_id(password_reset_params[:password_reset_id]) | ||
|
|
||
| redirect_to root_url unless @user | ||
| redirect_to root_url unless password_match? | ||
|
|
||
| @user.update(password: password_reset_params[:new_password]) | ||
|
|
||
| redirect_to new_session_path | ||
| end | ||
|
|
||
| def create | ||
| email = params[:email_address] | ||
| password_reset_url = session_password_reset_url(find_user_by_email(email).password_reset_id) | ||
|
|
||
| PasswordResetMailer.with(email: email, url: password_reset_url).password_reset_email.deliver_later | ||
|
|
||
| redirect_to new_session_password_reset_path | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def require_smpt | ||
| redirect_to root_url unless helpers.smtp_enabled? | ||
| end | ||
|
|
||
| def find_user_by_email(email) | ||
| User.find_by(email_address: email) | ||
| end | ||
|
|
||
| def password_match? | ||
| password_reset_params[:new_password] == password_reset_params[:confirm_new_password] | ||
| end | ||
|
|
||
| def password_reset_params | ||
| params.require(:user).permit(:new_password, :confirm_new_password, :password_reset_id) | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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,38 @@ | ||
| import { Controller } from "@hotwired/stimulus" | ||
|
|
||
| export default class extends Controller { | ||
| static targets = [ "resetPasswordInput", "resetPasswordConfirmInput", "resetPasswordError", "resetPasswordSubmit"] | ||
|
|
||
| resetPasswordCheckInputs() { | ||
| if(this.#checkResetInputsValues()) { | ||
| this.#hideErrorMessage() | ||
| this.#enableSubmitButton() | ||
| } else { | ||
| this.#showErrorMessage() | ||
| this.#disableSubmitButton() | ||
| } | ||
| } | ||
|
|
||
| #showErrorMessage() { | ||
| this.resetPasswordErrorTarget.style.visibility = "visible" | ||
| } | ||
|
|
||
| #hideErrorMessage() { | ||
| this.resetPasswordErrorTarget.style.visibility = "hidden" | ||
| } | ||
|
|
||
| #enableSubmitButton() { | ||
| this.resetPasswordSubmitTarget.disabled = false | ||
| } | ||
|
|
||
| #disableSubmitButton() { | ||
| this.resetPasswordSubmitTarget.disabled = true | ||
| } | ||
|
|
||
| #checkResetInputsValues() { | ||
| if (this.resetPasswordInputTarget.value.length < 0 || this.resetPasswordConfirmInputTarget.value.length < 0) return false | ||
| if (this.resetPasswordInputTarget.value !== this.resetPasswordConfirmInputTarget.value) return false | ||
|
|
||
| return true | ||
| } | ||
| } |
This file contains hidden or 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,6 @@ | ||
| class ApplicationMailer < ActionMailer::Base | ||
| DEFAULT_BASE_FROM="[email protected]" | ||
|
|
||
| default from: ENV.fetch("SMTP_INFO_EMAIL_FROM", DEFAULT_BASE_FROM) | ||
| layout "mailer" | ||
| end |
This file contains hidden or 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,9 @@ | ||
| class PasswordResetMailer < ApplicationMailer | ||
| default from: ENV.fetch("SMTP_PASSWORD_RESET_EMAIL_FROM", DEFAULT_BASE_FROM) | ||
|
|
||
| def password_reset_email | ||
| @email = params[:email] | ||
| @url = params[:url] | ||
| mail(to: @email, subject: "Campfire Reset Password") | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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,15 @@ | ||
| module User::Resettable | ||
| extend ActiveSupport::Concern | ||
|
|
||
| RESET_PASSWORD_LINK_EXPIRY_DURATION = 5.hours | ||
|
|
||
| class_methods do | ||
| def find_by_password_reset_id(id) | ||
| find_signed(id, purpose: :password_reset) | ||
| end | ||
| end | ||
|
|
||
| def password_reset_id | ||
| signed_id(purpose: :password_reset, expires_in: RESET_PASSWORD_LINK_EXPIRY_DURATION) | ||
| end | ||
| end | ||
9 changes: 9 additions & 0 deletions
9
app/views/password_reset_mailer/password_reset_email.html.erb
This file contains hidden or 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,9 @@ | ||
| <h1>Reset Your Campfire Password</h1> | ||
| <p>Hello,</p> | ||
| <br> | ||
| <p>You have requested a password reset for your Campfire account.</p> | ||
| <p> | ||
| To reset your Campfire password, please click on this: <%= link_to 'link', @url %>. | ||
| </p> | ||
| <br> | ||
| <p>Campfire</p> |
9 changes: 9 additions & 0 deletions
9
app/views/password_reset_mailer/password_reset_email.text.erb
This file contains hidden or 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,9 @@ | ||
| Reset Your Campfire Password | ||
| =============================================== | ||
| Hello, | ||
|
|
||
| You have requested a password reset for your Campfire account. | ||
|
|
||
| To reset your Campfire password, please click on this: <%= link_to 'link', @url %>. | ||
|
|
||
| Campfire |
This file contains hidden or 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 hidden or 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,30 @@ | ||
| <% @page_title = "Reset password" %> | ||
| <% turbo_page_requires_reload %> | ||
|
|
||
| <section class="txt-align-center"> | ||
| <div class="panel <%= "shake" if flash[:alert] %>"> | ||
| <%= account_logo_tag style: "center margin-block-end txt-xx-large" %> | ||
|
|
||
| <%= form_with url: session_password_resets_url, class: "flex flex-column gap" do |form| %> | ||
| <fieldset class="flex flex-column gap center-block upad"> | ||
| <legend class="txt-large txt-align-center"><strong><%= Current.account.name %></strong></legend> | ||
|
|
||
| <div>Enter your email to receive reset password link</div> | ||
|
|
||
| <div class="flex align-center gap"> | ||
| <%= translation_button(:email_address) %> | ||
| <label class="flex align-center gap input input--actor txt-large"> | ||
| <%= form.email_field :email_address, required: true, class: "input", autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address] %> | ||
| <%= image_tag "email.svg", aria: { hidden: "true" }, size: 24, class: "colorize--black" %> | ||
| </label> | ||
| </div> | ||
| <%= form.button class: "btn btn--reversed center txt-large", type: "submit", name: "reset_password_email" do %> | ||
| <%= image_tag "arrow-right.svg", aria: { hidden: "true" } %> | ||
| <span class="for-screen-reader">Email reset password link</span> | ||
| <% end %> | ||
| </fieldset> | ||
| <% end %> | ||
| </div> | ||
|
|
||
| <%= render "accounts/help_contact" %> | ||
| </section> |
This file contains hidden or 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,28 @@ | ||
| <% @page_title = "Reset password" %> | ||
| <% turbo_page_requires_reload %> | ||
|
|
||
| <section class="txt-align-center"> | ||
| <div class="panel <%= "shake" if flash[:alert] %>"> | ||
| <%= account_logo_tag style: "center margin-block-end txt-xx-large" %> | ||
|
|
||
| <%= form_with url: session_password_resets_url, class: "flex flex-column gap" do |form| %> | ||
| <fieldset class="flex flex-column gap center-block upad"> | ||
| <legend class="txt-large txt-align-center"><strong><%= Current.account.name %></strong></legend> | ||
| <p>Reset link has been sent to your email.</p> | ||
|
|
||
| <br> | ||
|
|
||
| <div> Didn't receive an email?</div> | ||
|
|
||
| <div> | ||
| <%= link_to session_password_resets_path, class: "btn flex-item-justify-end" do %> | ||
| <div> Return to the reset password page </div> | ||
| <span class="for-screen-reader">Return to the reset password page</span> | ||
| <% end %> | ||
| </div> | ||
| </fieldset> | ||
| <% end %> | ||
| </div> | ||
|
|
||
| <%= render "accounts/help_contact" %> | ||
| </section> |
This file contains hidden or 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,65 @@ | ||
| <% @page_title = "Reset password" %> | ||
| <% turbo_page_requires_reload %> | ||
|
|
||
| <section class="txt-align-center"> | ||
| <div class="panel <%= "shake" if flash[:alert] %>"> | ||
| <%= account_logo_tag style: "center margin-block-end txt-xx-large" %> | ||
|
|
||
| <%= form_with model: @user, url: session_password_reset_url, class: "flex flex-column gap", data: { controller: "password-reset" }, method: :patch do |form| %> | ||
| <fieldset class="flex flex-column gap center-block upad"> | ||
| <legend class="txt-large txt-align-center"><strong><%= Current.account.name %></strong></legend> | ||
| <p>Please enter the new password</p> | ||
|
|
||
| <div class="flex align-center gap"> | ||
| <%= translation_button(:password) %> | ||
| <label class="flex align-center gap flex-item-grow txt-large input input--actor"> | ||
| <%= form.password_field :new_password, | ||
| class: "input", | ||
| autocomplete: "new-password", | ||
| placeholder: "New password", | ||
| required: true, | ||
| maxlength: 72, | ||
| data: { | ||
| password_reset_target: "resetPasswordInput", | ||
| action: "input->password-reset#resetPasswordCheckInputs" | ||
| } %> | ||
| <%= image_tag "password.svg", aria: { hidden: "true" }, size: 24, class: "colorize--black" %> | ||
| </label> | ||
| </div> | ||
|
|
||
| <div class="flex align-center gap"> | ||
| <%= translation_button(:password) %> | ||
| <label class="flex align-center gap flex-item-grow txt-large input input--actor"> | ||
| <%= form.password_field :confirm_new_password, | ||
| class: "input", | ||
| autocomplete: "new-password", | ||
| placeholder: "Confirm new password", | ||
| required: true, | ||
| maxlength: 72, | ||
| data: { | ||
| password_reset_target: "resetPasswordConfirmInput", | ||
| action: "input->password-reset#resetPasswordCheckInputs" | ||
| } %> | ||
| <%= image_tag "password.svg", aria: { hidden: "true" }, size: 24, class: "colorize--black" %> | ||
| </label> | ||
| </div> | ||
| <%= form.text_field :password_reset_id, value: @password_reset_id, hidden: true,required: true %> | ||
|
|
||
| <p id="reset_password_not_matched" class="reset-password-alert" data-password-reset-target="resetPasswordError">Passwords do not match!</p> | ||
|
|
||
| <div> | ||
| <%= form.button class: "btn btn--reversed center txt-large", | ||
| type: "submit", | ||
| name: "reset_password", | ||
| disabled: true, | ||
| data: { password_reset_target: "resetPasswordSubmit" } do %> | ||
| <%= image_tag "arrow-right.svg", aria: { hidden: "true" } %> | ||
| <span class="for-screen-reader">Confirm new password</span> | ||
| <% end %> | ||
| </div> | ||
| </fieldset> | ||
| <% end %> | ||
| </div> | ||
|
|
||
| <%= render "accounts/help_contact" %> | ||
| </section> |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you forgot to delete the comment in line 4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep thx