9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/magic/link/controller_extensions.rb', line 9
def authenticate_user_from_token!
email = params[:email].presence
token = params[:sign_in_token].presence
user = email && token && Magic::Link.user_class.find_by(email: email)
if token && send("#{Magic::Link.user_class.name.underscore}_signed_in?")
flash.now[:alert] = "You are already signed in"
elsif user && token_matches?(user) && token_not_expired?(user)
flash[:notice] = "You have signed in successfully"
user.update_columns(sign_in_token: nil, sign_in_token_sent_at: nil)
sign_in user
elsif email && token
flash[:alert] = "Your sign in token is invalid"
redirect_to main_app.root_path
end
end
|