diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 50c4dcb..18fb632 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -26,9 +26,17 @@ class AccountController < ApplicationController # action to register an user to the application def signup begin + @terms_of_use = virtual_community.terms_of_use + terms_accepted = params[:user].delete(:terms_accepted) @user = User.new(params[:user]) return unless request.post? + if @terms_of_use and !terms_accepted + flash[:notice] = _("You have to accept the terms of service to signup") + return + end @user.save! + @user.person.virtual_community = virtual_community + @user.person.save! self.current_user = @user redirect_back_or_default(:controller => 'account', :action => 'index') flash[:notice] = _("Thanks for signing up!") diff --git a/app/models/virtual_community.rb b/app/models/virtual_community.rb index 00b1366..82dfb11 100644 --- a/app/models/virtual_community.rb +++ b/app/models/virtual_community.rb @@ -20,6 +20,7 @@ class VirtualCommunity < ActiveRecord::Base # One VirtualCommunity can be reached by many domains has_many :domains, :as => :owner + has_many :profiles # ################################################# # Attributes diff --git a/app/views/account/signup.rhtml b/app/views/account/signup.rhtml index 12b7059..54e9825 100644 --- a/app/views/account/signup.rhtml +++ b/app/views/account/signup.rhtml @@ -14,5 +14,11 @@
<%= f.password_field :password_confirmation %>
<%= @terms_of_use %>
+<%= check_box 'user', 'terms_accepted' %> +
+<% end %> +<%= submit_tag 'Sign up' %>
<% end -%> diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index 239498b..7d96c26 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -68,6 +68,22 @@ class AccountControllerTest < Test::Unit::TestCase end end + def test_shoud_not_save_without_acceptance_of_terms_of_use_on_signup + assert_no_difference User, :count do + VirtualCommunity.default.update_attributes(:terms_of_use => 'some terms ...') + create_user + assert_response :success + end + end + + def test_shoud_save_with_acceptance_of_terms_of_use_on_signup + assert_difference User, :count do + VirtualCommunity.default.update_attributes(:terms_of_use => 'some terms ...') + create_user(:terms_accepted => true) + assert_response :redirect + end + end + def test_should_logout login_as :johndoe get :logout -- libgit2 0.21.2