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