mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 05:09:38 +02:00
Allow users to update their email address (#1745)
* Change email address * Email confirmation * Email change test * Lint * Schema reset * Set test email sender * Select specific user fixture * Refactor/cleanup * Remove unused email_confirmation_token * Current user would never be true * Fix translation test failures
This commit is contained in:
parent
46e86a9a11
commit
41873de11d
28 changed files with 225 additions and 15 deletions
|
@ -4,10 +4,23 @@ class UsersController < ApplicationController
|
|||
def update
|
||||
@user = Current.user
|
||||
|
||||
@user.update!(user_params.except(:redirect_to, :delete_profile_image))
|
||||
@user.profile_image.purge if should_purge_profile_image?
|
||||
if email_changed?
|
||||
if @user.initiate_email_change(user_params[:email])
|
||||
if Rails.application.config.app_mode.self_hosted? && !Setting.require_email_confirmation
|
||||
handle_redirect(t(".success"))
|
||||
else
|
||||
redirect_to settings_profile_path, notice: t(".email_change_initiated")
|
||||
end
|
||||
else
|
||||
error_message = @user.errors.any? ? @user.errors.full_messages.to_sentence : t(".email_change_failed")
|
||||
redirect_to settings_profile_path, alert: error_message
|
||||
end
|
||||
else
|
||||
@user.update!(user_params.except(:redirect_to, :delete_profile_image))
|
||||
@user.profile_image.purge if should_purge_profile_image?
|
||||
|
||||
handle_redirect(t(".success"))
|
||||
handle_redirect(t(".success"))
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
@ -38,9 +51,13 @@ class UsersController < ApplicationController
|
|||
user_params[:profile_image].blank?
|
||||
end
|
||||
|
||||
def email_changed?
|
||||
user_params[:email].present? && user_params[:email] != @user.email
|
||||
end
|
||||
|
||||
def user_params
|
||||
params.require(:user).permit(
|
||||
:first_name, :last_name, :profile_image, :redirect_to, :delete_profile_image, :onboarded_at,
|
||||
:first_name, :last_name, :email, :profile_image, :redirect_to, :delete_profile_image, :onboarded_at,
|
||||
family_attributes: [ :name, :currency, :country, :locale, :date_format, :timezone, :id, :data_enrichment_enabled ]
|
||||
)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue