Class: RailsSimpleAuth::ConfirmationsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/rails_simple_auth/confirmations_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/rails_simple_auth/confirmations_controller.rb', line 34

def create
  user = user_class.find_by(email: params[:email])

  if user.respond_to?(:unconfirmed_or_reconfirming?) && user.unconfirmed_or_reconfirming?
    token = user.generate_confirmation_token
    RailsSimpleAuth.configuration.mailer.confirmation(user, token).deliver_later
  end

  redirect_to new_session_path,
              notice: 'If an unconfirmed account exists with that email, confirmation instructions have been sent.'
end

#newObject



32
# File 'app/controllers/rails_simple_auth/confirmations_controller.rb', line 32

def new; end

#showObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/rails_simple_auth/confirmations_controller.rb', line 14

def show
  user = user_class.find_signed(params[:token], purpose: :confirm_email)

  if user
    confirmed = user.respond_to?(:confirm!) ? user.confirm! : true

    if confirmed
      run_after_confirmation_callback(user)
      redirect_to resolve_path(:after_confirmation_path), notice: 'Email confirmed! You can now sign in.'
    else
      error_message = user.errors.full_messages.first || 'Could not confirm email.'
      redirect_to new_confirmation_path, alert: error_message
    end
  else
    redirect_to new_confirmation_path, alert: 'Invalid or expired confirmation link.'
  end
end