Module: SessionsHelper

Included in:
ApplicationController
Defined in:
app/helpers/sessions_helper.rb

Instance Method Summary collapse

Instance Method Details

#sessions_current_userObject



11
12
13
14
# File 'app/helpers/sessions_helper.rb', line 11

def sessions_current_user
  remember_token = User.encrypt(cookies[:remember_token])
  @sessions_current_user ||= User.find_by(remember_token: remember_token)
end

#sessions_current_user=(user) ⇒ Object



7
8
9
# File 'app/helpers/sessions_helper.rb', line 7

def sessions_current_user=(user)
  @sessions_current_user = user
end

#sessions_sign_in(user) ⇒ Object



16
17
18
19
20
21
# File 'app/helpers/sessions_helper.rb', line 16

def (user)
  remember_token = User.secure_random_token
  cookies.permanent[:remember_token] = remember_token
  user.update_attribute(:remember_token, User.encrypt(remember_token))
  self.sessions_current_user = user
end

#sessions_sign_outObject



23
24
25
26
# File 'app/helpers/sessions_helper.rb', line 23

def sessions_sign_out
  self.sessions_current_user = nil
  cookies.delete(:remember_token)
end

#sessions_signed_in?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'app/helpers/sessions_helper.rb', line 3

def sessions_signed_in?
  !sessions_current_user.nil?
end