Class: Passwordless::SessionsController
Instance Method Summary
collapse
#authenticate_by_cookie, #reset_passwordless_redirect_location!, #save_passwordless_redirect_location!, #sign_in, #sign_out
#passwordless_controller?
Instance Method Details
#create ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/controllers/passwordless/sessions_controller.rb', line 15
def create
email_field = authenticatable_class.passwordless_email_field
email = params.require(:passwordless).fetch(email_field).downcase
authenticatable =
authenticatable_class.where("lower(#{email_field}) = ?", email).first
session = Session.new.tap do |us|
us.remote_addr = request.remote_addr
us.user_agent = request.env['HTTP_USER_AGENT']
us.authenticatable = authenticatable
end
if session.save
Mailer.magic_link(session).deliver_now
end
render
end
|
#destroy ⇒ Object
55
56
57
58
|
# File 'app/controllers/passwordless/sessions_controller.rb', line 55
def destroy
sign_out authenticatable_class
redirect_to main_app.root_path
end
|
#new ⇒ Object
9
10
11
12
13
|
# File 'app/controllers/passwordless/sessions_controller.rb', line 9
def new
@email_field = authenticatable_class.passwordless_email_field
@session = Session.new
end
|
#show ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'app/controllers/passwordless/sessions_controller.rb', line 34
def show
BCrypt::Password.create(params[:token])
session = Session.valid.find_by!(
authenticatable_type: authenticatable_classname,
token: params[:token]
)
sign_in session.authenticatable
enabled = Passwordless.redirect_back_after_sign_in
destination = dest = reset_passwordless_redirect_location!(User)
if enabled && destination
redirect_to dest
else
redirect_to main_app.root_path
end
end
|