Module: Passwordless::ControllerHelpers

Included in:
SessionsController
Defined in:
lib/passwordless/controller_helpers.rb

Instance Method Summary collapse

Instance Method Details



3
4
5
6
7
8
9
# File 'lib/passwordless/controller_helpers.rb', line 3

def authenticate_by_cookie(authenticatable_class)
  key = cookie_name(authenticatable_class)
  authenticatable_id = cookies.encrypted[key]
  return unless authenticatable_id

  authenticatable_class.find_by(id: authenticatable_id)
end

#reset_passwordless_redirect_location!(authenticatable_class) ⇒ Object



27
28
29
# File 'lib/passwordless/controller_helpers.rb', line 27

def reset_passwordless_redirect_location!(authenticatable_class)
  session.delete session_key(authenticatable_class)
end

#save_passwordless_redirect_location!(authenticatable_class) ⇒ Object



23
24
25
# File 'lib/passwordless/controller_helpers.rb', line 23

def save_passwordless_redirect_location!(authenticatable_class)
  session[session_key(authenticatable_class)] = request.original_url
end

#sign_in(authenticatable) ⇒ Object



11
12
13
14
15
# File 'lib/passwordless/controller_helpers.rb', line 11

def (authenticatable)
  key = cookie_name(authenticatable.class)
  cookies.encrypted.permanent[key] = { value: authenticatable.id }
  authenticatable
end

#sign_out(authenticatable_class) ⇒ Object



17
18
19
20
21
# File 'lib/passwordless/controller_helpers.rb', line 17

def sign_out(authenticatable_class)
  key = cookie_name(authenticatable_class)
  cookies.encrypted.permanent[key] = { value: nil }
  cookies.delete(key)
end