| 
									
										
										
										
											2008-11-30 11:18:22 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							| 
									
										
										
										
											2012-05-05 12:56:53 +00:00
										 |  |  | # Copyright (C) 2006-2012  Jean-Philippe Lang | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | # modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | # as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  | # of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2011-08-31 12:08:29 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | # GNU General Public License for more details. | 
					
						
							| 
									
										
										
										
											2011-08-31 12:08:29 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | # along with this program; if not, write to the Free Software | 
					
						
							|  |  |  | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class AccountController < ApplicationController | 
					
						
							|  |  |  |   helper :custom_fields | 
					
						
							| 
									
										
										
										
											2011-08-31 12:08:29 +00:00
										 |  |  |   include CustomFieldsHelper | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |   # prevents login action to be filtered by check_if_login_required application scope filter | 
					
						
							| 
									
										
										
										
											2009-10-29 18:37:00 +00:00
										 |  |  |   skip_before_filter :check_if_login_required | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   # Login request and validation | 
					
						
							|  |  |  |   def login | 
					
						
							|  |  |  |     if request.get? | 
					
						
							| 
									
										
										
										
											2010-03-04 05:33:49 +00:00
										 |  |  |       logout_user | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2010-03-04 05:33:54 +00:00
										 |  |  |       authenticate_user | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-02-19 18:13:46 +00:00
										 |  |  |   rescue AuthSourceException => e | 
					
						
							|  |  |  |     logger.error "An error occured when authenticating #{params[:username]}: #{e.message}" | 
					
						
							|  |  |  |     render_error :message => e.message | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # Log out current user and redirect to welcome page | 
					
						
							|  |  |  |   def logout | 
					
						
							| 
									
										
										
										
											2010-03-04 05:33:49 +00:00
										 |  |  |     logout_user | 
					
						
							| 
									
										
										
										
											2007-09-24 18:38:45 +00:00
										 |  |  |     redirect_to home_url | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:08:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 18:05:32 +00:00
										 |  |  |   # Lets user choose a new password | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |   def lost_password | 
					
						
							| 
									
										
										
										
											2007-09-24 18:38:45 +00:00
										 |  |  |     redirect_to(home_url) && return unless Setting.lost_password? | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |     if params[:token] | 
					
						
							| 
									
										
										
										
											2012-07-07 18:05:32 +00:00
										 |  |  |       @token = Token.find_by_action_and_value("recovery", params[:token].to_s) | 
					
						
							|  |  |  |       if @token.nil? || @token.expired? | 
					
						
							|  |  |  |         redirect_to home_url | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |       @user = @token.user | 
					
						
							| 
									
										
										
										
											2012-07-08 07:36:58 +00:00
										 |  |  |       unless @user && @user.active? | 
					
						
							|  |  |  |         redirect_to home_url | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |       if request.post? | 
					
						
							|  |  |  |         @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] | 
					
						
							|  |  |  |         if @user.save | 
					
						
							|  |  |  |           @token.destroy | 
					
						
							|  |  |  |           flash[:notice] = l(:notice_account_password_updated) | 
					
						
							| 
									
										
										
										
											2012-07-07 18:05:32 +00:00
										 |  |  |           redirect_to signin_path | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |           return | 
					
						
							| 
									
										
										
										
											2011-08-31 12:08:29 +00:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |       render :template => "account/password_recovery" | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       if request.post? | 
					
						
							| 
									
										
										
										
											2012-07-07 18:27:34 +00:00
										 |  |  |         user = User.find_by_mail(params[:mail].to_s) | 
					
						
							|  |  |  |         # user not found or not active | 
					
						
							|  |  |  |         unless user && user.active? | 
					
						
							|  |  |  |           flash.now[:error] = l(:notice_account_unknown_email) | 
					
						
							|  |  |  |           return | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |         # user cannot change its password | 
					
						
							|  |  |  |         unless user.change_password_allowed? | 
					
						
							|  |  |  |           flash.now[:error] = l(:notice_can_t_change_password) | 
					
						
							|  |  |  |           return | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |         # create a new token for password recovery | 
					
						
							|  |  |  |         token = Token.new(:user => user, :action => "recovery") | 
					
						
							|  |  |  |         if token.save | 
					
						
							| 
									
										
										
										
											2012-05-05 13:07:12 +00:00
										 |  |  |           Mailer.lost_password(token).deliver | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |           flash[:notice] = l(:notice_account_lost_email_sent) | 
					
						
							| 
									
										
										
										
											2012-07-07 17:45:12 +00:00
										 |  |  |           redirect_to signin_path | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |           return | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:08:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |   # User self-registration | 
					
						
							|  |  |  |   def register | 
					
						
							| 
									
										
										
										
											2008-07-19 10:47:19 +00:00
										 |  |  |     redirect_to(home_url) && return unless Setting.self_registration? || session[:auth_source_registration] | 
					
						
							| 
									
										
										
										
											2007-11-18 17:46:55 +00:00
										 |  |  |     if request.get? | 
					
						
							| 
									
										
										
										
											2008-07-19 10:47:19 +00:00
										 |  |  |       session[:auth_source_registration] = nil | 
					
						
							| 
									
										
										
										
											2007-11-18 17:46:55 +00:00
										 |  |  |       @user = User.new(:language => Setting.default_language) | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2012-07-07 06:22:35 +00:00
										 |  |  |       user_params = params[:user] || {} | 
					
						
							| 
									
										
										
										
											2012-02-05 12:21:21 +00:00
										 |  |  |       @user = User.new | 
					
						
							| 
									
										
										
										
											2012-07-07 06:22:35 +00:00
										 |  |  |       @user.safe_attributes = user_params | 
					
						
							| 
									
										
										
										
											2007-11-18 17:46:55 +00:00
										 |  |  |       @user.admin = false | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:50 +00:00
										 |  |  |       @user.register | 
					
						
							| 
									
										
										
										
											2008-07-19 10:47:19 +00:00
										 |  |  |       if session[:auth_source_registration] | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:50 +00:00
										 |  |  |         @user.activate | 
					
						
							| 
									
										
										
										
											2008-07-19 10:47:19 +00:00
										 |  |  |         @user.login = session[:auth_source_registration][:login] | 
					
						
							|  |  |  |         @user.auth_source_id = session[:auth_source_registration][:auth_source_id] | 
					
						
							| 
									
										
										
										
											2007-11-18 17:46:55 +00:00
										 |  |  |         if @user.save | 
					
						
							| 
									
										
										
										
											2008-07-19 10:47:19 +00:00
										 |  |  |           session[:auth_source_registration] = nil | 
					
						
							| 
									
										
										
										
											2008-06-09 18:59:15 +00:00
										 |  |  |           self.logged_user = @user | 
					
						
							| 
									
										
										
										
											2007-11-18 17:46:55 +00:00
										 |  |  |           flash[:notice] = l(:notice_account_activated) | 
					
						
							| 
									
										
										
										
											2008-06-09 18:59:15 +00:00
										 |  |  |           redirect_to :controller => 'my', :action => 'account' | 
					
						
							| 
									
										
										
										
											2007-11-18 17:46:55 +00:00
										 |  |  |         end | 
					
						
							|  |  |  |       else | 
					
						
							| 
									
										
										
										
											2008-07-19 10:47:19 +00:00
										 |  |  |         @user.login = params[:user][:login] | 
					
						
							| 
									
										
										
										
											2012-07-07 06:22:35 +00:00
										 |  |  |         unless user_params[:identity_url].present? && user_params[:password].blank? && user_params[:password_confirmation].blank? | 
					
						
							|  |  |  |           @user.password, @user.password_confirmation = user_params[:password], user_params[:password_confirmation] | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-19 10:47:19 +00:00
										 |  |  |         case Setting.self_registration | 
					
						
							|  |  |  |         when '1' | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:34 +00:00
										 |  |  |           register_by_email_activation(@user) | 
					
						
							| 
									
										
										
										
											2008-07-19 10:47:19 +00:00
										 |  |  |         when '3' | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:34 +00:00
										 |  |  |           register_automatically(@user) | 
					
						
							| 
									
										
										
										
											2008-07-19 10:47:19 +00:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:34 +00:00
										 |  |  |           register_manually_by_administrator(@user) | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:08:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-18 17:46:55 +00:00
										 |  |  |   # Token based account activation | 
					
						
							|  |  |  |   def activate | 
					
						
							|  |  |  |     redirect_to(home_url) && return unless Setting.self_registration? && params[:token] | 
					
						
							|  |  |  |     token = Token.find_by_action_and_value('register', params[:token]) | 
					
						
							|  |  |  |     redirect_to(home_url) && return unless token and !token.expired? | 
					
						
							|  |  |  |     user = token.user | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:50 +00:00
										 |  |  |     redirect_to(home_url) && return unless user.registered? | 
					
						
							|  |  |  |     user.activate | 
					
						
							| 
									
										
										
										
											2007-11-18 17:46:55 +00:00
										 |  |  |     if user.save | 
					
						
							|  |  |  |       token.destroy | 
					
						
							|  |  |  |       flash[:notice] = l(:notice_account_activated) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-07-07 17:45:12 +00:00
										 |  |  |     redirect_to signin_path | 
					
						
							| 
									
										
										
										
											2007-11-18 17:46:55 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:08:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-25 14:59:33 +00:00
										 |  |  |   private | 
					
						
							| 
									
										
										
										
											2011-08-31 12:08:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-04 05:33:54 +00:00
										 |  |  |   def authenticate_user | 
					
						
							|  |  |  |     if Setting.openid? && using_open_id? | 
					
						
							|  |  |  |       open_id_authenticate(params[:openid_url]) | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       password_authentication | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:07 +00:00
										 |  |  |   def password_authentication | 
					
						
							|  |  |  |     user = User.try_to_login(params[:username], params[:password]) | 
					
						
							| 
									
										
										
										
											2009-12-21 02:24:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:07 +00:00
										 |  |  |     if user.nil? | 
					
						
							| 
									
										
										
										
											2009-12-21 02:24:44 +00:00
										 |  |  |       invalid_credentials | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:07 +00:00
										 |  |  |     elsif user.new_record? | 
					
						
							| 
									
										
										
										
											2009-12-20 20:13:50 +00:00
										 |  |  |       onthefly_creation_failed(user, {:login => user.login, :auth_source_id => user.auth_source_id }) | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:07 +00:00
										 |  |  |     else | 
					
						
							|  |  |  |       # Valid user | 
					
						
							|  |  |  |       successful_authentication(user) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def open_id_authenticate(openid_url) | 
					
						
							| 
									
										
										
										
											2012-04-29 08:48:50 +00:00
										 |  |  |     authenticate_with_open_id(openid_url, :required => [:nickname, :fullname, :email], :return_to => signin_url, :method => :post) do |result, identity_url, registration| | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:07 +00:00
										 |  |  |       if result.successful? | 
					
						
							|  |  |  |         user = User.find_or_initialize_by_identity_url(identity_url) | 
					
						
							|  |  |  |         if user.new_record? | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:41 +00:00
										 |  |  |           # Self-registration off | 
					
						
							|  |  |  |           redirect_to(home_url) && return unless Setting.self_registration? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:07 +00:00
										 |  |  |           # Create on the fly | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:23 +00:00
										 |  |  |           user.login = registration['nickname'] unless registration['nickname'].nil? | 
					
						
							|  |  |  |           user.mail = registration['email'] unless registration['email'].nil? | 
					
						
							|  |  |  |           user.firstname, user.lastname = registration['fullname'].split(' ') unless registration['fullname'].nil? | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:12 +00:00
										 |  |  |           user.random_password | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:50 +00:00
										 |  |  |           user.register | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |           case Setting.self_registration | 
					
						
							|  |  |  |           when '1' | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:34 +00:00
										 |  |  |             register_by_email_activation(user) do | 
					
						
							| 
									
										
										
										
											2009-02-20 00:31:50 +00:00
										 |  |  |               onthefly_creation_failed(user) | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:28 +00:00
										 |  |  |             end | 
					
						
							|  |  |  |           when '3' | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:34 +00:00
										 |  |  |             register_automatically(user) do | 
					
						
							| 
									
										
										
										
											2009-02-20 00:31:50 +00:00
										 |  |  |               onthefly_creation_failed(user) | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:28 +00:00
										 |  |  |             end | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:12 +00:00
										 |  |  |           else | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:34 +00:00
										 |  |  |             register_manually_by_administrator(user) do | 
					
						
							| 
									
										
										
										
											2009-02-20 00:31:50 +00:00
										 |  |  |               onthefly_creation_failed(user) | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:28 +00:00
										 |  |  |             end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:08:29 +00:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:07 +00:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:12 +00:00
										 |  |  |           # Existing record | 
					
						
							| 
									
										
										
										
											2009-02-20 00:16:45 +00:00
										 |  |  |           if user.active? | 
					
						
							|  |  |  |             successful_authentication(user) | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             account_pending | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:07 +00:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:08:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:07 +00:00
										 |  |  |   def successful_authentication(user) | 
					
						
							| 
									
										
										
										
											2012-08-07 19:50:18 +00:00
										 |  |  |     logger.info "Successful authentication for '#{user.login}' from #{request.remote_ip} at #{Time.now.utc}" | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:07 +00:00
										 |  |  |     # Valid user | 
					
						
							|  |  |  |     self.logged_user = user | 
					
						
							|  |  |  |     # generate a key and set cookie if autologin | 
					
						
							|  |  |  |     if params[:autologin] && Setting.autologin? | 
					
						
							| 
									
										
										
										
											2011-01-23 11:20:46 +00:00
										 |  |  |       set_autologin_cookie(user) | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:07 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2009-03-20 23:52:42 +00:00
										 |  |  |     call_hook(:controller_account_success_authentication_after, {:user => user }) | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:07 +00:00
										 |  |  |     redirect_back_or_default :controller => 'my', :action => 'page' | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:08:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-23 11:20:46 +00:00
										 |  |  |   def set_autologin_cookie(user) | 
					
						
							|  |  |  |     token = Token.create(:user => user, :action => 'autologin') | 
					
						
							|  |  |  |     cookie_name = Redmine::Configuration['autologin_cookie_name'] || 'autologin' | 
					
						
							|  |  |  |     cookie_options = { | 
					
						
							|  |  |  |       :value => token.value, | 
					
						
							|  |  |  |       :expires => 1.year.from_now, | 
					
						
							|  |  |  |       :path => (Redmine::Configuration['autologin_cookie_path'] || '/'), | 
					
						
							| 
									
										
										
										
											2011-01-23 11:40:07 +00:00
										 |  |  |       :secure => (Redmine::Configuration['autologin_cookie_secure'] ? true : false), | 
					
						
							|  |  |  |       :httponly => true | 
					
						
							| 
									
										
										
										
											2011-01-23 11:20:46 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     cookies[cookie_name] = cookie_options | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:28 +00:00
										 |  |  |   # Onthefly creation failed, display the registration form to fill/fix attributes | 
					
						
							|  |  |  |   def onthefly_creation_failed(user, auth_source_options = { }) | 
					
						
							|  |  |  |     @user = user | 
					
						
							|  |  |  |     session[:auth_source_registration] = auth_source_options unless auth_source_options.empty? | 
					
						
							| 
									
										
										
										
											2012-09-17 18:31:20 +00:00
										 |  |  |     render :action => 'register' | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:28 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-21 02:24:44 +00:00
										 |  |  |   def invalid_credentials | 
					
						
							| 
									
										
										
										
											2010-02-11 18:25:38 +00:00
										 |  |  |     logger.warn "Failed login for '#{params[:username]}' from #{request.remote_ip} at #{Time.now.utc}" | 
					
						
							| 
									
										
										
										
											2009-12-21 02:24:44 +00:00
										 |  |  |     flash.now[:error] = l(:notice_account_invalid_creditentials) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:34 +00:00
										 |  |  |   # Register a user for email activation. | 
					
						
							|  |  |  |   # | 
					
						
							|  |  |  |   # Pass a block for behavior when a user fails to save | 
					
						
							|  |  |  |   def register_by_email_activation(user, &block) | 
					
						
							|  |  |  |     token = Token.new(:user => user, :action => "register") | 
					
						
							|  |  |  |     if user.save and token.save | 
					
						
							| 
									
										
										
										
											2012-05-05 13:07:12 +00:00
										 |  |  |       Mailer.register(token).deliver | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:34 +00:00
										 |  |  |       flash[:notice] = l(:notice_account_register_done) | 
					
						
							| 
									
										
										
										
											2012-07-07 17:45:12 +00:00
										 |  |  |       redirect_to signin_path | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:34 +00:00
										 |  |  |     else | 
					
						
							|  |  |  |       yield if block_given? | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:08:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:34 +00:00
										 |  |  |   # Automatically register a user | 
					
						
							|  |  |  |   # | 
					
						
							|  |  |  |   # Pass a block for behavior when a user fails to save | 
					
						
							|  |  |  |   def register_automatically(user, &block) | 
					
						
							|  |  |  |     # Automatic activation | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:50 +00:00
										 |  |  |     user.activate | 
					
						
							| 
									
										
										
										
											2009-03-15 10:49:18 +00:00
										 |  |  |     user.last_login_on = Time.now | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:34 +00:00
										 |  |  |     if user.save | 
					
						
							|  |  |  |       self.logged_user = user | 
					
						
							|  |  |  |       flash[:notice] = l(:notice_account_activated) | 
					
						
							|  |  |  |       redirect_to :controller => 'my', :action => 'account' | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       yield if block_given? | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:08:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:34 +00:00
										 |  |  |   # Manual activation by the administrator | 
					
						
							|  |  |  |   # | 
					
						
							|  |  |  |   # Pass a block for behavior when a user fails to save | 
					
						
							|  |  |  |   def register_manually_by_administrator(user, &block) | 
					
						
							|  |  |  |     if user.save | 
					
						
							|  |  |  |       # Sends an email to the administrators | 
					
						
							| 
									
										
										
										
											2012-05-05 13:07:12 +00:00
										 |  |  |       Mailer.account_activation_request(user).deliver | 
					
						
							| 
									
										
										
										
											2009-02-20 00:16:45 +00:00
										 |  |  |       account_pending | 
					
						
							| 
									
										
										
										
											2009-02-11 19:07:34 +00:00
										 |  |  |     else | 
					
						
							|  |  |  |       yield if block_given? | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-02-20 00:16:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def account_pending | 
					
						
							|  |  |  |     flash[:notice] = l(:notice_account_pending) | 
					
						
							| 
									
										
										
										
											2012-07-07 17:45:12 +00:00
										 |  |  |     redirect_to signin_path | 
					
						
							| 
									
										
										
										
											2009-02-20 00:16:45 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  | end |