diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index e8e70076..37a810bd 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 aa372120..fe432e9a 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 ef9a12ac..f04bfbb0 100644 --- a/app/views/account/register.rhtml +++ b/app/views/account/register.rhtml @@ -29,9 +29,6 @@ <% for @custom_value in @custom_values %>

<%= custom_field_tag_with_label @custom_value %>

<% end %> - -

-<%= check_box 'user', 'mail_notification' %>

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 00000000..145ecfc8 --- /dev/null +++ b/app/views/mailer/account_activation_request.text.html.rhtml @@ -0,0 +1,2 @@ +

<%= l(:mail_body_account_activation_request, @user.login) %>

+

<%= link_to @url, @url %>

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 00000000..f431e22d --- /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 62aa7974..9b4cc2d5 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) %>

-<%= check_box_tag 'settings[self_registration]', 1, Setting.self_registration? %><%= hidden_field_tag 'settings[self_registration]', 0 %>

+<%= 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 ) %>

<%= check_box_tag 'settings[lost_password]', 1, Setting.lost_password? %><%= hidden_field_tag 'settings[lost_password]', 0 %>

diff --git a/config/settings.yml b/config/settings.yml index c59a5242..e9b9eebf 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -28,7 +28,7 @@ welcome_text: login_required: default: 0 self_registration: - default: 1 + default: '2' lost_password: default: 1 attachment_max_size: diff --git a/lang/bg.yml b/lang/bg.yml index 09a94397..b60173ae 100644 --- a/lang/bg.yml +++ b/lang/bg.yml @@ -538,3 +538,9 @@ mail_body_account_information: Your Redmine account information setting_protocol: Protocol label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" setting_time_format: Time format +label_registration_activation_by_email: account activation by email +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' +label_registration_automatic_activation: automatic account activation +label_registration_manual_activation: manual account activation +notice_account_pending: "Your account was created and is now pending administrator approval." diff --git a/lang/cs.yml b/lang/cs.yml index 493bc77a..487ec967 100644 --- a/lang/cs.yml +++ b/lang/cs.yml @@ -538,3 +538,9 @@ mail_body_account_information: Your Redmine account information setting_protocol: Protocol label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" setting_time_format: Time format +label_registration_activation_by_email: account activation by email +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' +label_registration_automatic_activation: automatic account activation +label_registration_manual_activation: manual account activation +notice_account_pending: "Your account was created and is now pending administrator approval." diff --git a/lang/de.yml b/lang/de.yml index 7463e93e..fc00753b 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -538,3 +538,9 @@ mail_body_account_information: Your Redmine account information setting_protocol: Protocol label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" setting_time_format: Time format +label_registration_activation_by_email: account activation by email +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' +label_registration_automatic_activation: automatic account activation +label_registration_manual_activation: manual account activation +notice_account_pending: "Your account was created and is now pending administrator approval." diff --git a/lang/en.yml b/lang/en.yml index c51a76c8..1df0cf7c 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -75,6 +75,7 @@ notice_email_error: An error occurred while sending mail (%s) notice_feeds_access_key_reseted: Your RSS access key was reseted. notice_failed_to_save_issues: "Failed to save %d issue(s) on %d selected: %s." notice_no_issue_selected: "No issue is selected! Please, check the issues you want to edit." +notice_account_pending: "Your account was created and is now pending administrator approval." mail_subject_lost_password: Your Redmine password mail_body_lost_password: 'To change your Redmine password, click on the following link:' @@ -82,6 +83,8 @@ mail_subject_register: Redmine account activation mail_body_register: 'To activate your Redmine account, click on the following link:' mail_body_account_information_external: You can use your "%s" account to log into Redmine. mail_body_account_information: Your Redmine account information +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' gui_validation_error: 1 error gui_validation_error_plural: %d errors @@ -171,8 +174,8 @@ setting_app_title: Application title setting_app_subtitle: Application subtitle setting_welcome_text: Welcome text setting_default_language: Default language -setting_login_required: Authent. required -setting_self_registration: Self-registration enabled +setting_login_required: Authentication required +setting_self_registration: Self-registration setting_attachment_max_size: Attachment max. size setting_issues_export_limit: Issues export limit setting_mail_from: Emission email address @@ -446,6 +449,9 @@ label_user_mail_option_all: "For any event on all my projects" label_user_mail_option_selected: "For any event on the selected projects only..." label_user_mail_option_none: "Only for things I watch or I'm involved in" label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" +label_registration_activation_by_email: account activation by email +label_registration_manual_activation: manual account activation +label_registration_automatic_activation: automatic account activation button_login: Login button_submit: Submit diff --git a/lang/es.yml b/lang/es.yml index 6807cacb..5175e6c1 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -541,3 +541,9 @@ mail_body_account_information: Your Redmine account information setting_protocol: Protocol label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" setting_time_format: Time format +label_registration_activation_by_email: account activation by email +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' +label_registration_automatic_activation: automatic account activation +label_registration_manual_activation: manual account activation +notice_account_pending: "Your account was created and is now pending administrator approval." diff --git a/lang/fr.yml b/lang/fr.yml index a44604a0..8e1af9a4 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -75,6 +75,7 @@ notice_email_error: "Erreur lors de l'envoi de l'email (%s)" notice_feeds_access_key_reseted: Votre clé d'accès aux flux RSS a été réinitialisée. notice_failed_to_save_issues: "%d demande(s) sur les %d sélectionnées n'ont pas pu être mise(s) à jour: %s." notice_no_issue_selected: "Aucune demande sélectionnée ! Cochez les demandes que vous voulez mettre à jour." +notice_account_pending: "Votre compte a été créé et attend l'approbation de l'administrateur." mail_subject_lost_password: Votre mot de passe redMine mail_body_lost_password: 'Pour changer votre mot de passe Redmine, cliquez sur le lien suivant:' @@ -82,6 +83,8 @@ mail_subject_register: Activation de votre compte redMine mail_body_register: 'Pour activer votre compte Redmine, cliquez sur le lien suivant:' mail_body_account_information_external: Vous pouvez utiliser votre compte "%s" pour vous connecter à Redmine. mail_body_account_information: Paramètres de connexion de votre compte Redmine +mail_subject_account_activation_request: "Demande d'activation d'un compte Redmine" +mail_body_account_activation_request: "Un nouvel utilisateur (%s) s'est inscrit. Son compte nécessite votre approbation:" gui_validation_error: 1 erreur gui_validation_error_plural: %d erreurs @@ -171,8 +174,8 @@ setting_app_title: Titre de l'application setting_app_subtitle: Sous-titre de l'application setting_welcome_text: Texte d'accueil setting_default_language: Langue par défaut -setting_login_required: Authentif. obligatoire -setting_self_registration: Enregistrement autorisé +setting_login_required: Authentification obligatoire +setting_self_registration: Inscription des nouveaux utilisateurs setting_attachment_max_size: Taille max des fichiers setting_issues_export_limit: Limite export demandes setting_mail_from: Adresse d'émission @@ -446,6 +449,9 @@ label_user_mail_option_all: "Pour tous les événements de tous mes projets" label_user_mail_option_selected: "Pour tous les événements des projets sélectionnés..." label_user_mail_option_none: "Seulement pour ce que je surveille ou à quoi je participe" label_user_mail_no_self_notified: "Je ne veux pas être notifié des changements que j'effectue" +label_registration_activation_by_email: activation du compte par email +label_registration_manual_activation: activation manuelle du compte +label_registration_automatic_activation: activation automatique du compte button_login: Connexion button_submit: Soumettre diff --git a/lang/he.yml b/lang/he.yml index 089cfdc7..26e808e0 100644 --- a/lang/he.yml +++ b/lang/he.yml @@ -538,3 +538,9 @@ mail_body_account_information: Your Redmine account information setting_protocol: Protocol label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" setting_time_format: Time format +label_registration_activation_by_email: account activation by email +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' +label_registration_automatic_activation: automatic account activation +label_registration_manual_activation: manual account activation +notice_account_pending: "Your account was created and is now pending administrator approval." diff --git a/lang/it.yml b/lang/it.yml index 13c84893..a8007089 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -538,3 +538,9 @@ mail_body_account_information: Your Redmine account information setting_protocol: Protocol label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" setting_time_format: Time format +label_registration_activation_by_email: account activation by email +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' +label_registration_automatic_activation: automatic account activation +label_registration_manual_activation: manual account activation +notice_account_pending: "Your account was created and is now pending administrator approval." diff --git a/lang/ja.yml b/lang/ja.yml index 6fd8dfcc..86a104d1 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -539,3 +539,9 @@ mail_body_account_information: Your Redmine account information setting_protocol: Protocol label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" setting_time_format: Time format +label_registration_activation_by_email: account activation by email +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' +label_registration_automatic_activation: automatic account activation +label_registration_manual_activation: manual account activation +notice_account_pending: "Your account was created and is now pending administrator approval." diff --git a/lang/ko.yml b/lang/ko.yml index 9998f2f6..e46a6395 100644 --- a/lang/ko.yml +++ b/lang/ko.yml @@ -170,7 +170,7 @@ setting_app_subtitle: Application subtitle setting_welcome_text: Welcome text setting_default_language: Default language setting_login_required: Authent. required -setting_self_registration: Self-registration enabled +setting_self_registration: Self-registration setting_attachment_max_size: Attachment max. size setting_issues_export_limit: Issues export limit setting_mail_from: Emission mail address @@ -538,3 +538,9 @@ setting_protocol: Protocol mail_body_account_information: Your Redmine account information label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" setting_time_format: Time format +label_registration_activation_by_email: account activation by email +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' +label_registration_automatic_activation: automatic account activation +label_registration_manual_activation: manual account activation +notice_account_pending: "Your account was created and is now pending administrator approval." diff --git a/lang/nl.yml b/lang/nl.yml index ab1913e1..1758514a 100644 --- a/lang/nl.yml +++ b/lang/nl.yml @@ -539,3 +539,9 @@ mail_body_account_information: Your Redmine account information setting_protocol: Protocol label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" setting_time_format: Time format +label_registration_activation_by_email: account activation by email +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' +label_registration_automatic_activation: automatic account activation +label_registration_manual_activation: manual account activation +notice_account_pending: "Your account was created and is now pending administrator approval." diff --git a/lang/pl.yml b/lang/pl.yml index 0b433bac..e2d90de7 100644 --- a/lang/pl.yml +++ b/lang/pl.yml @@ -538,3 +538,9 @@ mail_body_account_information: Twoje konto w Redmine setting_protocol: Protocol label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" setting_time_format: Time format +label_registration_activation_by_email: account activation by email +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' +label_registration_automatic_activation: automatic account activation +label_registration_manual_activation: manual account activation +notice_account_pending: "Your account was created and is now pending administrator approval." diff --git a/lang/pt-br.yml b/lang/pt-br.yml index d4f51b61..80c57d3f 100644 --- a/lang/pt-br.yml +++ b/lang/pt-br.yml @@ -538,3 +538,9 @@ mail_body_account_information: Your Redmine account information setting_protocol: Protocol label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" setting_time_format: Time format +label_registration_activation_by_email: account activation by email +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' +label_registration_automatic_activation: automatic account activation +label_registration_manual_activation: manual account activation +notice_account_pending: "Your account was created and is now pending administrator approval." diff --git a/lang/pt.yml b/lang/pt.yml index bfd89bba..00d13641 100644 --- a/lang/pt.yml +++ b/lang/pt.yml @@ -538,3 +538,9 @@ mail_body_account_information: Your Redmine account information setting_protocol: Protocol label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" setting_time_format: Time format +label_registration_activation_by_email: account activation by email +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' +label_registration_automatic_activation: automatic account activation +label_registration_manual_activation: manual account activation +notice_account_pending: "Your account was created and is now pending administrator approval." diff --git a/lang/ro.yml b/lang/ro.yml index 049efa7b..ad8881b9 100644 --- a/lang/ro.yml +++ b/lang/ro.yml @@ -538,3 +538,9 @@ mail_body_account_information: Your Redmine account information setting_protocol: Protocol label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" setting_time_format: Time format +label_registration_activation_by_email: account activation by email +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' +label_registration_automatic_activation: automatic account activation +label_registration_manual_activation: manual account activation +notice_account_pending: "Your account was created and is now pending administrator approval." diff --git a/lang/ru.yml b/lang/ru.yml index 782d715d..100fad70 100644 --- a/lang/ru.yml +++ b/lang/ru.yml @@ -538,3 +538,9 @@ default_activity_development: Разработка enumeration_issue_priorities: Приоритеты задач enumeration_doc_categories: Категории документов enumeration_activities: Действия (учет времени) +label_registration_activation_by_email: account activation by email +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' +label_registration_automatic_activation: automatic account activation +label_registration_manual_activation: manual account activation +notice_account_pending: "Your account was created and is now pending administrator approval." diff --git a/lang/sr.yml b/lang/sr.yml index 1072af7e..769d8177 100644 --- a/lang/sr.yml +++ b/lang/sr.yml @@ -539,3 +539,9 @@ button_copy: Copy setting_protocol: Protocol label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" setting_time_format: Time format +label_registration_activation_by_email: account activation by email +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' +label_registration_automatic_activation: automatic account activation +label_registration_manual_activation: manual account activation +notice_account_pending: "Your account was created and is now pending administrator approval." diff --git a/lang/sv.yml b/lang/sv.yml index d22b5c47..6421173f 100644 --- a/lang/sv.yml +++ b/lang/sv.yml @@ -539,3 +539,9 @@ mail_body_account_information: Your Redmine account information setting_protocol: Protocol label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" setting_time_format: Time format +label_registration_activation_by_email: account activation by email +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' +label_registration_automatic_activation: automatic account activation +label_registration_manual_activation: manual account activation +notice_account_pending: "Your account was created and is now pending administrator approval." diff --git a/lang/zh.yml b/lang/zh.yml index 19e5b122..d738afdb 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -541,3 +541,9 @@ mail_body_account_information: Your Redmine account information setting_protocol: Protocol label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself" setting_time_format: Time format +label_registration_activation_by_email: account activation by email +mail_subject_account_activation_request: Redmine account activation request +mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:' +label_registration_automatic_activation: automatic account activation +label_registration_manual_activation: manual account activation +notice_account_pending: "Your account was created and is now pending administrator approval." diff --git a/test/integration/account_test.rb b/test/integration/account_test.rb index 6799b928..e9d665d1 100644 --- a/test/integration/account_test.rb +++ b/test/integration/account_test.rb @@ -56,5 +56,46 @@ class AccountTest < ActionController::IntegrationTest log_user('jsmith', 'newpass') assert_equal 0, Token.count - end + end + + def test_register_with_automatic_activation + Setting.self_registration = '3' + + get 'account/register' + assert_response :success + assert_template 'account/register' + + post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar"}, + :password => "newpass", :password_confirmation => "newpass" + assert_redirected_to 'account/login' + log_user('newuser', 'newpass') + end + + def test_register_with_manual_activation + Setting.self_registration = '2' + + post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar"}, + :password => "newpass", :password_confirmation => "newpass" + assert_redirected_to 'account/login' + assert !User.find_by_login('newuser').active? + end + + def test_register_with_email_activation + Setting.self_registration = '1' + Token.delete_all + + post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar"}, + :password => "newpass", :password_confirmation => "newpass" + assert_redirected_to 'account/login' + assert !User.find_by_login('newuser').active? + + token = Token.find(:first) + assert_equal 'register', token.action + assert_equal 'newuser@foo.bar', token.user.mail + assert !token.expired? + + get 'account/activate', :token => token.value + assert_redirected_to 'account/login' + log_user('newuser', 'newpass') + end end