logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

change_emails_controller.rb (1118B)


  1. # frozen_string_literal: true
  2. module Admin
  3. class ChangeEmailsController < BaseController
  4. before_action :set_account
  5. before_action :require_local_account!
  6. def show
  7. authorize @user, :change_email?
  8. end
  9. def update
  10. authorize @user, :change_email?
  11. new_email = resource_params.fetch(:unconfirmed_email)
  12. if new_email != @user.email
  13. @user.update!(
  14. unconfirmed_email: new_email,
  15. # Regenerate the confirmation token:
  16. confirmation_token: nil
  17. )
  18. log_action :change_email, @user
  19. @user.send_confirmation_instructions
  20. end
  21. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.change_email.changed_msg')
  22. end
  23. private
  24. def set_account
  25. @account = Account.find(params[:account_id])
  26. @user = @account.user
  27. end
  28. def require_local_account!
  29. redirect_to admin_account_path(@account.id) unless @account.local? && @account.user.present?
  30. end
  31. def resource_params
  32. params.require(:user).permit(
  33. :unconfirmed_email
  34. )
  35. end
  36. end
  37. end