Adds a way for a registered user to get a new action email (#14228).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11946 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
1 parent
ec46d4315c
commit
4bd874ab46
7 files changed
+144
-13
No files matched your search
@@ -75,11 +75,15 @@ class AccountController < ApplicationController
|
||||
else
|
||||
if request.post?
|
||||
user = User.find_by_mail(params[:mail].to_s)
|
||||
# user not found or not active
|
||||
unless user && user.active?
|
||||
# user not found
|
||||
unless user
|
||||
flash.now[:error] = l(:notice_account_unknown_email)
|
||||
return
|
||||
end
|
||||
unless user.active?
|
||||
handle_inactive_user(user, lost_password_path)
|
||||
return
|
||||
end
|
||||
# user cannot change its password
|
||||
unless user.change_password_allowed?
|
||||
flash.now[:error] = l(:notice_can_t_change_password)
|
||||
@@ -152,6 +156,19 @@ class AccountController < ApplicationController
|
||||
redirect_to signin_path
|
||||
end
|
||||
|
||||
# Sends a new account activation email
|
||||
def activation_email
|
||||
if session[:registered_user_id] && Setting.self_registration == '1'
|
||||
user_id = session.delete(:registered_user_id).to_i
|
||||
user = User.find_by_id(user_id)
|
||||
if user && user.registered?
|
||||
register_by_email_activation(user)
|
||||
return
|
||||
end
|
||||
end
|
||||
redirect_to(home_url)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def authenticate_user
|
||||
@@ -163,7 +180,7 @@ class AccountController < ApplicationController
|
||||
end
|
||||
|
||||
def password_authentication
|
||||
user = User.try_to_login(params[:username], params[:password])
|
||||
user = User.try_to_login(params[:username], params[:password], false)
|
||||
|
||||
if user.nil?
|
||||
invalid_credentials
|
||||
@@ -171,7 +188,11 @@ class AccountController < ApplicationController
|
||||
onthefly_creation_failed(user, {:login => user.login, :auth_source_id => user.auth_source_id })
|
||||
else
|
||||
# Valid user
|
||||
successful_authentication(user)
|
||||
if user.active?
|
||||
successful_authentication(user)
|
||||
else
|
||||
handle_inactive_user(user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -211,7 +232,7 @@ class AccountController < ApplicationController
|
||||
if user.active?
|
||||
successful_authentication(user)
|
||||
else
|
||||
account_pending
|
||||
handle_inactive_user(user)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -291,14 +312,32 @@ class AccountController < ApplicationController
|
||||
if user.save
|
||||
# Sends an email to the administrators
|
||||
Mailer.account_activation_request(user).deliver
|
||||
account_pending
|
||||
account_pending(user)
|
||||
else
|
||||
yield if block_given?
|
||||
end
|
||||
end
|
||||
|
||||
def account_pending
|
||||
flash[:notice] = l(:notice_account_pending)
|
||||
redirect_to signin_path
|
||||
def handle_inactive_user(user, redirect_path=signin_path)
|
||||
if user.registered?
|
||||
account_pending(user, redirect_path)
|
||||
else
|
||||
account_locked(user, redirect_path)
|
||||
end
|
||||
end
|
||||
|
||||
def account_pending(user, redirect_path=signin_path)
|
||||
if Setting.self_registration == '1'
|
||||
flash[:error] = l(:notice_account_not_activated_yet, :url => activation_email_path)
|
||||
session[:registered_user_id] = user.id
|
||||
else
|
||||
flash[:error] = l(:notice_account_pending)
|
||||
end
|
||||
redirect_to redirect_path
|
||||
end
|
||||
|
||||
def account_locked(user, redirect_path=signin_path)
|
||||
flash[:error] = l(:notice_account_locked)
|
||||
redirect_to redirect_path
|
||||
end
|
||||
end
|
||||
+3
-3
@@ -157,7 +157,7 @@ class User < Principal
|
||||
end
|
||||
|
||||
# Returns the user that matches provided login and password, or nil
|
||||
def self.try_to_login(login, password)
|
||||
def self.try_to_login(login, password, active_only=true)
|
||||
login = login.to_s
|
||||
password = password.to_s
|
||||
|
||||
@@ -166,8 +166,8 @@ class User < Principal
|
||||
user = find_by_login(login)
|
||||
if user
|
||||
# user is already in local database
|
||||
return nil unless user.active?
|
||||
return nil unless user.check_password?(password)
|
||||
return nil if !user.active? && active_only
|
||||
else
|
||||
# user is not yet registered, try to authenticate with available sources
|
||||
attrs = AuthSource.authenticate(login, password)
|
||||
@@ -181,7 +181,7 @@ class User < Principal
|
||||
end
|
||||
end
|
||||
end
|
||||
user.update_column(:last_login_on, Time.now) if user && !user.new_record?
|
||||
user.update_column(:last_login_on, Time.now) if user && !user.new_record? && user.active?
|
||||
user
|
||||
rescue => text
|
||||
raise text
|
||||
|
||||
Reference in new issue
Block a user