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
# 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)
: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)
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)
<% 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>
--- /dev/null
+<p><%= l(:mail_body_account_activation_request, @user.login) %></p>
+<p><%= link_to @url, @url %></p>
--- /dev/null
+<%= l(:mail_body_account_activation_request, @user.login) %>
+<%= @url %>
<%= 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>
login_required:
default: 0
self_registration:
- default: 1
+ default: '2'
lost_password:
default: 1
attachment_max_size:
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."
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."
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."
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:'
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
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
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
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."
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:'
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
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
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
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."
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."
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."
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
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."
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."
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."
setting_protocol: Protocol\r
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"\r
setting_time_format: Time format\r
+label_registration_activation_by_email: account activation by email\r
+mail_subject_account_activation_request: Redmine account activation request\r
+mail_body_account_activation_request: 'A new user (%s) has registered. His account his pending your approval:'\r
+label_registration_automatic_activation: automatic account activation\r
+label_registration_manual_activation: manual account activation\r
+notice_account_pending: "Your account was created and is now pending administrator approval."\r
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."
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."
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."
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."
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."
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."
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