summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-11-18 17:46:55 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-11-18 17:46:55 +0000
commit9c9ae217716304f7062fc31c2f4e4f8adafee2b1 (patch)
treeca10cbe2297f5a2a77cbbe33a81acd436f597e17 /app
parentf8aa2dc9b71640a4da008e8ef0968a8cd9ce7385 (diff)
downloadredmine-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')
-rw-r--r--app/controllers/account_controller.rb68
-rw-r--r--app/models/mailer.rb10
-rw-r--r--app/views/account/register.rhtml3
-rw-r--r--app/views/mailer/account_activation_request.text.html.rhtml2
-rw-r--r--app/views/mailer/account_activation_request.text.plain.rhtml2
-rw-r--r--app/views/settings/edit.rhtml7
6 files changed, 64 insertions, 28 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)
diff --git a/app/models/mailer.rb b/app/models/mailer.rb
index aa372120d..fe432e9a6 100644
--- a/app/models/mailer.rb
+++ b/app/models/mailer.rb
@@ -88,6 +88,14 @@ class Mailer < ActionMailer::Base
:password => password,
:login_url => url_for(:controller => 'account', :action => 'login')
end
+
+ def account_activation_request(user)
+ # Send the email to all active administrators
+ recipients User.find_active(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
+ subject l(:mail_subject_account_activation_request)
+ body :user => user,
+ :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
+ end
def lost_password(token)
set_language_if_valid(token.user.language)
@@ -102,7 +110,7 @@ class Mailer < ActionMailer::Base
recipients token.user.mail
subject l(:mail_subject_register)
body :token => token,
- :url => url_for(:controller => 'account', :action => 'register', :token => token.value)
+ :url => url_for(:controller => 'account', :action => 'activate', :token => token.value)
end
def test(user)
diff --git a/app/views/account/register.rhtml b/app/views/account/register.rhtml
index ef9a12ac0..f04bfbb0e 100644
--- a/app/views/account/register.rhtml
+++ b/app/views/account/register.rhtml
@@ -29,9 +29,6 @@
<% for @custom_value in @custom_values %>
<p><%= custom_field_tag_with_label @custom_value %></p>
<% end %>
-
-<p><label for="user_mail_notification"><%=l(:field_mail_notification)%></label>
-<%= check_box 'user', 'mail_notification' %></p>
<!--[eoform:user]-->
</div>
diff --git a/app/views/mailer/account_activation_request.text.html.rhtml b/app/views/mailer/account_activation_request.text.html.rhtml
new file mode 100644
index 000000000..145ecfc8e
--- /dev/null
+++ b/app/views/mailer/account_activation_request.text.html.rhtml
@@ -0,0 +1,2 @@
+<p><%= l(:mail_body_account_activation_request, @user.login) %></p>
+<p><%= link_to @url, @url %></p>
diff --git a/app/views/mailer/account_activation_request.text.plain.rhtml b/app/views/mailer/account_activation_request.text.plain.rhtml
new file mode 100644
index 000000000..f431e22d3
--- /dev/null
+++ b/app/views/mailer/account_activation_request.text.plain.rhtml
@@ -0,0 +1,2 @@
+<%= l(:mail_body_account_activation_request, @user.login) %>
+<%= @url %>
diff --git a/app/views/settings/edit.rhtml b/app/views/settings/edit.rhtml
index 62aa7974c..9b4cc2d57 100644
--- a/app/views/settings/edit.rhtml
+++ b/app/views/settings/edit.rhtml
@@ -78,7 +78,12 @@
<%= select_tag 'settings[autologin]', options_for_select( [[l(:label_disabled), "0"]] + [1, 7, 30, 365].collect{|days| [lwr(:actionview_datehelper_time_in_words_day, days), days.to_s]}, Setting.autologin) %></p>
<p><label><%= l(:setting_self_registration) %></label>
-<%= check_box_tag 'settings[self_registration]', 1, Setting.self_registration? %><%= hidden_field_tag 'settings[self_registration]', 0 %></p>
+<%= select_tag 'settings[self_registration]',
+ options_for_select( [[l(:label_disabled), "0"],
+ [l(:label_registration_activation_by_email), "1"],
+ [l(:label_registration_manual_activation), "2"],
+ [l(:label_registration_automatic_activation), "3"]
+ ], Setting.self_registration ) %></p>
<p><label><%= l(:label_password_lost) %></label>
<%= check_box_tag 'settings[lost_password]', 1, Setting.lost_password? %><%= hidden_field_tag 'settings[lost_password]', 0 %></p>