summaryrefslogtreecommitdiff
path: root/app/helpers
diff options
context:
space:
mode:
authorshumakl <shumakl@purdue.edu>2014-04-03 16:44:29 -0400
committershumakl <shumakl@purdue.edu>2014-04-03 16:45:00 -0400
commitdfe5dbd2ada1841b09f70bfd742c10ba878f74fe (patch)
tree1bfd64e9f20f1299fe570130d2660e58d14e2dad /app/helpers
parent9f19d0e16d7920e07255c0fbe596c518d1aa415f (diff)
Use the null object pattern for current_user when not logged in
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/sessions_helper.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb
index 54e4b0d..89e5ef3 100644
--- a/app/helpers/sessions_helper.rb
+++ b/app/helpers/sessions_helper.rb
@@ -18,7 +18,7 @@ module SessionsHelper
def current_user
@token ||= Session.hash_token(cookies[:remember_token])
@session ||= Session.find_by(token: @token)
- @current_user ||= (@session.nil? ? nil : @session.user)
+ @current_user ||= (@session.nil? ? NilUser.new : @session.user)
end
# checks if someone is currently signed in
@@ -30,7 +30,7 @@ module SessionsHelper
if signed_in?
@session.destroy
end
- @current_user = nil
+ @current_user = NilUser.new
cookies.delete(:remember_token)
end