Allow users to update their email address #1745
Reference in New Issue
Block a user
Delete Branch "email-update"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Users can now update their email address. Upon updating, they'll be emailed a confirmation link.
Self-hosters can disable the need to confirm an email change.
@zachgoll A couple of the failing tests are transaction related...could that have anything to do with the transaction work over the past 24-48 hours?
@Shpigford possibly, although the last few commits passed just fine. It looks like your
schema.rbhas several stale migrations flowing into it. Can you remove those and re-run the tests? My guess is that will get things fixed.@zachgoll Cleaned up the schema and still hitting those two errors (both here in github and locally). Not sure what else to try there.
@Shpigford the transaction error is because with the addition of the
:new_emailin the fixtures, it's causing the evaluation of this user to be that user, who has no transactions:ded42a8c33/test/controllers/transactions_controller_test.rb (L35)We can just flip that to:
sign_in users(:empty)and that error will be resolved.@@ -4,10 +4,23 @@ class UsersController < ApplicationControllerdef updateThere won't be any errors populated on the user model here for most cases (blank alert), so here and below we should probably just pass a string alert like "Something went wrong"
@@ -25,6 +26,30 @@ class User < ApplicationRecordpassword_salt&.last(10)I think we can remove this method and handle directly in the controller. Then the controller would just be:
Think we can delete this
@@ -10,2 +10,4 @@<div><%= form.email_field :email, placeholder: t(".email"), label: t(".email") %><% if @user.unconfirmed_email.present? %>From a UX standpoint, I think we need some sort of message underneath this when
unconfirmed_emailis present:@@ -9,6 +9,7 @@ Rails.application.routes.draw doresources :sessions, only: %i[new create destroy]Totally semantic and optional, but for consistency with the other routes I think this is a great use case for something like:
Would still use
email_confirmations_controllerand the new route would benew_email_confirmation_url@@ -0,0 +2,4 @@def changeadd_column :users, :unconfirmed_email, :stringadd_column :users, :email_confirmation_token, :stringadd_column :users, :email_confirmation_sent_at, :datetimeWe should be able to delete
:email_confirmation_sent_atand just let thegenerates_token_forexpiry handle the expiration validation (see my comment above about removing theconfirm_email_changemethod)@@ -0,0 +1,18 @@class EmailConfirmationsController < ApplicationControllersynxsystem96@gmail.com
Looks good!
@@ -0,0 +1,18 @@class EmailConfirmationsController < ApplicationControllerSince we're skipping auth, this should never be true so we can remove it
@@ -0,0 +1,9 @@class AddEmailConfirmationToUsers < ActiveRecord::Migration[7.2]def changeadd_column :users, :unconfirmed_email, :stringadd_column :users, :email_confirmation_token, :stringI totally missed this yesterday, but what is
:email_confirmation_tokenfor here? It doesn't seem to be used anywhere unless I'm missing something@@ -0,0 +1,9 @@class AddEmailConfirmationToUsers < ActiveRecord::Migration[7.2]def changeadd_column :users, :unconfirmed_email, :stringadd_column :users, :email_confirmation_token, :stringAh, this is leftover from before switching to the rails
generate_token_forstuff. Will remove.