Refactor: Add methods to User to edit the encapsulate the status field.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3906 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
25037b841b
commit
13234f8552
|
@ -83,9 +83,9 @@ class AccountController < ApplicationController
|
||||||
else
|
else
|
||||||
@user = User.new(params[:user])
|
@user = User.new(params[:user])
|
||||||
@user.admin = false
|
@user.admin = false
|
||||||
@user.status = User::STATUS_REGISTERED
|
@user.register
|
||||||
if session[:auth_source_registration]
|
if session[:auth_source_registration]
|
||||||
@user.status = User::STATUS_ACTIVE
|
@user.activate
|
||||||
@user.login = session[:auth_source_registration][:login]
|
@user.login = session[:auth_source_registration][:login]
|
||||||
@user.auth_source_id = session[:auth_source_registration][:auth_source_id]
|
@user.auth_source_id = session[:auth_source_registration][:auth_source_id]
|
||||||
if @user.save
|
if @user.save
|
||||||
|
@ -116,8 +116,8 @@ class AccountController < ApplicationController
|
||||||
token = Token.find_by_action_and_value('register', params[:token])
|
token = Token.find_by_action_and_value('register', params[:token])
|
||||||
redirect_to(home_url) && return unless token and !token.expired?
|
redirect_to(home_url) && return unless token and !token.expired?
|
||||||
user = token.user
|
user = token.user
|
||||||
redirect_to(home_url) && return unless user.status == User::STATUS_REGISTERED
|
redirect_to(home_url) && return unless user.registered?
|
||||||
user.status = User::STATUS_ACTIVE
|
user.activate
|
||||||
if user.save
|
if user.save
|
||||||
token.destroy
|
token.destroy
|
||||||
flash[:notice] = l(:notice_account_activated)
|
flash[:notice] = l(:notice_account_activated)
|
||||||
|
@ -170,7 +170,7 @@ class AccountController < ApplicationController
|
||||||
user.mail = registration['email'] unless registration['email'].nil?
|
user.mail = registration['email'] unless registration['email'].nil?
|
||||||
user.firstname, user.lastname = registration['fullname'].split(' ') unless registration['fullname'].nil?
|
user.firstname, user.lastname = registration['fullname'].split(' ') unless registration['fullname'].nil?
|
||||||
user.random_password
|
user.random_password
|
||||||
user.status = User::STATUS_REGISTERED
|
user.register
|
||||||
|
|
||||||
case Setting.self_registration
|
case Setting.self_registration
|
||||||
when '1'
|
when '1'
|
||||||
|
@ -241,7 +241,7 @@ class AccountController < ApplicationController
|
||||||
# Pass a block for behavior when a user fails to save
|
# Pass a block for behavior when a user fails to save
|
||||||
def register_automatically(user, &block)
|
def register_automatically(user, &block)
|
||||||
# Automatic activation
|
# Automatic activation
|
||||||
user.status = User::STATUS_ACTIVE
|
user.activate
|
||||||
user.last_login_on = Time.now
|
user.last_login_on = Time.now
|
||||||
if user.save
|
if user.save
|
||||||
self.logged_user = user
|
self.logged_user = user
|
||||||
|
|
|
@ -164,6 +164,30 @@ class User < Principal
|
||||||
self.status == STATUS_LOCKED
|
self.status == STATUS_LOCKED
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def activate
|
||||||
|
self.status = STATUS_ACTIVE
|
||||||
|
end
|
||||||
|
|
||||||
|
def register
|
||||||
|
self.status = STATUS_REGISTERED
|
||||||
|
end
|
||||||
|
|
||||||
|
def lock
|
||||||
|
self.status = STATUS_LOCKED
|
||||||
|
end
|
||||||
|
|
||||||
|
def activate!
|
||||||
|
update_attribute(:status, STATUS_ACTIVE)
|
||||||
|
end
|
||||||
|
|
||||||
|
def register!
|
||||||
|
update_attribute(:status, STATUS_REGISTERED)
|
||||||
|
end
|
||||||
|
|
||||||
|
def lock!
|
||||||
|
update_attribute(:status, STATUS_LOCKED)
|
||||||
|
end
|
||||||
|
|
||||||
def check_password?(clear_password)
|
def check_password?(clear_password)
|
||||||
if auth_source_id.present?
|
if auth_source_id.present?
|
||||||
auth_source.authenticate(self.login, clear_password)
|
auth_source.authenticate(self.login, clear_password)
|
||||||
|
|
Loading…
Reference in New Issue