-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfirmations_controller.rb
32 lines (28 loc) · 1023 Bytes
/
confirmations_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class ConfirmationsController < ApplicationController
before_action :redirect_if_authenticated, only: [:create, :new]
def new
@user = User.new
end
def create
@user = User.find_by(email: params[:user][:email].downcase)
if @user.present? && @user.unconfirmed?
@user.send_confirmation_email!
redirect_to root_path, notice: "Check your email for confirmation instructions."
else
redirect_to new_confirmation_path, alert: "We could not find a user with that email or that email has already been confirmed."
end
end
def edit
@user = User.find_signed(params[:confirmation_token], purpose: :confirm_email)
if @user.present? && @user.unconfirmed_or_reconfirming?
if @user.confirm!
login @user
redirect_to root_path, notice: "Your account has been confirmed."
else
redirect_to new_confirmation_path, alert: "Something went wrong."
end
else
redirect_to new_confirmation_path, alert: "Invalid token."
end
end
end