diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-11-18 17:46:55 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-11-18 17:46:55 +0000 |
commit | 9c9ae217716304f7062fc31c2f4e4f8adafee2b1 (patch) | |
tree | ca10cbe2297f5a2a77cbbe33a81acd436f597e17 /app/controllers/account_controller.rb | |
parent | f8aa2dc9b71640a4da008e8ef0968a8cd9ce7385 (diff) | |
download | redmine-9c9ae217716304f7062fc31c2f4e4f8adafee2b1.tar.gz redmine-9c9ae217716304f7062fc31c2f4e4f8adafee2b1.zip |
There's now 3 account activation strategies (available in application settings):
* activation by email: the user receives an email containing a link to active his account
* manual activation: an email is sent to administrators for account approval (default)
* automatic activation: the user can log in as soon as he has registered
git-svn-id: http://redmine.rubyforge.org/svn/trunk@915 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/account_controller.rb')
-rw-r--r-- | app/controllers/account_controller.rb | 68 |
1 files changed, 45 insertions, 23 deletions
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index e8e70076b..37a810bdf 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -21,7 +21,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, :only => [:login, :lost_password, :register] + skip_before_filter :check_if_login_required, :only => [:login, :lost_password, :register, :activate] # Show user's account def show @@ -106,40 +106,62 @@ class AccountController < ApplicationController # User self-registration def register redirect_to(home_url) && return unless Setting.self_registration? - if params[:token] - token = Token.find_by_action_and_value("register", params[:token]) - redirect_to(home_url) && return unless token and !token.expired? - user = token.user - redirect_to(home_url) && return unless user.status == User::STATUS_REGISTERED - user.status = User::STATUS_ACTIVE - if user.save - token.destroy - flash[:notice] = l(:notice_account_activated) - redirect_to :action => 'login' - return - end + if request.get? + @user = User.new(:language => Setting.default_language) + @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user) } else - if request.get? - @user = User.new(:language => Setting.default_language) - @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user) } - else - @user = User.new(params[:user]) - @user.admin = false - @user.login = params[:user][:login] - @user.status = User::STATUS_REGISTERED - @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] + @user = User.new(params[:user]) + @user.admin = false + @user.login = params[:user][:login] + @user.status = User::STATUS_REGISTERED + @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] + if params["custom_fields"] @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) } @user.custom_values = @custom_values + end + case Setting.self_registration + when '1' + # Email activation token = Token.new(:user => @user, :action => "register") if @user.save and token.save Mailer.deliver_register(token) flash[:notice] = l(:notice_account_register_done) - redirect_to :controller => 'account', :action => 'login' + redirect_to :action => 'login' + end + when '3' + # Automatic activation + @user.status = User::STATUS_ACTIVE + if @user.save + flash[:notice] = l(:notice_account_activated) + redirect_to :action => 'login' + end + else + # Manual activation by the administrator + if @user.save + # Sends an email to the administrators + Mailer.deliver_account_activation_request(@user) + flash[:notice] = l(:notice_account_pending) + redirect_to :action => 'login' end end end end + # Token based account activation + def activate + redirect_to(home_url) && return unless Setting.self_registration? && params[:token] + token = Token.find_by_action_and_value('register', params[:token]) + redirect_to(home_url) && return unless token and !token.expired? + user = token.user + redirect_to(home_url) && return unless user.status == User::STATUS_REGISTERED + user.status = User::STATUS_ACTIVE + if user.save + token.destroy + flash[:notice] = l(:notice_account_activated) + end + redirect_to :action => 'login' + end + private def logged_user=(user) if user && user.is_a?(User) |