Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 119
- Log:
First steps in adapting RForum to use Hub for login.
- Author:
- adh
- Date:
- Fri Oct 27 21:27:11 +0100 2006
- Size:
- 3989 Bytes
1 | require 'navbar' |
2 | require 'post_menu' |
3 | require 'url_generator' |
4 | |
5 | # The filters added to this controller will be run for all controllers in the application. |
6 | # Likewise will all the methods added be available for all controllers. |
7 | class ApplicationController < ActionController::Base |
8 | |
9 | # Hub single sign-on support. |
10 | |
11 | require 'hub_sso_lib' |
12 | include HubSsoLib::Core |
13 | before_filter :hubssolib_beforehand |
14 | after_filter :hubssolib_afterwards |
15 | |
16 | # Standard RForum gubbins follows. |
17 | |
18 | model :forum, :post, :topic, :user |
19 | helper :application |
20 | |
21 | session :session_expires => Time.now + 1.years |
22 | |
23 | include RForum::Localization |
24 | |
25 | layout 'default' |
26 | before_filter :check_block, :setup_user, :setup_url_generator, :setup_local, \ |
27 | :setup_skin |
28 | |
29 | before_filter :detect_site if RForum::CONFIG[:use_sites] |
30 | |
31 | before_filter :get_forums |
32 | |
33 | after_filter :finish_user, :remember_location |
34 | |
35 | # Default index action: redirect to start page |
36 | def index |
37 | redirect_to :controller => 'forum', :action => 'list' |
38 | end |
39 | |
40 | protected |
41 | |
42 | def rescue_action(e) |
43 | if e.is_a?(RForum::SecurityError) |
44 | redirect_to :controller => 'security', :action => 'access_denied' |
45 | else |
46 | super |
47 | end |
48 | end |
49 | |
50 | # Check if the client IP is blocked |
51 | def check_block |
52 | if BlockedIp.blocked?(@request.remote_ip) |
53 | # don't waste any time on template rendering |
54 | render_text 'blocked', 403 |
55 | return false |
56 | end |
57 | end |
58 | |
59 | def setup_user |
60 | if @params['user_id'] and @params['key'] |
61 | @user = User.find_by_token(@params['user_id'], @params['key']) |
62 | @authenticated_by_token = true |
63 | # set the token to expire in no more than next 10 minutes |
64 | if @user |
65 | @user.token_expiry = [@user.token_expiry, Time.at(Time.now.to_i + 600 * 1000)].min |
66 | @user.save |
67 | end |
68 | elsif @session[:user_id] |
69 | @user = User.find(@session[:user_id]) |
70 | else |
71 | @user = Guest.new(@session[:guest_name], @session[:guest_email]) if @user.nil? |
72 | end |
73 | |
74 | raise RForum::SecurityError if @user.nil? |
75 | |
76 | rescue => e |
77 | reset_session |
78 | if retried? |
79 | raise e |
80 | else |
81 | retried = true |
82 | retry |
83 | end |
84 | end |
85 | |
86 | def setup_url_generator |
87 | UrlGenerator.controller = self |
88 | end |
89 | |
90 | def finish_user |
91 | @session[:user_id] = @user.id |
92 | @session[:guest_name] = @user.guest_name |
93 | @session[:guest_email] = @user.guest_email |
94 | end |
95 | |
96 | @@REMEMBER_NOT = ['user', 'security', 'feed'] |
97 | def remember_location |
98 | if @response.headers['Status'] == '200 OK' |
99 | @session[:return_to] = url_for unless @@REMEMBER_NOT.include? controller_name |
100 | end |
101 | end |
102 | |
103 | def return_to_last_remembered |
104 | begin |
105 | redirect_to_url(@session[:return_to] || '/') |
106 | rescue RForum::SecurityError |
107 | redirect_to_url('/') |
108 | end |
109 | end |
110 | |
111 | def setup_local |
112 | @headers["Content-Type"] = "text/html; charset=#{RForum::CONFIG[:web_charset]}" |
113 | end |
114 | |
115 | def setup_skin |
116 | if @params['set_skin'] |
117 | @session[:skin] = @params['set_skin'] |
118 | end |
119 | |
120 | @skin = @session[:skin] || RForum::CONFIG[:skin] |
121 | end |
122 | |
123 | def detect_site |
124 | @site = Site.find(:first, :conditions => ["host = ?", request.host]) |
125 | if @site |
126 | self.class.layout @site.layout || 'default' |
127 | @skin = @session[:skin] || @site.skin || 'default' |
128 | end |
129 | end |
130 | |
131 | def get_forums |
132 | if @site |
133 | @forums = @site.forums.find(:all, :order => 'position') |
134 | else |
135 | @forums = Forum.find(:all, :order => 'site_id, position') |
136 | end |
137 | end |
138 | |
139 | def redirect_if_site_doesnt_match |
140 | if @site && @forum && @forum.site && (@site != @forum.site) |
141 | headers["Status"] = "301 Moved Permanently" |
142 | redirect_to_url 'http://' + @forum.site.host + request.path |
143 | return true |
144 | end |
145 | return false |
146 | end |
147 | end |
148 | |
149 | module RForum |
150 | |
151 | # Security error. Controllers throw these in situations where a user is trying to access a |
152 | # function that he is not authorized to access. |
153 | # Normally, RForum does not show URLs that would allow the user to access such features. |
154 | class SecurityError < StandardError |
155 | end |
156 | |
157 | end |