-
-
Notifications
You must be signed in to change notification settings - Fork 515
Improve email visibility and confirmation handling #6666
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| source "https://rubygems.org" | ||
|
|
||
| group :development do | ||
| gem 'letter_opener' | ||
| end | ||
| ruby "3.3.8" | ||
| gem "rails", "~> 7.2" | ||
|
|
||
| gem "paper_trail" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. paper_trail is useful but what is it doing here |
||
| gem "after_party" # post-deployment tasks | ||
| gem "amazing_print" # easier console reading | ||
| gem "authtrail" # Track Devise login activity | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| class UsersController < ApplicationController | ||
| before_action :load_users_not_confirmed , only: :edit | ||
| before_action :get_user | ||
| before_action :authorize_user_with_policy | ||
| before_action :set_active_casa_admins | ||
|
|
@@ -51,6 +52,8 @@ def remove_language | |
| end | ||
| end | ||
|
|
||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove extra line breaks |
||
|
|
||
| def update_password | ||
| unless valid_user_password | ||
| @user.errors.add(:base, "Current password is incorrect") | ||
|
|
@@ -69,23 +72,47 @@ def update_password | |
| redirect_to edit_users_path | ||
| end | ||
|
|
||
|
|
||
|
|
||
| def update_email | ||
|
|
||
| unless valid_user_password | ||
| @user.errors.add(:base, "Current password is incorrect") | ||
| return render "edit", status: :unprocessable_entity | ||
| end | ||
|
|
||
| unless update_user_email | ||
| return render "edit", status: :unprocessable_entity | ||
| end | ||
| end | ||
|
|
||
| bypass_sign_in(@user) if @user == true_user | ||
|
|
||
| redirect_to edit_users_path | ||
| flash.now[:success] = "Your email address has been updated. Click the link sent to your new email to complete the update." | ||
|
|
||
| respond_to do |format| | ||
| format.turbo_stream do | ||
| render turbo_stream: turbo_stream.replace("email-confirmed-message", html: flash.now[:success]) | ||
| end | ||
| format.html | ||
| end | ||
|
|
||
|
|
||
|
|
||
|
|
||
| UserMailer.email_changed_notification(@user).deliver | ||
|
|
||
|
|
||
|
|
||
| end | ||
|
|
||
| private | ||
|
|
||
|
|
||
| def load_users_not_confirmed | ||
| @users = User.all.where.not(unconfirmed_email:[nil, ""]).pluck(:unconfirmed_email) | ||
| end | ||
|
|
||
|
|
||
| def set_language | ||
| @language = Language.find_by(id: params[:id] || params[:language_id]) | ||
| end | ||
|
|
@@ -119,8 +146,11 @@ def email_params | |
| end | ||
|
|
||
| def update_user_email | ||
| @user.update({email: email_params[:email]}) | ||
| @user.filter_old_emails!(@user.email) | ||
| sucess = @user.update({email: email_params[:email]}) | ||
| @user.filter_old_emails!(@user.email) if sucess | ||
|
|
||
| sucess | ||
| puts | ||
| end | ||
|
|
||
| def user_params | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,10 +7,12 @@ class User < ApplicationRecord | |
| include ByOrganizationScope | ||
| include DateHelper | ||
|
|
||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove extra line breaks |
||
| before_save :normalize_phone_number | ||
| after_create :skip_email_confirmation_upon_creation | ||
| after_create :create_preference_set | ||
| before_update :record_previous_email | ||
|
|
||
|
|
||
| validates_with UserValidator | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| <div class="title mb-30 mt-30"> | ||
| <h1>Edit Profile</h1> | ||
| </div> | ||
|
|
||
| </div> | ||
|
|
||
| <div class="card-style"> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,5 +3,5 @@ | |
| <% if @resource.try(:unconfirmed_email?) %> | ||
| <p>We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.</p> | ||
| <% else %> | ||
| <p>We're contacting you to notify you that your email has been changed to <%= @resource.email %>.</p> | ||
| <p>Your CASA account's email has been updated to <%= @resource.email %>.</p> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good improved message |
||
| <% end %> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <meta itemprop="name" content="Password changed reminder" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> | ||
| <style>/* Email styles need to be inline */</style> | ||
| <table width="100%" cellpadding="0" cellspacing="0" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> | ||
| <tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> | ||
| <td class="content-block" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top"> | ||
| Hello <%= @user.try(:display_name) || @user.email %> | ||
| </td> | ||
| </tr> | ||
| <tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> | ||
| <td class="content-block" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top"> | ||
| TESTEEEEEE <%=@user.email%>. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blocker: remove test text |
||
| </td> | ||
| </tr> | ||
| <tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> | ||
| <td class="content-block" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top"> | ||
| If you have any questions, please contact a (Name of relevant CASA) CASA administrator for assistance. | ||
| </td> | ||
| </tr> | ||
| </table> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,14 @@ | |
| config.eager_load = false | ||
|
|
||
| # Show full error reports. | ||
| config.consider_all_requests_local = true | ||
| config.action_mailer.perform_deliveries = true | ||
| config.action_mailer.raise_delivery_errors = true | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix spacing |
||
| config.action_mailer.delivery_method = :letter_opener | ||
|
|
||
| config.action_mailer.default_url_options = { | ||
| host: 'localhost', | ||
| port: 3000 | ||
| } | ||
|
|
||
| # Enable server timing | ||
| config.server_timing = true | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| class RecreateVersionsForPaperTrail < ActiveRecord::Migration[7.2] | ||
| TEXT_BYTES = 1_073_741_823 | ||
|
|
||
| def change | ||
| create_table :versions do |t| | ||
| t.string :item_type, null: false | ||
| t.bigint :item_id, null: false | ||
| t.string :event, null: false | ||
| t.string :whodunnit | ||
| t.text :object, limit: TEXT_BYTES | ||
| t.text :object_changes | ||
| t.datetime :created_at | ||
| end | ||
|
|
||
| add_index :versions, %i[item_type item_id] | ||
| end | ||
| end |
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.
valid and correct to put letter_opener in a devlopment gem section