From ed2a58fd73a521747cf3370baa5807ce07047290 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Wed, 16 May 2012 14:59:58 -0300 Subject: [PATCH] Allow disabling the need for e-mail confirmations --- app/controllers/public/account_controller.rb | 7 ++++++- app/models/environment.rb | 1 + app/models/user.rb | 3 +++ test/functional/account_controller_test.rb | 10 ++++++++++ test/unit/user_test.rb | 8 ++++++++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index 925f6a2..5d3ea19 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -78,7 +78,12 @@ class AccountController < ApplicationController invitation.update_attributes!({:friend => @user.person}) invitation.finish end - @register_pending = true + if @user.activated? + self.current_user = @user + redirect_to '/' + else + @register_pending = true + end end rescue ActiveRecord::RecordInvalid @person.valid? diff --git a/app/models/environment.rb b/app/models/environment.rb index ee313e9..8bca2e3 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -121,6 +121,7 @@ class Environment < ActiveRecord::Base 'xmpp_chat' => _('XMPP/Jabber based chat'), 'show_zoom_button_on_article_images' => _('Show a zoom link on all article images'), 'captcha_for_logged_users' => _('Ask captcha when a logged user comments too'), + 'skip_new_user_email_confirmation' => _('Skip e-mail confirmation for new users') } end diff --git a/app/models/user.rb b/app/models/user.rb index e2ea1f5..020a4a9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -35,6 +35,9 @@ class User < ActiveRecord::Base user.person.name ||= user.login user.person.visible = false unless user.activated? user.person.save! + if user.environment && user.environment.enabled?('skip_new_user_email_confirmation') + user.activate + end end after_create :deliver_activation_code after_create :delay_activation_check diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index 3480ef0..fb3d516 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -737,6 +737,16 @@ class AccountControllerTest < ActionController::TestCase end end + should 'login after signup when no e-mail confirmation is required' do + e = Environment.default + e.enable('skip_new_user_email_confirmation') + e.save! + + new_user + assert_response :redirect + assert_not_nil assigns(:current_user) + end + protected def new_user(options = {}, extra_options ={}) data = {:profile_data => person_data} diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 15b869e..6dbe034 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -478,6 +478,14 @@ class UserTest < ActiveSupport::TestCase end end + should 'activate right after creation when confirmation is not required' do + e = Environment.default + e.enable('skip_new_user_email_confirmation') + e.save! + + assert new_user.activated? + end + protected def new_user(options = {}) user = User.new({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options)) -- libgit2 0.21.2