summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-08-05 17:58:33 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-08-05 17:58:33 +0000
commitb764e398475c26217bcca8ac9063f053bc1cf627 (patch)
treef8c44b9b990ff60f3cf51fe65bb8dad9dae8bd35 /app
parentbd4fba08e5bec539a746e9be422b9c2baab51406 (diff)
downloadredmine-b764e398475c26217bcca8ac9063f053bc1cf627.tar.gz
redmine-b764e398475c26217bcca8ac9063f053bc1cf627.zip
Option to force a user to change his password (#3872).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12081 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/account_controller.rb2
-rw-r--r--app/controllers/application_controller.rb19
-rw-r--r--app/controllers/my_controller.rb11
-rw-r--r--app/models/user.rb5
-rw-r--r--app/views/my/password.html.erb4
-rw-r--r--app/views/users/_form.html.erb3
6 files changed, 38 insertions, 6 deletions
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index 7089c176f..d39fc2ace 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -20,7 +20,7 @@ class AccountController < ApplicationController
include CustomFieldsHelper
# prevents login action to be filtered by check_if_login_required application scope filter
- skip_before_filter :check_if_login_required
+ skip_before_filter :check_if_login_required, :check_password_change
# Login request and validation
def login
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index bb8dae56f..6e53ffe01 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -38,7 +38,7 @@ class ApplicationController < ActionController::Base
cookies.delete(autologin_cookie_name)
end
- before_filter :session_expiration, :user_setup, :check_if_login_required, :set_localization
+ before_filter :session_expiration, :user_setup, :check_if_login_required, :check_password_change, :set_localization
rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
rescue_from ::Unauthorized, :with => :deny_access
@@ -78,6 +78,9 @@ class ApplicationController < ActionController::Base
session[:user_id] = user.id
session[:ctime] = Time.now.utc.to_i
session[:atime] = Time.now.utc.to_i
+ if user.must_change_password?
+ session[:pwd] = '1'
+ end
end
def user_setup
@@ -112,6 +115,10 @@ class ApplicationController < ActionController::Base
authenticate_with_http_basic do |username, password|
user = User.try_to_login(username, password) || User.find_by_api_key(username)
end
+ if user && user.must_change_password?
+ render_error :message => 'You must change your password', :status => 403
+ return
+ end
end
# Switch user if requested by an admin user
if user && user.admin? && (username = api_switch_user_from_request)
@@ -170,6 +177,16 @@ class ApplicationController < ActionController::Base
require_login if Setting.login_required?
end
+ def check_password_change
+ if session[:pwd]
+ if User.current.must_change_password?
+ redirect_to my_password_path
+ else
+ session.delete(:pwd)
+ end
+ end
+ end
+
def set_localization
lang = nil
if User.current.logged?
diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb
index 5328991b3..82532918a 100644
--- a/app/controllers/my_controller.rb
+++ b/app/controllers/my_controller.rb
@@ -17,6 +17,8 @@
class MyController < ApplicationController
before_filter :require_login
+ # let user change his password when he has to
+ skip_before_filter :check_password_change, :only => :password
helper :issues
helper :users
@@ -90,14 +92,17 @@ class MyController < ApplicationController
return
end
if request.post?
- if @user.check_password?(params[:password])
+ if !@user.check_password?(params[:password])
+ flash.now[:error] = l(:notice_account_wrong_password)
+ elsif params[:password] == params[:new_password]
+ flash.now[:error] = 'Your new password must be different from your current password'
+ else
@user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
+ @user.must_change_passwd = false
if @user.save
flash[:notice] = l(:notice_account_password_updated)
redirect_to my_account_path
end
- else
- flash[:error] = l(:notice_account_wrong_password)
end
end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 441e6b5b8..9020295d0 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -280,6 +280,10 @@ class User < Principal
return auth_source.allow_password_changes?
end
+ def must_change_password?
+ must_change_passwd? && change_password_allowed?
+ end
+
def generate_password?
generate_password == '1' || generate_password == true
end
@@ -568,6 +572,7 @@ class User < Principal
safe_attributes 'status',
'auth_source_id',
'generate_password',
+ 'must_change_passwd',
:if => lambda {|user, current_user| current_user.admin?}
safe_attributes 'group_ids',
diff --git a/app/views/my/password.html.erb b/app/views/my/password.html.erb
index de9a459e4..5dbf24cb0 100644
--- a/app/views/my/password.html.erb
+++ b/app/views/my/password.html.erb
@@ -17,6 +17,10 @@
<%= submit_tag l(:button_apply) %>
<% end %>
+<% unless @user.must_change_passwd? %>
<% content_for :sidebar do %>
<%= render :partial => 'sidebar' %>
<% end %>
+<% end %>
+
+<%= javascript_tag "$('#password').focus();" %>
diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb
index 57c2f29b2..bb762c1ee 100644
--- a/app/views/users/_form.html.erb
+++ b/app/views/users/_form.html.erb
@@ -28,10 +28,11 @@
<p><%= f.select :auth_source_id, ([[l(:label_internal), ""]] + @auth_sources.collect { |a| [a.name, a.id] }), {}, :onchange => "if (this.value=='') {$('#password_fields').show();} else {$('#password_fields').hide();}" %></p>
<% end %>
<div id="password_fields" style="<%= 'display:none;' if @user.auth_source %>">
- <p><%= f.check_box :generate_password %></p>
<p><%= f.password_field :password, :required => true, :size => 25 %>
<em class="info"><%= l(:text_caracters_minimum, :count => Setting.password_min_length) %></em></p>
<p><%= f.password_field :password_confirmation, :required => true, :size => 25 %></p>
+ <p><%= f.check_box :generate_password %></p>
+ <p><%= f.check_box :must_change_passwd %></p>
</div>
</fieldset>
</div>