diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 112d8f8b0..9ef3def2a 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -26,7 +26,7 @@ class Users::RegistrationsController < Devise::RegistrationsController private def sign_up_params - params.require(:user).permit(:username, :email, :password, :password_confirmation, :captcha, :captcha_key) + params.require(:user).permit(:username, :email, :password, :password_confirmation, :captcha, :captcha_key, :terms_of_service) end def after_inactive_sign_up_path_for(resource_or_scope) diff --git a/app/models/user.rb b/app/models/user.rb index 71db4ee2e..8c11ddad9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -25,6 +25,7 @@ class User < ActiveRecord::Base validates :username, uniqueness: true, unless: :organization? validates :official_level, inclusion: {in: 0..5} validates_format_of :email, without: OMNIAUTH_EMAIL_REGEX, on: :update + validates :terms_of_service, acceptance: { allow_nil: false }, on: :create validates_associated :organization, message: false diff --git a/app/views/users/registrations/new.html.erb b/app/views/users/registrations/new.html.erb index 6795ece5f..cf3d82c6a 100644 --- a/app/views/users/registrations/new.html.erb +++ b/app/views/users/registrations/new.html.erb @@ -28,14 +28,14 @@ <%= f.simple_captcha input_html: {required: false} %> - - <%= f.label :remember_me do %> - <%= f.check_box :remember_me, label: false %> + + <%= f.label :terms_of_service do %> + <%= f.check_box :terms_of_service, label: false %> <%= t("devise_views.users.registrations.new.terms", terms: link_to(t("devise_views.users.registrations.new.terms_link"), "/conditions", target: "_blank")).html_safe %> <% end %> - + <%= f.submit t("devise_views.users.registrations.new.submit"), class: "button radius expand" %> diff --git a/spec/factories.rb b/spec/factories.rb index 07b4e9557..0294d5eb8 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -3,6 +3,7 @@ FactoryGirl.define do sequence(:username) { |n| "Manuela#{n}" } sequence(:email) { |n| "manuela#{n}@madrid.es" } password 'judgmentday' + terms_of_service '1' confirmed_at { Time.now } trait :hidden do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index f9c24ec4d..801702cae 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -52,6 +52,13 @@ describe User do expect(subject).to be_valid end + describe "#terms" do + it "is not valid without accepting the terms of service" do + subject.terms_of_service = nil + expect(subject).to_not be_valid + end + end + describe "#name" do it "is the username when the user is not an organization" do expect(subject.name).to eq(subject.username)