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