Sha256: 7f5a1aebefb3a8050a44ef9b4167d65aadfd513fd1cd2ae15e268e583affd0b6

Contents?: true

Size: 958 Bytes

Versions: 21

Compression:

Stored size: 958 Bytes

Contents

require 'active_support/concern'

module Wbase
  module AuthHelper
    extend ActiveSupport::Concern

    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] || current_user.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)
      cookies[:email] = user.email
    end

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

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
wbase-0.3.20 app/helpers/wbase/auth_helper.rb
wbase-0.3.19 app/helpers/wbase/auth_helper.rb
wbase-0.3.18 app/helpers/wbase/auth_helper.rb
wbase-0.3.17 app/helpers/wbase/auth_helper.rb
wbase-0.3.16 app/helpers/wbase/auth_helper.rb
wbase-0.3.15 app/helpers/wbase/auth_helper.rb
wbase-0.3.14 app/helpers/wbase/auth_helper.rb
wbase-0.3.13 app/helpers/wbase/auth_helper.rb
wbase-0.3.12 app/helpers/wbase/auth_helper.rb
wbase-0.3.11 app/helpers/wbase/auth_helper.rb
wbase-0.3.10 app/helpers/wbase/auth_helper.rb
wbase-0.3.9 app/helpers/wbase/auth_helper.rb
wbase-0.3.8 app/helpers/wbase/auth_helper.rb
wbase-0.3.7 app/helpers/wbase/auth_helper.rb
wbase-0.3.6 app/helpers/wbase/auth_helper.rb
wbase-0.3.5 app/helpers/wbase/auth_helper.rb
wbase-0.3.4 app/helpers/wbase/auth_helper.rb
wbase-0.3.3 app/helpers/wbase/auth_helper.rb
wbase-0.3.2 app/helpers/wbase/auth_helper.rb
wbase-0.3.1 app/helpers/wbase/auth_helper.rb