##// END OF EJS Templates
lost_password option checking in account controller...
Jean-Philippe Lang -
r233:d185e2f9e015
parent child
Show More
@@ -1,130 +1,131
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class AccountController < ApplicationController
19 19 layout 'base'
20 20 helper :custom_fields
21 21 include CustomFieldsHelper
22 22
23 23 # prevents login action to be filtered by check_if_login_required application scope filter
24 24 skip_before_filter :check_if_login_required, :only => [:login, :lost_password, :register]
25 before_filter :require_login, :except => [:show, :login, :lost_password, :register]
25 before_filter :require_login, :only => :logout
26 26
27 27 # Show user's account
28 28 def show
29 29 @user = User.find(params[:id])
30 30 @custom_values = @user.custom_values.find(:all, :include => :custom_field)
31 31 rescue ActiveRecord::RecordNotFound
32 32 render_404
33 33 end
34 34
35 35 # Login request and validation
36 36 def login
37 37 if request.get?
38 38 # Logout user
39 39 self.logged_in_user = nil
40 40 else
41 41 # Authenticate user
42 42 user = User.try_to_login(params[:login], params[:password])
43 43 if user
44 44 self.logged_in_user = user
45 45 redirect_back_or_default :controller => 'my', :action => 'page'
46 46 else
47 47 flash.now[:notice] = l(:notice_account_invalid_creditentials)
48 48 end
49 49 end
50 50 end
51 51
52 52 # Log out current user and redirect to welcome page
53 53 def logout
54 54 self.logged_in_user = nil
55 55 redirect_to :controller => 'welcome'
56 56 end
57 57
58 58 # Enable user to choose a new password
59 59 def lost_password
60 redirect_to :controller => 'welcome' and return unless Setting.lost_password?
60 61 if params[:token]
61 62 @token = Token.find_by_action_and_value("recovery", params[:token])
62 63 redirect_to :controller => 'welcome' and return unless @token and !@token.expired?
63 64 @user = @token.user
64 65 if request.post?
65 66 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
66 67 if @user.save
67 68 @token.destroy
68 69 flash[:notice] = l(:notice_account_password_updated)
69 70 redirect_to :action => 'login'
70 71 return
71 72 end
72 73 end
73 74 render :template => "account/password_recovery"
74 75 return
75 76 else
76 77 if request.post?
77 78 user = User.find_by_mail(params[:mail])
78 79 # user not found in db
79 80 flash.now[:notice] = l(:notice_account_unknown_email) and return unless user
80 81 # user uses an external authentification
81 82 flash.now[:notice] = l(:notice_can_t_change_password) and return if user.auth_source_id
82 83 # create a new token for password recovery
83 84 token = Token.new(:user => user, :action => "recovery")
84 85 if token.save
85 86 Mailer.deliver_lost_password(token)
86 87 flash[:notice] = l(:notice_account_lost_email_sent)
87 88 redirect_to :action => 'login'
88 89 return
89 90 end
90 91 end
91 92 end
92 93 end
93 94
94 95 # User self-registration
95 96 def register
96 97 redirect_to :controller => 'welcome' and return unless Setting.self_registration?
97 98 if params[:token]
98 99 token = Token.find_by_action_and_value("register", params[:token])
99 100 redirect_to :controller => 'welcome' and return unless token and !token.expired?
100 101 user = token.user
101 102 redirect_to :controller => 'welcome' and return unless user.status == User::STATUS_REGISTERED
102 103 user.status = User::STATUS_ACTIVE
103 104 if user.save
104 105 token.destroy
105 106 flash[:notice] = l(:notice_account_activated)
106 107 redirect_to :action => 'login'
107 108 return
108 109 end
109 110 else
110 111 if request.get?
111 112 @user = User.new(:language => Setting.default_language)
112 113 @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
113 114 else
114 115 @user = User.new(params[:user])
115 116 @user.admin = false
116 117 @user.login = params[:user][:login]
117 118 @user.status = User::STATUS_REGISTERED
118 119 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
119 120 @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
120 121 @user.custom_values = @custom_values
121 122 token = Token.new(:user => @user, :action => "register")
122 123 if @user.save and token.save
123 124 Mailer.deliver_register(token)
124 125 flash[:notice] = l(:notice_account_register_done)
125 126 redirect_to :controller => 'welcome' and return
126 127 end
127 128 end
128 129 end
129 130 end
130 131 end
General Comments 0
You need to be logged in to leave comments. Login now