|
@@ -43,8 +43,8 @@ module AuthenticationHelper
|
43
|
43
|
|
44
|
44
|
# Determine whether the user is logged in, and if so, disable the Session, then flush session cookies.
|
45
|
45
|
def log_out(session_broken: false)
|
46
|
|
- if !session_broken && is_logged_in? && @user_session
|
47
|
|
- get_user_session
|
|
46
|
+ if !session_broken && logged_in? && @user_session
|
|
47
|
+ user_session
|
48
|
48
|
|
49
|
49
|
@user_session.update!(active: false)
|
50
|
50
|
end
|
|
@@ -57,12 +57,12 @@ module AuthenticationHelper
|
57
|
57
|
|
58
|
58
|
# Determine whether the current request is from a user with a non-expired session.
|
59
|
59
|
# Makes @user_session available as a side effect if the user is not.
|
60
|
|
- def is_logged_in?
|
|
60
|
+ def logged_in?
|
61
|
61
|
# Case 1: User has an active session inside the cookie.
|
62
|
62
|
# We verify that the session hasn't expired yet.
|
63
|
63
|
if session[:user_id] && session[:expires].to_time > DateTime.now
|
64
|
64
|
|
65
|
|
- get_user_session
|
|
65
|
+ user_session
|
66
|
66
|
|
67
|
67
|
return false if !@user_session.active || @user_session.expires < Time.now
|
68
|
68
|
|
|
@@ -74,7 +74,7 @@ module AuthenticationHelper
|
74
|
74
|
if cookies.signed.permanent[:remember_token] && cookies.signed.permanent[:user_id] &&
|
75
|
75
|
cookies.signed.permanent[:session_id]
|
76
|
76
|
|
77
|
|
- get_user_session
|
|
77
|
+ user_session
|
78
|
78
|
|
79
|
79
|
return false if @user_session.nil? || @user_session.remember_digest.nil?
|
80
|
80
|
|
|
@@ -94,7 +94,7 @@ module AuthenticationHelper
|
94
|
94
|
end
|
95
|
95
|
|
96
|
96
|
# Get the Session object representing the current user's session.
|
97
|
|
- def get_user_session
|
|
97
|
+ def user_session
|
98
|
98
|
if @user_session
|
99
|
99
|
@user_session
|
100
|
100
|
else
|
|
@@ -107,7 +107,7 @@ module AuthenticationHelper
|
107
|
107
|
end
|
108
|
108
|
|
109
|
109
|
def current_user
|
110
|
|
- get_user_session
|
|
110
|
+ user_session
|
111
|
111
|
@user_session&.user
|
112
|
112
|
end
|
113
|
113
|
|
|
@@ -116,7 +116,7 @@ module AuthenticationHelper
|
116
|
116
|
end
|
117
|
117
|
|
118
|
118
|
def require_login!
|
119
|
|
- unless is_logged_in?
|
|
119
|
+ unless logged_in?
|
120
|
120
|
flash_message(:warning, I18n.t('authentication.login_required'))
|
121
|
121
|
redirect_to controller: 'authentication', action: 'login_form'
|
122
|
122
|
return false
|