From 9adbde13619de8b2c300056b062d12f0961cb710 Mon Sep 17 00:00:00 2001 From: ankonym Date: Mon, 21 Sep 2015 18:34:04 +0200 Subject: Make invite code configurable Through the config param 'invite_required', providers can decide whether users need to provide an invite code upon signup. The default setting is false. --- app/models/account.rb | 9 ++++++--- app/models/user.rb | 2 +- app/views/users/new.html.haml | 5 ++++- 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/models/account.rb b/app/models/account.rb index c398d93..a5cd833 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -28,9 +28,12 @@ class Account identity.errors.each do |attr, msg| user.errors.add(attr, msg) end - user_invite_code = InviteCode.find_by_invite_code user.invite_code - user_invite_code.invite_count += 1 - user_invite_code.save + + if APP_CONFIG[:invite_required] + user_invite_code = InviteCode.find_by_invite_code user.invite_code + user_invite_code.invite_count += 1 + user_invite_code.save + end end rescue StandardError => ex user.errors.add(:base, ex.to_s) if user diff --git a/app/models/user.rb b/app/models/user.rb index c0079d5..3daee0f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -40,7 +40,7 @@ class User < CouchRest::Model::Base :mx_with_fallback => true - validates_with InviteCodeValidator, on: :create + validates_with InviteCodeValidator, on: :create, if: -> {APP_CONFIG[:invite_required]} timestamps! diff --git a/app/views/users/new.html.haml b/app/views/users/new.html.haml index cd4bf70..b44f77c 100644 --- a/app/views/users/new.html.haml +++ b/app/views/users/new.html.haml @@ -17,8 +17,11 @@ = f.input :login, :label => t(:username), :required => false, :input_html => { :id => :srp_username } = f.input :password, :required => false, :validate => true, :input_html => { :id => :srp_password } = f.input :password_confirmation, :required => false, :validate => true, :input_html => { :id => :srp_password_confirmation } - = f.input :invite_code, :input_html => { :id => :srp_invite_code } + - if APP_CONFIG[:invite_required] + = f.input :invite_code, :input_html => { :id => :srp_invite_code } + - else + = f.input :invite_code, :as => "hidden", :input_html => { :value => " ", :id => :srp_invite_code } = f.button :wrapped, cancel: home_path -# -- cgit v1.2.3