From dcd24d61be99e2b2f2480d402a6fdbce099eafb6 Mon Sep 17 00:00:00 2001 From: John Ma Date: Tue, 2 Oct 2018 10:23:09 -0400 Subject: [PATCH] John fix issue#274 (#275) * * * * * * --- app/controllers/rooms_controller.rb | 4 +++- app/controllers/users_controller.rb | 2 ++ app/models/user.rb | 3 ++- app/views/users/new.html.erb | 12 +++++++----- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index f6c705dd..0220dae6 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -180,6 +180,8 @@ class RoomsController < ApplicationController end def validate_accepted_terms - redirect_to terms_path unless current_user.accepted_terms + if current_user + redirect_to terms_path unless current_user.accepted_terms + end end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 28d9fa80..d76b3aeb 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -99,6 +99,8 @@ class UsersController < ApplicationController # GET /terms def terms + redirect_to '/404' unless Rails.configuration.terms + if params[:accept] == "true" current_user.update_attributes(accepted_terms: true) redirect_to current_user.main_room if current_user diff --git a/app/models/user.rb b/app/models/user.rb index 06b2b81a..84f824e8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -35,7 +35,8 @@ class User < ApplicationRecord validates :password, length: { minimum: 6 }, confirmation: true, if: :greenlight_account?, on: :create # Bypass validation if omniauth - validates :accepted_terms, acceptance: true, unless: proc { !greenlight_account? } + validates :accepted_terms, acceptance: true, + unless: -> { !greenlight_account? || !Rails.configuration.terms } # We don't want to require password validations on all accounts. has_secure_password(validations: false) diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 52fe644e..e0be4e13 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -57,11 +57,13 @@ <%= f.password_field :password_confirmation, class: "form-control #{form_is_invalid?(@user, :password_confirmation)}", placeholder: t("signup.password_confirm") %>
<%= @user.errors.full_messages_for(:password_confirmation).first %>
-
- <%= f.check_box :accepted_terms, class: "form-control #{form_is_invalid?(@user, :accepted_terms)}", placeholder: t("signup.password_confirm") %> - <%= f.label :accepted_terms, t("terms.accept", href: link_to(t("terms.title"), terms_path, target: "_blank", class: "ml-1 text-blue")).html_safe, class: "ml-1" %> -
<%= @user.errors.full_messages_for(:accepted_terms).first %>
-
+ <% if Rails.configuration.terms %> +
+ <%= f.check_box :accepted_terms, class: "form-control #{form_is_invalid?(@user, :accepted_terms)}", placeholder: t("signup.password_confirm") %> + <%= f.label :accepted_terms, t("terms.accept", href: link_to(t("terms.title"), terms_path, target: "_blank", class: "ml-1 text-blue")).html_safe, class: "ml-1" %> +
<%= @user.errors.full_messages_for(:accepted_terms).first %>
+
+ <% end %>