Introduction
Introduction Statistics Contact Development Disclaimer Help
application_controller.rb - warvox - VoIP based wardialing tool, forked from ra…
git clone git://jay.scot/warvox
Log
Files
Refs
README
---
application_controller.rb (1671B)
---
1 class ApplicationController < ActionController::Base
2 protect_from_forgery with: :exception
3 helper :all
4
5 helper_method :current_user_session, :current_user
6 before_action :require_user, :load_project
7 add_breadcrumb :projects, :root_path
8
9 include ActionView::Helpers::NumberHelper
10
11 private
12
13 def current_user_session
14 return @current_user_session if defined?(@current_user_session)
15 @current_user_session = UserSession.find
16 end
17
18 def current_user
19 return @current_user if defined?(@current_user)
20 @current_user = current_user_session && current_user_session.record
21 end
22
23 def require_user
24 unless current_user
25 store_location
26 flash.now[:notice] = "You must be logged in to access this page"
27 redirect_to '/login'
28 return false
29 end
30 end
31
32 def require_no_user
33 if current_user
34 store_location
35 flash[:notice] = "You must be logged out to access this page"
36 redirect_to user_path(current_user)
37 return false
38 end
39 end
40
41 def store_location
42 session[:return_to] = request.fullpath
43 end
44
45 def redirect_back_or_default(default)
46 redirect_to(session[:return_to] || default)
47 session[:return_to] = nil
48 end
49
50 def load_project
51 # Only load this when we are logged in
52 return true unless current_user
53
54 if params[:project_id]
55 @project = Project.where(id: params[:project_id].to_i).first
56 elsif session[:project_id]
57 @project = Project.where(id: session[:project_id].to_i).first
58 end
59
60 if @project and @project.id and not (session[:project_id] and sessio…
61 session[:project_id] = @project.id
62 end
63
64 true
65 end
66
67
68 end
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.