Sha256: 27083e459f115d335fa8145aebf09600cad9e5854007d45f2109873d6a4cf1ef
Contents?: true
Size: 902 Bytes
Versions: 10
Compression:
Stored size: 902 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] 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
10 entries across 10 versions & 1 rubygems