@@ -73,13 +73,11 @@ def check_token_expiry!
73
73
def handle_user_cache_cookie!
74
74
if SESSION_REDIS
75
75
handle_user_cache_cookie_with_redis
76
- else
77
- if cookies [ :_radius_user_cache_key ]
78
- if cookies [ :_radius_user_cache_key ] == "none"
79
- delete_session_data
80
- elsif session [ :user_cache_key ] != cookies [ :_radius_user_cache_key ]
81
- clear_cache_cookie_and_sign_out
82
- end
76
+ elsif cookies [ :_radius_user_cache_key ]
77
+ if cookies [ :_radius_user_cache_key ] == "none"
78
+ delete_session_data
79
+ elsif session [ :user_cache_key ] != cookies [ :_radius_user_cache_key ]
80
+ clear_cache_cookie_and_sign_out
83
81
end
84
82
end
85
83
end
@@ -119,19 +117,23 @@ def user_signed_in?
119
117
private
120
118
121
119
def handle_user_cache_cookie_with_redis
122
- # If the user passes us a cache key cookie:
123
- if cookies [ :_radius_user_cache_key ]
124
- expected_val = SESSION_REDIS . get ( cookies [ :_radius_user_cache_key ] )
120
+ return redirect_to_sign_in unless session_present?
121
+ return if session_and_redis_match?
125
122
126
- # And we do not have that cookie in Redis
127
- if !expected_val
128
- delete_session_data
129
- # Or we have it in Redis, but it may be somebody else's
130
- # - it's not what we expect from their session
131
- elsif expected_val && expected_val != session [ :user_cache_key ]
132
- clear_cache_cookie_and_sign_out
133
- end
134
- end
123
+ delete_session_data
124
+ redirect_to_sign_in
125
+ end
126
+
127
+ def session_present?
128
+ session [ :user_id ] && session [ :user_cache_key ]
129
+ end
130
+
131
+ def session_and_redis_match?
132
+ SESSION_REDIS . get ( user_session_key ( session [ :user_id ] ) ) == session [ :user_cache_key ]
133
+ end
134
+
135
+ def user_session_key ( id )
136
+ "rnsession:#{ id } "
135
137
end
136
138
137
139
def delete_session_data
0 commit comments