Module: Authentication

Extended by:
ActiveSupport::Concern
Defined in:
lib/authentication.rb

Instance Method Summary collapse

Instance Method Details

#admin?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/authentication.rb', line 56

def admin?
  signed_in? && current_user.role.admin?
end

#auth_failedObject



46
47
48
49
50
# File 'lib/authentication.rb', line 46

def auth_failed
  sign_out
  session[:attempted_path] = request.fullpath
  redirect_to new_session_path, status: :see_other
end

#current_userObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/authentication.rb', line 12

def current_user
  if session[:user_id]
    @current_user ||= User.find(session[:user_id])
  end

  @current_user
rescue ActiveRecord::RecordNotFound
  sign_out
  nil
end

#require_userObject



8
9
10
# File 'lib/authentication.rb', line 8

def require_user
  if signed_in? then true else redirect_to(root_path) end
end

#sign_in(user) ⇒ Object



23
24
25
26
# File 'lib/authentication.rb', line 23

def  user
  session[:user_id] = user.id
  @current_user = user
end

#sign_outObject



28
29
30
31
# File 'lib/authentication.rb', line 28

def sign_out
  reset_session
  remove_instance_variable :@current_user if defined?(@current_user)
end

#signed_in!Object



41
42
43
44
# File 'lib/authentication.rb', line 41

def signed_in!
  return if signed_in?
  auth_failed
end

#signed_in?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/authentication.rb', line 33

def signed_in?
  !!current_user
end

#signed_in_path(source) ⇒ Object



60
61
62
# File 'lib/authentication.rb', line 60

def signed_in_path source
  session[:attempted_path] || current_user.role.admin? ? cms_path : root_path
end

#signed_out!Object



52
53
54
# File 'lib/authentication.rb', line 52

def signed_out!

end

#signed_out?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/authentication.rb', line 37

def signed_out?
  !signed_in?
end

#signed_out_pathObject



68
69
70
# File 'lib/authentication.rb', line 68

def signed_out_path
  root_path
end

#updated_account_pathObject



64
65
66
# File 'lib/authentication.rb', line 64

def 
  root_path
end