@@ -1,354 +1,354 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 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, :check_password_change |
|
23 | skip_before_filter :check_if_login_required, :check_password_change | |
24 |
|
24 | |||
25 | # Overrides ApplicationController#verify_authenticity_token to disable |
|
25 | # Overrides ApplicationController#verify_authenticity_token to disable | |
26 | # token verification on openid callbacks |
|
26 | # token verification on openid callbacks | |
27 | def verify_authenticity_token |
|
27 | def verify_authenticity_token | |
28 | unless using_open_id? |
|
28 | unless using_open_id? | |
29 | super |
|
29 | super | |
30 | end |
|
30 | end | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | # Login request and validation |
|
33 | # Login request and validation | |
34 | def login |
|
34 | def login | |
35 | if request.get? |
|
35 | if request.get? | |
36 | if User.current.logged? |
|
36 | if User.current.logged? | |
37 | redirect_back_or_default home_url, :referer => true |
|
37 | redirect_back_or_default home_url, :referer => true | |
38 | end |
|
38 | end | |
39 | else |
|
39 | else | |
40 | authenticate_user |
|
40 | authenticate_user | |
41 | end |
|
41 | end | |
42 | rescue AuthSourceException => e |
|
42 | rescue AuthSourceException => e | |
43 | logger.error "An error occured when authenticating #{params[:username]}: #{e.message}" |
|
43 | logger.error "An error occured when authenticating #{params[:username]}: #{e.message}" | |
44 | render_error :message => e.message |
|
44 | render_error :message => e.message | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | # Log out current user and redirect to welcome page |
|
47 | # Log out current user and redirect to welcome page | |
48 | def logout |
|
48 | def logout | |
49 | if User.current.anonymous? |
|
49 | if User.current.anonymous? | |
50 | redirect_to home_url |
|
50 | redirect_to home_url | |
51 | elsif request.post? |
|
51 | elsif request.post? | |
52 | logout_user |
|
52 | logout_user | |
53 | redirect_to home_url |
|
53 | redirect_to home_url | |
54 | end |
|
54 | end | |
55 | # display the logout form |
|
55 | # display the logout form | |
56 | end |
|
56 | end | |
57 |
|
57 | |||
58 | # Lets user choose a new password |
|
58 | # Lets user choose a new password | |
59 | def lost_password |
|
59 | def lost_password | |
60 | (redirect_to(home_url); return) unless Setting.lost_password? |
|
60 | (redirect_to(home_url); return) unless Setting.lost_password? | |
61 | if params[:token] |
|
61 | if params[:token] | |
62 | @token = Token.find_token("recovery", params[:token].to_s) |
|
62 | @token = Token.find_token("recovery", params[:token].to_s) | |
63 | if @token.nil? || @token.expired? |
|
63 | if @token.nil? || @token.expired? | |
64 | redirect_to home_url |
|
64 | redirect_to home_url | |
65 | return |
|
65 | return | |
66 | end |
|
66 | end | |
67 | @user = @token.user |
|
67 | @user = @token.user | |
68 | unless @user && @user.active? |
|
68 | unless @user && @user.active? | |
69 | redirect_to home_url |
|
69 | redirect_to home_url | |
70 | return |
|
70 | return | |
71 | end |
|
71 | end | |
72 | if request.post? |
|
72 | if request.post? | |
73 | @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] |
|
73 | @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] | |
74 | if @user.save |
|
74 | if @user.save | |
75 | @token.destroy |
|
75 | @token.destroy | |
76 | flash[:notice] = l(:notice_account_password_updated) |
|
76 | flash[:notice] = l(:notice_account_password_updated) | |
77 | redirect_to signin_path |
|
77 | redirect_to signin_path | |
78 | return |
|
78 | return | |
79 | end |
|
79 | end | |
80 | end |
|
80 | end | |
81 | render :template => "account/password_recovery" |
|
81 | render :template => "account/password_recovery" | |
82 | return |
|
82 | return | |
83 | else |
|
83 | else | |
84 | if request.post? |
|
84 | if request.post? | |
85 | email = params[:mail].to_s |
|
85 | email = params[:mail].to_s | |
86 | user = User.find_by_mail(email) |
|
86 | user = User.find_by_mail(email) | |
87 | # user not found |
|
87 | # user not found | |
88 | unless user |
|
88 | unless user | |
89 | flash.now[:error] = l(:notice_account_unknown_email) |
|
89 | flash.now[:error] = l(:notice_account_unknown_email) | |
90 | return |
|
90 | return | |
91 | end |
|
91 | end | |
92 | unless user.active? |
|
92 | unless user.active? | |
93 | handle_inactive_user(user, lost_password_path) |
|
93 | handle_inactive_user(user, lost_password_path) | |
94 | return |
|
94 | return | |
95 | end |
|
95 | end | |
96 | # user cannot change its password |
|
96 | # user cannot change its password | |
97 | unless user.change_password_allowed? |
|
97 | unless user.change_password_allowed? | |
98 | flash.now[:error] = l(:notice_can_t_change_password) |
|
98 | flash.now[:error] = l(:notice_can_t_change_password) | |
99 | return |
|
99 | return | |
100 | end |
|
100 | end | |
101 | # create a new token for password recovery |
|
101 | # create a new token for password recovery | |
102 | token = Token.new(:user => user, :action => "recovery") |
|
102 | token = Token.new(:user => user, :action => "recovery") | |
103 | if token.save |
|
103 | if token.save | |
104 | # Don't use the param to send the email |
|
104 | # Don't use the param to send the email | |
105 | recipent = user.mails.detect {|e| e.downcase == email.downcase} || user.mail |
|
105 | recipent = user.mails.detect {|e| e.downcase == email.downcase} || user.mail | |
106 | Mailer.lost_password(token, recipent).deliver |
|
106 | Mailer.lost_password(token, recipent).deliver | |
107 | flash[:notice] = l(:notice_account_lost_email_sent) |
|
107 | flash[:notice] = l(:notice_account_lost_email_sent) | |
108 | redirect_to signin_path |
|
108 | redirect_to signin_path | |
109 | return |
|
109 | return | |
110 | end |
|
110 | end | |
111 | end |
|
111 | end | |
112 | end |
|
112 | end | |
113 | end |
|
113 | end | |
114 |
|
114 | |||
115 | # User self-registration |
|
115 | # User self-registration | |
116 | def register |
|
116 | def register | |
117 | (redirect_to(home_url); return) unless Setting.self_registration? || session[:auth_source_registration] |
|
117 | (redirect_to(home_url); return) unless Setting.self_registration? || session[:auth_source_registration] | |
118 | if request.get? |
|
118 | if request.get? | |
119 | session[:auth_source_registration] = nil |
|
119 | session[:auth_source_registration] = nil | |
120 | @user = User.new(:language => current_language.to_s) |
|
120 | @user = User.new(:language => current_language.to_s) | |
121 | else |
|
121 | else | |
122 | user_params = params[:user] || {} |
|
122 | user_params = params[:user] || {} | |
123 | @user = User.new |
|
123 | @user = User.new | |
124 | @user.safe_attributes = user_params |
|
124 | @user.safe_attributes = user_params | |
125 | @user.admin = false |
|
125 | @user.admin = false | |
126 | @user.register |
|
126 | @user.register | |
127 | if session[:auth_source_registration] |
|
127 | if session[:auth_source_registration] | |
128 | @user.activate |
|
128 | @user.activate | |
129 | @user.login = session[:auth_source_registration][:login] |
|
129 | @user.login = session[:auth_source_registration][:login] | |
130 | @user.auth_source_id = session[:auth_source_registration][:auth_source_id] |
|
130 | @user.auth_source_id = session[:auth_source_registration][:auth_source_id] | |
131 | if @user.save |
|
131 | if @user.save | |
132 | session[:auth_source_registration] = nil |
|
132 | session[:auth_source_registration] = nil | |
133 | self.logged_user = @user |
|
133 | self.logged_user = @user | |
134 | flash[:notice] = l(:notice_account_activated) |
|
134 | flash[:notice] = l(:notice_account_activated) | |
135 | redirect_to my_account_path |
|
135 | redirect_to my_account_path | |
136 | end |
|
136 | end | |
137 | else |
|
137 | else | |
138 | @user.login = params[:user][:login] |
|
138 | @user.login = params[:user][:login] | |
139 | unless user_params[:identity_url].present? && user_params[:password].blank? && user_params[:password_confirmation].blank? |
|
139 | unless user_params[:identity_url].present? && user_params[:password].blank? && user_params[:password_confirmation].blank? | |
140 | @user.password, @user.password_confirmation = user_params[:password], user_params[:password_confirmation] |
|
140 | @user.password, @user.password_confirmation = user_params[:password], user_params[:password_confirmation] | |
141 | end |
|
141 | end | |
142 |
|
142 | |||
143 | case Setting.self_registration |
|
143 | case Setting.self_registration | |
144 | when '1' |
|
144 | when '1' | |
145 | register_by_email_activation(@user) |
|
145 | register_by_email_activation(@user) | |
146 | when '3' |
|
146 | when '3' | |
147 | register_automatically(@user) |
|
147 | register_automatically(@user) | |
148 | else |
|
148 | else | |
149 | register_manually_by_administrator(@user) |
|
149 | register_manually_by_administrator(@user) | |
150 | end |
|
150 | end | |
151 | end |
|
151 | end | |
152 | end |
|
152 | end | |
153 | end |
|
153 | end | |
154 |
|
154 | |||
155 | # Token based account activation |
|
155 | # Token based account activation | |
156 | def activate |
|
156 | def activate | |
157 | (redirect_to(home_url); return) unless Setting.self_registration? && params[:token].present? |
|
157 | (redirect_to(home_url); return) unless Setting.self_registration? && params[:token].present? | |
158 | token = Token.find_token('register', params[:token].to_s) |
|
158 | token = Token.find_token('register', params[:token].to_s) | |
159 | (redirect_to(home_url); return) unless token and !token.expired? |
|
159 | (redirect_to(home_url); return) unless token and !token.expired? | |
160 | user = token.user |
|
160 | user = token.user | |
161 | (redirect_to(home_url); return) unless user.registered? |
|
161 | (redirect_to(home_url); return) unless user.registered? | |
162 | user.activate |
|
162 | user.activate | |
163 | if user.save |
|
163 | if user.save | |
164 | token.destroy |
|
164 | token.destroy | |
165 | flash[:notice] = l(:notice_account_activated) |
|
165 | flash[:notice] = l(:notice_account_activated) | |
166 | end |
|
166 | end | |
167 | redirect_to signin_path |
|
167 | redirect_to signin_path | |
168 | end |
|
168 | end | |
169 |
|
169 | |||
170 | # Sends a new account activation email |
|
170 | # Sends a new account activation email | |
171 | def activation_email |
|
171 | def activation_email | |
172 | if session[:registered_user_id] && Setting.self_registration == '1' |
|
172 | if session[:registered_user_id] && Setting.self_registration == '1' | |
173 | user_id = session.delete(:registered_user_id).to_i |
|
173 | user_id = session.delete(:registered_user_id).to_i | |
174 | user = User.find_by_id(user_id) |
|
174 | user = User.find_by_id(user_id) | |
175 | if user && user.registered? |
|
175 | if user && user.registered? | |
176 | register_by_email_activation(user) |
|
176 | register_by_email_activation(user) | |
177 | return |
|
177 | return | |
178 | end |
|
178 | end | |
179 | end |
|
179 | end | |
180 | redirect_to(home_url) |
|
180 | redirect_to(home_url) | |
181 | end |
|
181 | end | |
182 |
|
182 | |||
183 | private |
|
183 | private | |
184 |
|
184 | |||
185 | def authenticate_user |
|
185 | def authenticate_user | |
186 | if Setting.openid? && using_open_id? |
|
186 | if Setting.openid? && using_open_id? | |
187 | open_id_authenticate(params[:openid_url]) |
|
187 | open_id_authenticate(params[:openid_url]) | |
188 | else |
|
188 | else | |
189 | password_authentication |
|
189 | password_authentication | |
190 | end |
|
190 | end | |
191 | end |
|
191 | end | |
192 |
|
192 | |||
193 | def password_authentication |
|
193 | def password_authentication | |
194 | user = User.try_to_login(params[:username], params[:password], false) |
|
194 | user = User.try_to_login(params[:username], params[:password], false) | |
195 |
|
195 | |||
196 | if user.nil? |
|
196 | if user.nil? | |
197 | invalid_credentials |
|
197 | invalid_credentials | |
198 | elsif user.new_record? |
|
198 | elsif user.new_record? | |
199 | onthefly_creation_failed(user, {:login => user.login, :auth_source_id => user.auth_source_id }) |
|
199 | onthefly_creation_failed(user, {:login => user.login, :auth_source_id => user.auth_source_id }) | |
200 | else |
|
200 | else | |
201 | # Valid user |
|
201 | # Valid user | |
202 | if user.active? |
|
202 | if user.active? | |
203 | successful_authentication(user) |
|
203 | successful_authentication(user) | |
204 | else |
|
204 | else | |
205 | handle_inactive_user(user) |
|
205 | handle_inactive_user(user) | |
206 | end |
|
206 | end | |
207 | end |
|
207 | end | |
208 | end |
|
208 | end | |
209 |
|
209 | |||
210 | def open_id_authenticate(openid_url) |
|
210 | def open_id_authenticate(openid_url) | |
211 | back_url = signin_url(:autologin => params[:autologin]) |
|
211 | back_url = signin_url(:autologin => params[:autologin]) | |
212 | authenticate_with_open_id( |
|
212 | authenticate_with_open_id( | |
213 | openid_url, :required => [:nickname, :fullname, :email], |
|
213 | openid_url, :required => [:nickname, :fullname, :email], | |
214 | :return_to => back_url, :method => :post |
|
214 | :return_to => back_url, :method => :post | |
215 | ) do |result, identity_url, registration| |
|
215 | ) do |result, identity_url, registration| | |
216 | if result.successful? |
|
216 | if result.successful? | |
217 | user = User.find_or_initialize_by_identity_url(identity_url) |
|
217 | user = User.find_or_initialize_by_identity_url(identity_url) | |
218 | if user.new_record? |
|
218 | if user.new_record? | |
219 | # Self-registration off |
|
219 | # Self-registration off | |
220 | (redirect_to(home_url); return) unless Setting.self_registration? |
|
220 | (redirect_to(home_url); return) unless Setting.self_registration? | |
221 | # Create on the fly |
|
221 | # Create on the fly | |
222 | user.login = registration['nickname'] unless registration['nickname'].nil? |
|
222 | user.login = registration['nickname'] unless registration['nickname'].nil? | |
223 | user.mail = registration['email'] unless registration['email'].nil? |
|
223 | user.mail = registration['email'] unless registration['email'].nil? | |
224 | user.firstname, user.lastname = registration['fullname'].split(' ') unless registration['fullname'].nil? |
|
224 | user.firstname, user.lastname = registration['fullname'].split(' ') unless registration['fullname'].nil? | |
225 | user.random_password |
|
225 | user.random_password | |
226 | user.register |
|
226 | user.register | |
227 | case Setting.self_registration |
|
227 | case Setting.self_registration | |
228 | when '1' |
|
228 | when '1' | |
229 | register_by_email_activation(user) do |
|
229 | register_by_email_activation(user) do | |
230 | onthefly_creation_failed(user) |
|
230 | onthefly_creation_failed(user) | |
231 | end |
|
231 | end | |
232 | when '3' |
|
232 | when '3' | |
233 | register_automatically(user) do |
|
233 | register_automatically(user) do | |
234 | onthefly_creation_failed(user) |
|
234 | onthefly_creation_failed(user) | |
235 | end |
|
235 | end | |
236 | else |
|
236 | else | |
237 | register_manually_by_administrator(user) do |
|
237 | register_manually_by_administrator(user) do | |
238 | onthefly_creation_failed(user) |
|
238 | onthefly_creation_failed(user) | |
239 | end |
|
239 | end | |
240 | end |
|
240 | end | |
241 | else |
|
241 | else | |
242 | # Existing record |
|
242 | # Existing record | |
243 | if user.active? |
|
243 | if user.active? | |
244 | successful_authentication(user) |
|
244 | successful_authentication(user) | |
245 | else |
|
245 | else | |
246 | handle_inactive_user(user) |
|
246 | handle_inactive_user(user) | |
247 | end |
|
247 | end | |
248 | end |
|
248 | end | |
249 | end |
|
249 | end | |
250 | end |
|
250 | end | |
251 | end |
|
251 | end | |
252 |
|
252 | |||
253 | def successful_authentication(user) |
|
253 | def successful_authentication(user) | |
254 | logger.info "Successful authentication for '#{user.login}' from #{request.remote_ip} at #{Time.now.utc}" |
|
254 | logger.info "Successful authentication for '#{user.login}' from #{request.remote_ip} at #{Time.now.utc}" | |
255 | # Valid user |
|
255 | # Valid user | |
256 | self.logged_user = user |
|
256 | self.logged_user = user | |
257 | # generate a key and set cookie if autologin |
|
257 | # generate a key and set cookie if autologin | |
258 | if params[:autologin] && Setting.autologin? |
|
258 | if params[:autologin] && Setting.autologin? | |
259 | set_autologin_cookie(user) |
|
259 | set_autologin_cookie(user) | |
260 | end |
|
260 | end | |
261 | call_hook(:controller_account_success_authentication_after, {:user => user }) |
|
261 | call_hook(:controller_account_success_authentication_after, {:user => user }) | |
262 | redirect_back_or_default my_page_path |
|
262 | redirect_back_or_default my_page_path | |
263 | end |
|
263 | end | |
264 |
|
264 | |||
265 | def set_autologin_cookie(user) |
|
265 | def set_autologin_cookie(user) | |
266 | token = Token.create(:user => user, :action => 'autologin') |
|
266 | token = Token.create(:user => user, :action => 'autologin') | |
267 | cookie_options = { |
|
267 | cookie_options = { | |
268 | :value => token.value, |
|
268 | :value => token.value, | |
269 | :expires => 1.year.from_now, |
|
269 | :expires => 1.year.from_now, | |
270 | :path => (Redmine::Configuration['autologin_cookie_path'] || '/'), |
|
270 | :path => (Redmine::Configuration['autologin_cookie_path'] || '/'), | |
271 | :secure => (Redmine::Configuration['autologin_cookie_secure'] ? true : false), |
|
271 | :secure => (Redmine::Configuration['autologin_cookie_secure'] ? true : false), | |
272 | :httponly => true |
|
272 | :httponly => true | |
273 | } |
|
273 | } | |
274 | cookies[autologin_cookie_name] = cookie_options |
|
274 | cookies[autologin_cookie_name] = cookie_options | |
275 | end |
|
275 | end | |
276 |
|
276 | |||
277 | # Onthefly creation failed, display the registration form to fill/fix attributes |
|
277 | # Onthefly creation failed, display the registration form to fill/fix attributes | |
278 | def onthefly_creation_failed(user, auth_source_options = { }) |
|
278 | def onthefly_creation_failed(user, auth_source_options = { }) | |
279 | @user = user |
|
279 | @user = user | |
280 | session[:auth_source_registration] = auth_source_options unless auth_source_options.empty? |
|
280 | session[:auth_source_registration] = auth_source_options unless auth_source_options.empty? | |
281 | render :action => 'register' |
|
281 | render :action => 'register' | |
282 | end |
|
282 | end | |
283 |
|
283 | |||
284 | def invalid_credentials |
|
284 | def invalid_credentials | |
285 | logger.warn "Failed login for '#{params[:username]}' from #{request.remote_ip} at #{Time.now.utc}" |
|
285 | logger.warn "Failed login for '#{params[:username]}' from #{request.remote_ip} at #{Time.now.utc}" | |
286 | flash.now[:error] = l(:notice_account_invalid_creditentials) |
|
286 | flash.now[:error] = l(:notice_account_invalid_creditentials) | |
287 | end |
|
287 | end | |
288 |
|
288 | |||
289 | # Register a user for email activation. |
|
289 | # Register a user for email activation. | |
290 | # |
|
290 | # | |
291 | # Pass a block for behavior when a user fails to save |
|
291 | # Pass a block for behavior when a user fails to save | |
292 | def register_by_email_activation(user, &block) |
|
292 | def register_by_email_activation(user, &block) | |
293 | token = Token.new(:user => user, :action => "register") |
|
293 | token = Token.new(:user => user, :action => "register") | |
294 | if user.save and token.save |
|
294 | if user.save and token.save | |
295 | Mailer.register(token).deliver |
|
295 | Mailer.register(token).deliver | |
296 | flash[:notice] = l(:notice_account_register_done, :email => user.mail) |
|
296 | flash[:notice] = l(:notice_account_register_done, :email => ERB::Util.h(user.mail)) | |
297 | redirect_to signin_path |
|
297 | redirect_to signin_path | |
298 | else |
|
298 | else | |
299 | yield if block_given? |
|
299 | yield if block_given? | |
300 | end |
|
300 | end | |
301 | end |
|
301 | end | |
302 |
|
302 | |||
303 | # Automatically register a user |
|
303 | # Automatically register a user | |
304 | # |
|
304 | # | |
305 | # Pass a block for behavior when a user fails to save |
|
305 | # Pass a block for behavior when a user fails to save | |
306 | def register_automatically(user, &block) |
|
306 | def register_automatically(user, &block) | |
307 | # Automatic activation |
|
307 | # Automatic activation | |
308 | user.activate |
|
308 | user.activate | |
309 | user.last_login_on = Time.now |
|
309 | user.last_login_on = Time.now | |
310 | if user.save |
|
310 | if user.save | |
311 | self.logged_user = user |
|
311 | self.logged_user = user | |
312 | flash[:notice] = l(:notice_account_activated) |
|
312 | flash[:notice] = l(:notice_account_activated) | |
313 | redirect_to my_account_path |
|
313 | redirect_to my_account_path | |
314 | else |
|
314 | else | |
315 | yield if block_given? |
|
315 | yield if block_given? | |
316 | end |
|
316 | end | |
317 | end |
|
317 | end | |
318 |
|
318 | |||
319 | # Manual activation by the administrator |
|
319 | # Manual activation by the administrator | |
320 | # |
|
320 | # | |
321 | # Pass a block for behavior when a user fails to save |
|
321 | # Pass a block for behavior when a user fails to save | |
322 | def register_manually_by_administrator(user, &block) |
|
322 | def register_manually_by_administrator(user, &block) | |
323 | if user.save |
|
323 | if user.save | |
324 | # Sends an email to the administrators |
|
324 | # Sends an email to the administrators | |
325 | Mailer.account_activation_request(user).deliver |
|
325 | Mailer.account_activation_request(user).deliver | |
326 | account_pending(user) |
|
326 | account_pending(user) | |
327 | else |
|
327 | else | |
328 | yield if block_given? |
|
328 | yield if block_given? | |
329 | end |
|
329 | end | |
330 | end |
|
330 | end | |
331 |
|
331 | |||
332 | def handle_inactive_user(user, redirect_path=signin_path) |
|
332 | def handle_inactive_user(user, redirect_path=signin_path) | |
333 | if user.registered? |
|
333 | if user.registered? | |
334 | account_pending(user, redirect_path) |
|
334 | account_pending(user, redirect_path) | |
335 | else |
|
335 | else | |
336 | account_locked(user, redirect_path) |
|
336 | account_locked(user, redirect_path) | |
337 | end |
|
337 | end | |
338 | end |
|
338 | end | |
339 |
|
339 | |||
340 | def account_pending(user, redirect_path=signin_path) |
|
340 | def account_pending(user, redirect_path=signin_path) | |
341 | if Setting.self_registration == '1' |
|
341 | if Setting.self_registration == '1' | |
342 | flash[:error] = l(:notice_account_not_activated_yet, :url => activation_email_path) |
|
342 | flash[:error] = l(:notice_account_not_activated_yet, :url => activation_email_path) | |
343 | session[:registered_user_id] = user.id |
|
343 | session[:registered_user_id] = user.id | |
344 | else |
|
344 | else | |
345 | flash[:error] = l(:notice_account_pending) |
|
345 | flash[:error] = l(:notice_account_pending) | |
346 | end |
|
346 | end | |
347 | redirect_to redirect_path |
|
347 | redirect_to redirect_path | |
348 | end |
|
348 | end | |
349 |
|
349 | |||
350 | def account_locked(user, redirect_path=signin_path) |
|
350 | def account_locked(user, redirect_path=signin_path) | |
351 | flash[:error] = l(:notice_account_locked) |
|
351 | flash[:error] = l(:notice_account_locked) | |
352 | redirect_to redirect_path |
|
352 | redirect_to redirect_path | |
353 | end |
|
353 | end | |
354 | end |
|
354 | end |
@@ -1,84 +1,84 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 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 AdminController < ApplicationController |
|
18 | class AdminController < ApplicationController | |
19 | layout 'admin' |
|
19 | layout 'admin' | |
20 | menu_item :projects, :only => :projects |
|
20 | menu_item :projects, :only => :projects | |
21 | menu_item :plugins, :only => :plugins |
|
21 | menu_item :plugins, :only => :plugins | |
22 | menu_item :info, :only => :info |
|
22 | menu_item :info, :only => :info | |
23 |
|
23 | |||
24 | before_filter :require_admin |
|
24 | before_filter :require_admin | |
25 | helper :sort |
|
25 | helper :sort | |
26 | include SortHelper |
|
26 | include SortHelper | |
27 |
|
27 | |||
28 | def index |
|
28 | def index | |
29 | @no_configuration_data = Redmine::DefaultData::Loader::no_data? |
|
29 | @no_configuration_data = Redmine::DefaultData::Loader::no_data? | |
30 | end |
|
30 | end | |
31 |
|
31 | |||
32 | def projects |
|
32 | def projects | |
33 | @status = params[:status] || 1 |
|
33 | @status = params[:status] || 1 | |
34 |
|
34 | |||
35 | scope = Project.status(@status).sorted |
|
35 | scope = Project.status(@status).sorted | |
36 | scope = scope.like(params[:name]) if params[:name].present? |
|
36 | scope = scope.like(params[:name]) if params[:name].present? | |
37 | @projects = scope.to_a |
|
37 | @projects = scope.to_a | |
38 |
|
38 | |||
39 | render :action => "projects", :layout => false if request.xhr? |
|
39 | render :action => "projects", :layout => false if request.xhr? | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | def plugins |
|
42 | def plugins | |
43 | @plugins = Redmine::Plugin.all |
|
43 | @plugins = Redmine::Plugin.all | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | # Loads the default configuration |
|
46 | # Loads the default configuration | |
47 | # (roles, trackers, statuses, workflow, enumerations) |
|
47 | # (roles, trackers, statuses, workflow, enumerations) | |
48 | def default_configuration |
|
48 | def default_configuration | |
49 | if request.post? |
|
49 | if request.post? | |
50 | begin |
|
50 | begin | |
51 | Redmine::DefaultData::Loader::load(params[:lang]) |
|
51 | Redmine::DefaultData::Loader::load(params[:lang]) | |
52 | flash[:notice] = l(:notice_default_data_loaded) |
|
52 | flash[:notice] = l(:notice_default_data_loaded) | |
53 | rescue Exception => e |
|
53 | rescue Exception => e | |
54 | flash[:error] = l(:error_can_t_load_default_data, e.message) |
|
54 | flash[:error] = l(:error_can_t_load_default_data, ERB::Util.h(e.message)) | |
55 | end |
|
55 | end | |
56 | end |
|
56 | end | |
57 | redirect_to admin_path |
|
57 | redirect_to admin_path | |
58 | end |
|
58 | end | |
59 |
|
59 | |||
60 | def test_email |
|
60 | def test_email | |
61 | raise_delivery_errors = ActionMailer::Base.raise_delivery_errors |
|
61 | raise_delivery_errors = ActionMailer::Base.raise_delivery_errors | |
62 | # Force ActionMailer to raise delivery errors so we can catch it |
|
62 | # Force ActionMailer to raise delivery errors so we can catch it | |
63 | ActionMailer::Base.raise_delivery_errors = true |
|
63 | ActionMailer::Base.raise_delivery_errors = true | |
64 | begin |
|
64 | begin | |
65 | @test = Mailer.test_email(User.current).deliver |
|
65 | @test = Mailer.test_email(User.current).deliver | |
66 | flash[:notice] = l(:notice_email_sent, User.current.mail) |
|
66 | flash[:notice] = l(:notice_email_sent, ERB::Util.h(User.current.mail)) | |
67 | rescue Exception => e |
|
67 | rescue Exception => e | |
68 | flash[:error] = l(:notice_email_error, Redmine::CodesetUtil.replace_invalid_utf8(e.message.dup)) |
|
68 | flash[:error] = l(:notice_email_error, ERB::Util.h(Redmine::CodesetUtil.replace_invalid_utf8(e.message.dup))) | |
69 | end |
|
69 | end | |
70 | ActionMailer::Base.raise_delivery_errors = raise_delivery_errors |
|
70 | ActionMailer::Base.raise_delivery_errors = raise_delivery_errors | |
71 | redirect_to settings_path(:tab => 'notifications') |
|
71 | redirect_to settings_path(:tab => 'notifications') | |
72 | end |
|
72 | end | |
73 |
|
73 | |||
74 | def info |
|
74 | def info | |
75 | @db_adapter_name = ActiveRecord::Base.connection.adapter_name |
|
75 | @db_adapter_name = ActiveRecord::Base.connection.adapter_name | |
76 | @checklist = [ |
|
76 | @checklist = [ | |
77 | [:text_default_administrator_account_changed, User.default_admin_account_changed?], |
|
77 | [:text_default_administrator_account_changed, User.default_admin_account_changed?], | |
78 | [:text_file_repository_writable, File.writable?(Attachment.storage_path)], |
|
78 | [:text_file_repository_writable, File.writable?(Attachment.storage_path)], | |
79 | ["#{l :text_plugin_assets_writable} (./public/plugin_assets)", File.writable?(Redmine::Plugin.public_directory)], |
|
79 | ["#{l :text_plugin_assets_writable} (./public/plugin_assets)", File.writable?(Redmine::Plugin.public_directory)], | |
80 | [:text_rmagick_available, Object.const_defined?(:Magick)], |
|
80 | [:text_rmagick_available, Object.const_defined?(:Magick)], | |
81 | [:text_convert_available, Redmine::Thumbnail.convert_available?] |
|
81 | [:text_convert_available, Redmine::Thumbnail.convert_available?] | |
82 | ] |
|
82 | ] | |
83 | end |
|
83 | end | |
84 | end |
|
84 | end |
General Comments 0
You need to be logged in to leave comments.
Login now