Sha256: 5034309902f4ec315b5ea45d5835f2892bc3e72bb72b7799fd4cf5f4c4a95cfe

Contents?: true

Size: 867 Bytes

Versions: 13

Compression:

Stored size: 867 Bytes

Contents

require 'active_support/concern'

module Wbase
  module AuthHelper
    def logged_in?
      !!current_user
    end

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

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

    def admin?
      session[:root]
    end

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

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

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

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

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
wbase-0.1.2 app/helpers/wbase/auth_helper.rb
wbase-0.1.0 app/helpers/wbase/auth_helper.rb
wbase-0.0.15 app/helpers/wbase/auth_helper.rb
wbase-0.0.14 app/helpers/wbase/auth_helper.rb
wbase-0.0.13 app/helpers/wbase/auth_helper.rb
wbase-0.0.12 app/helpers/wbase/auth_helper.rb
wbase-0.0.11 app/helpers/wbase/auth_helper.rb
wbase-0.0.10 app/helpers/wbase/auth_helper.rb
wbase-0.0.9 app/helpers/wbase/auth_helper.rb
wbase-0.0.8 app/helpers/wbase/auth_helper.rb
wbase-0.0.7 app/helpers/wbase/auth_helper.rb
wbase-0.0.6 app/helpers/wbase/auth_helper.rb
wbase-0.0.5 app/helpers/wbase/auth_helper.rb