Module: Wbase::AuthHelper

Included in:
ApplicationController
Defined in:
app/helpers/wbase/auth_helper.rb

Instance Method Summary collapse

Instance Method Details

#admin?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/helpers/wbase/auth_helper.rb', line 17

def admin?
  session[:root]
end

#current_userObject



13
14
15
# File 'app/helpers/wbase/auth_helper.rb', line 13

def current_user
  @current_user ||= User.find_by(session_token: session[:token])
end

#logged_in?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'app/helpers/wbase/auth_helper.rb', line 5

def logged_in?
  !!current_user
end

#login(user) ⇒ Object



33
34
35
36
37
# File 'app/helpers/wbase/auth_helper.rb', line 33

def (user)
  session[:token] = user.session_token
  session[:root] = user.root?
  user.update(login_at: Time.now)
end

#logoutObject



39
40
41
42
# File 'app/helpers/wbase/auth_helper.rb', line 39

def logout
  current_user.try(:reset_session_token!)
  session[:root] = false
end

#require_login!Object



29
30
31
# File 'app/helpers/wbase/auth_helper.rb', line 29

def require_login!
  redirect_to '/welcome' unless logged_in?
end

#require_root!Object



25
26
27
# File 'app/helpers/wbase/auth_helper.rb', line 25

def require_root!
  redirect_to '/' unless current_user.try(:root)
end

#require_subscription!Object



21
22
23
# File 'app/helpers/wbase/auth_helper.rb', line 21

def require_subscription!
  redirect_to '/subscription/new' unless subscribed?
end

#subscribed?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'app/helpers/wbase/auth_helper.rb', line 9

def subscribed?
  logged_in? && current_user && current_user.try(:subscribed?)
end