##// END OF EJS Templates
Code cleanup....
Jean-Philippe Lang -
r9758:6adf61fd02e5
parent child
Show More
@@ -1,15 +1,20
1 1 <h2><%=l(:label_password_lost)%></h2>
2 2
3 3 <%= error_messages_for 'user' %>
4 4
5 <%= form_tag({:token => @token.value}) do %>
6 <div class="box tabular">
7 <p><label for="new_password"><%=l(:field_new_password)%> <span class="required">*</span></label>
8 <%= password_field_tag 'new_password', nil, :size => 25 %>
9 <em class="info"><%= l(:text_caracters_minimum, :count => Setting.password_min_length) %></em></p>
5 <%= form_tag(lost_password_path) do %>
6 <%= hidden_field_tag 'token', @token.value %>
7 <div class="box tabular">
8 <p>
9 <label for="new_password"><%=l(:field_new_password)%> <span class="required">*</span></label>
10 <%= password_field_tag 'new_password', nil, :size => 25 %>
11 <em class="info"><%= l(:text_caracters_minimum, :count => Setting.password_min_length) %></em>
12 </p>
10 13
11 <p><label for="new_password_confirmation"><%=l(:field_password_confirmation)%> <span class="required">*</span></label>
12 <%= password_field_tag 'new_password_confirmation', nil, :size => 25 %></p>
13 </div>
14 <p><%= submit_tag l(:button_save) %></p>
14 <p>
15 <label for="new_password_confirmation"><%=l(:field_password_confirmation)%> <span class="required">*</span></label>
16 <%= password_field_tag 'new_password_confirmation', nil, :size => 25 %>
17 </p>
18 </div>
19 <p><%= submit_tag l(:button_save) %></p>
15 20 <% end %>
@@ -1,183 +1,187
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 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 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 begin
21 21 require 'mocha'
22 22 rescue
23 23 # Won't run some tests
24 24 end
25 25
26 26 class AccountTest < ActionController::IntegrationTest
27 27 fixtures :users, :roles
28 28
29 29 # Replace this with your real tests.
30 30 def test_login
31 31 get "my/page"
32 32 assert_redirected_to "/login?back_url=http%3A%2F%2Fwww.example.com%2Fmy%2Fpage"
33 33 log_user('jsmith', 'jsmith')
34 34
35 35 get "my/account"
36 36 assert_response :success
37 37 assert_template "my/account"
38 38 end
39 39
40 40 def test_autologin
41 41 user = User.find(1)
42 42 Setting.autologin = "7"
43 43 Token.delete_all
44 44
45 45 # User logs in with 'autologin' checked
46 46 post '/login', :username => user.login, :password => 'admin', :autologin => 1
47 47 assert_redirected_to '/my/page'
48 48 token = Token.find :first
49 49 assert_not_nil token
50 50 assert_equal user, token.user
51 51 assert_equal 'autologin', token.action
52 52 assert_equal user.id, session[:user_id]
53 53 assert_equal token.value, cookies['autologin']
54 54
55 55 # Session is cleared
56 56 reset!
57 57 User.current = nil
58 58 # Clears user's last login timestamp
59 59 user.update_attribute :last_login_on, nil
60 60 assert_nil user.reload.last_login_on
61 61
62 62 # User comes back with his autologin cookie
63 63 cookies[:autologin] = token.value
64 64 get '/my/page'
65 65 assert_response :success
66 66 assert_template 'my/page'
67 67 assert_equal user.id, session[:user_id]
68 68 assert_not_nil user.reload.last_login_on
69 69 seconds_ago = 10.second.ago.utc
70 70 assert user.last_login_on.utc > 10.second.ago.utc, "#{user.last_login_on.utc} was not > #{seconds_ago}"
71 71 end
72 72
73 73 def test_lost_password
74 74 Token.delete_all
75 75
76 76 get "account/lost_password"
77 77 assert_response :success
78 78 assert_template "account/lost_password"
79 assert_select 'input[name=mail]'
79 80
80 81 post "account/lost_password", :mail => 'jSmith@somenet.foo'
81 82 assert_redirected_to "/login"
82 83
83 84 token = Token.find(:first)
84 85 assert_equal 'recovery', token.action
85 86 assert_equal 'jsmith@somenet.foo', token.user.mail
86 87 assert !token.expired?
87 88
88 89 get "account/lost_password", :token => token.value
89 90 assert_response :success
90 91 assert_template "account/password_recovery"
92 assert_select 'input[type=hidden][name=token][value=?]', token.value
93 assert_select 'input[name=new_password]'
94 assert_select 'input[name=new_password_confirmation]'
91 95
92 96 post "account/lost_password", :token => token.value, :new_password => 'newpass', :new_password_confirmation => 'newpass'
93 97 assert_redirected_to "/login"
94 98 assert_equal 'Password was successfully updated.', flash[:notice]
95 99
96 100 log_user('jsmith', 'newpass')
97 101 assert_equal 0, Token.count
98 102 end
99 103
100 104 def test_register_with_automatic_activation
101 105 Setting.self_registration = '3'
102 106
103 107 get 'account/register'
104 108 assert_response :success
105 109 assert_template 'account/register'
106 110
107 111 post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
108 112 :password => "newpass", :password_confirmation => "newpass"}
109 113 assert_redirected_to '/my/account'
110 114 follow_redirect!
111 115 assert_response :success
112 116 assert_template 'my/account'
113 117
114 118 user = User.find_by_login('newuser')
115 119 assert_not_nil user
116 120 assert user.active?
117 121 assert_not_nil user.last_login_on
118 122 end
119 123
120 124 def test_register_with_manual_activation
121 125 Setting.self_registration = '2'
122 126
123 127 post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
124 128 :password => "newpass", :password_confirmation => "newpass"}
125 129 assert_redirected_to '/login'
126 130 assert !User.find_by_login('newuser').active?
127 131 end
128 132
129 133 def test_register_with_email_activation
130 134 Setting.self_registration = '1'
131 135 Token.delete_all
132 136
133 137 post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
134 138 :password => "newpass", :password_confirmation => "newpass"}
135 139 assert_redirected_to '/login'
136 140 assert !User.find_by_login('newuser').active?
137 141
138 142 token = Token.find(:first)
139 143 assert_equal 'register', token.action
140 144 assert_equal 'newuser@foo.bar', token.user.mail
141 145 assert !token.expired?
142 146
143 147 get 'account/activate', :token => token.value
144 148 assert_redirected_to '/login'
145 149 log_user('newuser', 'newpass')
146 150 end
147 151
148 152 def test_onthefly_registration
149 153 # disable registration
150 154 Setting.self_registration = '0'
151 155 AuthSource.expects(:authenticate).returns({:login => 'foo', :firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com', :auth_source_id => 66})
152 156
153 157 post '/login', :username => 'foo', :password => 'bar'
154 158 assert_redirected_to '/my/page'
155 159
156 160 user = User.find_by_login('foo')
157 161 assert user.is_a?(User)
158 162 assert_equal 66, user.auth_source_id
159 163 assert user.hashed_password.blank?
160 164 end
161 165
162 166 def test_onthefly_registration_with_invalid_attributes
163 167 # disable registration
164 168 Setting.self_registration = '0'
165 169 AuthSource.expects(:authenticate).returns({:login => 'foo', :lastname => 'Smith', :auth_source_id => 66})
166 170
167 171 post '/login', :username => 'foo', :password => 'bar'
168 172 assert_response :success
169 173 assert_template 'account/register'
170 174 assert_tag :input, :attributes => { :name => 'user[firstname]', :value => '' }
171 175 assert_tag :input, :attributes => { :name => 'user[lastname]', :value => 'Smith' }
172 176 assert_no_tag :input, :attributes => { :name => 'user[login]' }
173 177 assert_no_tag :input, :attributes => { :name => 'user[password]' }
174 178
175 179 post 'account/register', :user => {:firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com'}
176 180 assert_redirected_to '/my/account'
177 181
178 182 user = User.find_by_login('foo')
179 183 assert user.is_a?(User)
180 184 assert_equal 66, user.auth_source_id
181 185 assert user.hashed_password.blank?
182 186 end
183 187 end
General Comments 0
You need to be logged in to leave comments. Login now