Chris@154: Chris@154:
Generated on Tue Jun 24 21:43:53 +0200 2008 with rcov 0.8.1.2 Chris@154:
Chris@154:Code reported as executed by Ruby looks like this... Chris@154: and this: this line is also marked as covered. Chris@154: Lines considered as run by rcov, but not reported by Ruby, look like this, Chris@154: and this: these lines were inferred by rcov (using simple heuristics). Chris@154: Finally, here's a line marked as not executed. Chris@154:Chris@154:
Name | Chris@154:Total lines | Chris@154:Lines of code | Chris@154:Total coverage | Chris@154:Code coverage | Chris@154:||||||||
app/controllers/account_controller.rb Chris@154: | Chris@154:173 Chris@154: | Chris@154:129 Chris@154: | Chris@154:
|
Chris@154:
|
Chris@154:
1 # redMine - project management software Chris@154: 2 # Copyright (C) 2006-2007 Jean-Philippe Lang Chris@154: 3 # Chris@154: 4 # This program is free software; you can redistribute it and/or Chris@154: 5 # modify it under the terms of the GNU General Public License Chris@154: 6 # as published by the Free Software Foundation; either version 2 Chris@154: 7 # of the License, or (at your option) any later version. Chris@154: 8 # Chris@154: 9 # This program is distributed in the hope that it will be useful, Chris@154: 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@154: 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@154: 12 # GNU General Public License for more details. Chris@154: 13 # Chris@154: 14 # You should have received a copy of the GNU General Public License Chris@154: 15 # along with this program; if not, write to the Free Software Chris@154: 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@154: 17 Chris@154: 18 class AccountController < ApplicationController Chris@154: 19 layout 'base' Chris@154: 20 helper :custom_fields Chris@154: 21 include CustomFieldsHelper Chris@154: 22 Chris@154: 23 # prevents login action to be filtered by check_if_login_required application scope filter Chris@154: 24 skip_before_filter :check_if_login_required, :only => [:login, :lost_password, :register, :activate] Chris@154: 25 Chris@154: 26 # Show user's account Chris@154: 27 def show Chris@154: 28 @user = User.find_active(params[:id]) Chris@154: 29 @custom_values = @user.custom_values.find(:all, :include => :custom_field) Chris@154: 30 Chris@154: 31 # show only public projects and private projects that the logged in user is also a member of Chris@154: 32 @memberships = @user.memberships.select do |membership| Chris@154: 33 membership.project.is_public? || (User.current.member_of?(membership.project)) Chris@154: 34 end Chris@154: 35 rescue ActiveRecord::RecordNotFound Chris@154: 36 render_404 Chris@154: 37 end Chris@154: 38 Chris@154: 39 # Login request and validation Chris@154: 40 def login Chris@154: 41 if request.get? Chris@154: 42 # Logout user Chris@154: 43 self.logged_user = nil Chris@154: 44 else Chris@154: 45 # Authenticate user Chris@154: 46 user = User.try_to_login(params[:username], params[:password]) Chris@154: 47 if user Chris@154: 48 self.logged_user = user Chris@154: 49 # generate a key and set cookie if autologin Chris@154: 50 if params[:autologin] && Setting.autologin? Chris@154: 51 token = Token.create(:user => user, :action => 'autologin') Chris@154: 52 cookies[:autologin] = { :value => token.value, :expires => 1.year.from_now } Chris@154: 53 end Chris@154: 54 redirect_back_or_default :controller => 'my', :action => 'page' Chris@154: 55 else Chris@154: 56 flash.now[:error] = l(:notice_account_invalid_creditentials) Chris@154: 57 end Chris@154: 58 end Chris@154: 59 rescue User::OnTheFlyCreationFailure Chris@154: 60 flash.now[:error] = 'Redmine could not retrieve the required information from the LDAP to create your account. Please, contact your Redmine administrator.' Chris@154: 61 end Chris@154: 62 Chris@154: 63 # Log out current user and redirect to welcome page Chris@154: 64 def logout Chris@154: 65 cookies.delete :autologin Chris@154: 66 Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin']) if User.current.logged? Chris@154: 67 self.logged_user = nil Chris@154: 68 redirect_to home_url Chris@154: 69 end Chris@154: 70 Chris@154: 71 # Enable user to choose a new password Chris@154: 72 def lost_password Chris@154: 73 redirect_to(home_url) && return unless Setting.lost_password? Chris@154: 74 if params[:token] Chris@154: 75 @token = Token.find_by_action_and_value("recovery", params[:token]) Chris@154: 76 redirect_to(home_url) && return unless @token and !@token.expired? Chris@154: 77 @user = @token.user Chris@154: 78 if request.post? Chris@154: 79 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] Chris@154: 80 if @user.save Chris@154: 81 @token.destroy Chris@154: 82 flash[:notice] = l(:notice_account_password_updated) Chris@154: 83 redirect_to :action => 'login' Chris@154: 84 return Chris@154: 85 end Chris@154: 86 end Chris@154: 87 render :template => "account/password_recovery" Chris@154: 88 return Chris@154: 89 else Chris@154: 90 if request.post? Chris@154: 91 user = User.find_by_mail(params[:mail]) Chris@154: 92 # user not found in db Chris@154: 93 flash.now[:error] = l(:notice_account_unknown_email) and return unless user Chris@154: 94 # user uses an external authentification Chris@154: 95 flash.now[:error] = l(:notice_can_t_change_password) and return if user.auth_source_id Chris@154: 96 # create a new token for password recovery Chris@154: 97 token = Token.new(:user => user, :action => "recovery") Chris@154: 98 if token.save Chris@154: 99 Mailer.deliver_lost_password(token) Chris@154: 100 flash[:notice] = l(:notice_account_lost_email_sent) Chris@154: 101 redirect_to :action => 'login' Chris@154: 102 return Chris@154: 103 end Chris@154: 104 end Chris@154: 105 end Chris@154: 106 end Chris@154: 107 Chris@154: 108 # User self-registration Chris@154: 109 def register Chris@154: 110 redirect_to(home_url) && return unless Setting.self_registration? Chris@154: 111 if request.get? Chris@154: 112 @user = User.new(:language => Setting.default_language) Chris@154: 113 else Chris@154: 114 @user = User.new(params[:user]) Chris@154: 115 @user.admin = false Chris@154: 116 @user.login = params[:user][:login] Chris@154: 117 @user.status = User::STATUS_REGISTERED Chris@154: 118 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] Chris@154: 119 case Setting.self_registration Chris@154: 120 when '1' Chris@154: 121 # Email activation Chris@154: 122 token = Token.new(:user => @user, :action => "register") Chris@154: 123 if @user.save and token.save Chris@154: 124 Mailer.deliver_register(token) Chris@154: 125 flash[:notice] = l(:notice_account_register_done) Chris@154: 126 redirect_to :action => 'login' Chris@154: 127 end Chris@154: 128 when '3' Chris@154: 129 # Automatic activation Chris@154: 130 @user.status = User::STATUS_ACTIVE Chris@154: 131 if @user.save Chris@154: 132 self.logged_user = @user Chris@154: 133 flash[:notice] = l(:notice_account_activated) Chris@154: 134 redirect_to :controller => 'my', :action => 'account' Chris@154: 135 end Chris@154: 136 else Chris@154: 137 # Manual activation by the administrator Chris@154: 138 if @user.save Chris@154: 139 # Sends an email to the administrators Chris@154: 140 Mailer.deliver_account_activation_request(@user) Chris@154: 141 flash[:notice] = l(:notice_account_pending) Chris@154: 142 redirect_to :action => 'login' Chris@154: 143 end Chris@154: 144 end Chris@154: 145 end Chris@154: 146 end Chris@154: 147 Chris@154: 148 # Token based account activation Chris@154: 149 def activate Chris@154: 150 redirect_to(home_url) && return unless Setting.self_registration? && params[:token] Chris@154: 151 token = Token.find_by_action_and_value('register', params[:token]) Chris@154: 152 redirect_to(home_url) && return unless token and !token.expired? Chris@154: 153 user = token.user Chris@154: 154 redirect_to(home_url) && return unless user.status == User::STATUS_REGISTERED Chris@154: 155 user.status = User::STATUS_ACTIVE Chris@154: 156 if user.save Chris@154: 157 token.destroy Chris@154: 158 flash[:notice] = l(:notice_account_activated) Chris@154: 159 end Chris@154: 160 redirect_to :action => 'login' Chris@154: 161 end Chris@154: 162 Chris@154: 163 private Chris@154: 164 def logged_user=(user) Chris@154: 165 if user && user.is_a?(User) Chris@154: 166 User.current = user Chris@154: 167 session[:user_id] = user.id Chris@154: 168 else Chris@154: 169 User.current = User.anonymous Chris@154: 170 session[:user_id] = nil Chris@154: 171 end Chris@154: 172 end Chris@154: 173 end Chris@154:
Generated using the rcov code coverage analysis tool for Ruby Chris@154: version 0.8.1.2.
Chris@154:
Chris@154:
Chris@154:
Chris@154:
Chris@154: