Mercurial > hg > soundsoftware-site
comparison app/controllers/account_controller.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | 0579821a129a |
children | 5e80956cc792 433d4f72a19b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2009 Jean-Philippe Lang | 2 # Copyright (C) 2006-2011 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
8 # | 8 # |
9 # This program is distributed in the hope that it will be useful, | 9 # This program is distributed in the hope that it will be useful, |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 # GNU General Public License for more details. | 12 # GNU General Public License for more details. |
13 # | 13 # |
14 # You should have received a copy of the GNU General Public License | 14 # You should have received a copy of the GNU General Public License |
15 # along with this program; if not, write to the Free Software | 15 # along with this program; if not, write to the Free Software |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 class AccountController < ApplicationController | 18 class AccountController < ApplicationController |
19 helper :custom_fields | 19 helper :custom_fields |
20 include CustomFieldsHelper | 20 include CustomFieldsHelper |
21 | 21 |
22 # prevents login action to be filtered by check_if_login_required application scope filter | 22 # prevents login action to be filtered by check_if_login_required application scope filter |
23 skip_before_filter :check_if_login_required | 23 skip_before_filter :check_if_login_required |
24 | 24 |
25 # Login request and validation | 25 # Login request and validation |
26 def login | 26 def login |
34 # Log out current user and redirect to welcome page | 34 # Log out current user and redirect to welcome page |
35 def logout | 35 def logout |
36 logout_user | 36 logout_user |
37 redirect_to home_url | 37 redirect_to home_url |
38 end | 38 end |
39 | 39 |
40 # Enable user to choose a new password | 40 # Enable user to choose a new password |
41 def lost_password | 41 def lost_password |
42 redirect_to(home_url) && return unless Setting.lost_password? | 42 redirect_to(home_url) && return unless Setting.lost_password? |
43 if params[:token] | 43 if params[:token] |
44 @token = Token.find_by_action_and_value("recovery", params[:token]) | 44 @token = Token.find_by_action_and_value("recovery", params[:token]) |
49 if @user.save | 49 if @user.save |
50 @token.destroy | 50 @token.destroy |
51 flash[:notice] = l(:notice_account_password_updated) | 51 flash[:notice] = l(:notice_account_password_updated) |
52 redirect_to :action => 'login' | 52 redirect_to :action => 'login' |
53 return | 53 return |
54 end | 54 end |
55 end | 55 end |
56 render :template => "account/password_recovery" | 56 render :template => "account/password_recovery" |
57 return | 57 return |
58 else | 58 else |
59 if request.post? | 59 if request.post? |
71 return | 71 return |
72 end | 72 end |
73 end | 73 end |
74 end | 74 end |
75 end | 75 end |
76 | 76 |
77 # User self-registration | 77 # User self-registration |
78 def register | 78 def register |
79 redirect_to(home_url) && return unless Setting.self_registration? || session[:auth_source_registration] | 79 redirect_to(home_url) && return unless Setting.self_registration? || session[:auth_source_registration] |
80 if request.get? | 80 if request.get? |
81 session[:auth_source_registration] = nil | 81 session[:auth_source_registration] = nil |
107 register_manually_by_administrator(@user) | 107 register_manually_by_administrator(@user) |
108 end | 108 end |
109 end | 109 end |
110 end | 110 end |
111 end | 111 end |
112 | 112 |
113 # Token based account activation | 113 # Token based account activation |
114 def activate | 114 def activate |
115 redirect_to(home_url) && return unless Setting.self_registration? && params[:token] | 115 redirect_to(home_url) && return unless Setting.self_registration? && params[:token] |
116 token = Token.find_by_action_and_value('register', params[:token]) | 116 token = Token.find_by_action_and_value('register', params[:token]) |
117 redirect_to(home_url) && return unless token and !token.expired? | 117 redirect_to(home_url) && return unless token and !token.expired? |
122 token.destroy | 122 token.destroy |
123 flash[:notice] = l(:notice_account_activated) | 123 flash[:notice] = l(:notice_account_activated) |
124 end | 124 end |
125 redirect_to :action => 'login' | 125 redirect_to :action => 'login' |
126 end | 126 end |
127 | 127 |
128 private | 128 private |
129 | 129 |
130 def logout_user | 130 def logout_user |
131 if User.current.logged? | 131 if User.current.logged? |
132 cookies.delete :autologin | 132 cookies.delete :autologin |
133 Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin']) | 133 Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin']) |
134 self.logged_user = nil | 134 self.logged_user = nil |
135 end | 135 end |
136 end | 136 end |
137 | 137 |
138 def authenticate_user | 138 def authenticate_user |
139 if Setting.openid? && using_open_id? | 139 if Setting.openid? && using_open_id? |
140 open_id_authenticate(params[:openid_url]) | 140 open_id_authenticate(params[:openid_url]) |
141 else | 141 else |
142 password_authentication | 142 password_authentication |
154 # Valid user | 154 # Valid user |
155 successful_authentication(user) | 155 successful_authentication(user) |
156 end | 156 end |
157 end | 157 end |
158 | 158 |
159 | |
160 def open_id_authenticate(openid_url) | 159 def open_id_authenticate(openid_url) |
161 authenticate_with_open_id(openid_url, :required => [:nickname, :fullname, :email], :return_to => signin_url) do |result, identity_url, registration| | 160 authenticate_with_open_id(openid_url, :required => [:nickname, :fullname, :email], :return_to => signin_url) do |result, identity_url, registration| |
162 if result.successful? | 161 if result.successful? |
163 user = User.find_or_initialize_by_identity_url(identity_url) | 162 user = User.find_or_initialize_by_identity_url(identity_url) |
164 if user.new_record? | 163 if user.new_record? |
183 end | 182 end |
184 else | 183 else |
185 register_manually_by_administrator(user) do | 184 register_manually_by_administrator(user) do |
186 onthefly_creation_failed(user) | 185 onthefly_creation_failed(user) |
187 end | 186 end |
188 end | 187 end |
189 else | 188 else |
190 # Existing record | 189 # Existing record |
191 if user.active? | 190 if user.active? |
192 successful_authentication(user) | 191 successful_authentication(user) |
193 else | 192 else |
195 end | 194 end |
196 end | 195 end |
197 end | 196 end |
198 end | 197 end |
199 end | 198 end |
200 | 199 |
201 def successful_authentication(user) | 200 def successful_authentication(user) |
202 # Valid user | 201 # Valid user |
203 self.logged_user = user | 202 self.logged_user = user |
204 # generate a key and set cookie if autologin | 203 # generate a key and set cookie if autologin |
205 if params[:autologin] && Setting.autologin? | 204 if params[:autologin] && Setting.autologin? |
206 set_autologin_cookie(user) | 205 set_autologin_cookie(user) |
207 end | 206 end |
208 call_hook(:controller_account_success_authentication_after, {:user => user }) | 207 call_hook(:controller_account_success_authentication_after, {:user => user }) |
209 redirect_back_or_default :controller => 'my', :action => 'page' | 208 redirect_back_or_default :controller => 'my', :action => 'page' |
210 end | 209 end |
211 | 210 |
212 def set_autologin_cookie(user) | 211 def set_autologin_cookie(user) |
213 token = Token.create(:user => user, :action => 'autologin') | 212 token = Token.create(:user => user, :action => 'autologin') |
214 cookie_name = Redmine::Configuration['autologin_cookie_name'] || 'autologin' | 213 cookie_name = Redmine::Configuration['autologin_cookie_name'] || 'autologin' |
215 cookie_options = { | 214 cookie_options = { |
216 :value => token.value, | 215 :value => token.value, |
245 redirect_to :action => 'login' | 244 redirect_to :action => 'login' |
246 else | 245 else |
247 yield if block_given? | 246 yield if block_given? |
248 end | 247 end |
249 end | 248 end |
250 | 249 |
251 # Automatically register a user | 250 # Automatically register a user |
252 # | 251 # |
253 # Pass a block for behavior when a user fails to save | 252 # Pass a block for behavior when a user fails to save |
254 def register_automatically(user, &block) | 253 def register_automatically(user, &block) |
255 # Automatic activation | 254 # Automatic activation |
261 redirect_to :controller => 'my', :action => 'account' | 260 redirect_to :controller => 'my', :action => 'account' |
262 else | 261 else |
263 yield if block_given? | 262 yield if block_given? |
264 end | 263 end |
265 end | 264 end |
266 | 265 |
267 # Manual activation by the administrator | 266 # Manual activation by the administrator |
268 # | 267 # |
269 # Pass a block for behavior when a user fails to save | 268 # Pass a block for behavior when a user fails to save |
270 def register_manually_by_administrator(user, &block) | 269 def register_manually_by_administrator(user, &block) |
271 if user.save | 270 if user.save |