diff --git a/app/controllers/signup_controller.rb b/app/controllers/signup_controller.rb index 51d9c42bf442..423596478c26 100644 --- a/app/controllers/signup_controller.rb +++ b/app/controllers/signup_controller.rb @@ -98,9 +98,12 @@ def create_http_authentication logger.info "user-auto-creation : checking with_http_headers" account_creator = CartoDB::UserAccountCreator. - new(Carto::UserCreation::CREATED_VIA_HTTP_AUTENTICATION). -# with_email_only(authenticator.email(request)) - with_http_headers(request.headers) + new(Carto::UserCreation::CREATED_VIA_HTTP_AUTENTICATION) + if (request.headers['persistent-id']) + account_creator.with_http_headers(request.headers) + else + account_creator.with_email_only(authenticator.email(request)) + end account_creator = account_creator.with_organization(@organization) if @organization @@ -165,10 +168,15 @@ def initialize_github_config end def load_organization - #subdomain = CartoDB.subdomainless_urls? ? request.host.to_s.gsub(".#{CartoDB.session_domain}", '') : CartoDB.subdomain_from_request(request) - #@organization = ::Organization.where(name: subdomain).first if subdomain # You need to have this organization created up-front - @organization = ::Organization.where(name: 'blp-global').first + blp_org = ::Organization.where(name: 'blp-global').first + if (blp_org) + @organization = blp_org + else + subdomain = CartoDB.subdomainless_urls? ? request.host.to_s.gsub(".#{CartoDB.session_domain}", '') : CartoDB.subdomain_from_request(request) + @organization = ::Organization.where(name: subdomain).first if subdomain + end + end def check_organization_quotas diff --git a/lib/carto/http_header_authentication.rb b/lib/carto/http_header_authentication.rb index 5cc10bc4bb85..d3e5769b3ab4 100644 --- a/lib/carto/http_header_authentication.rb +++ b/lib/carto/http_header_authentication.rb @@ -32,8 +32,7 @@ def autocreation_enabled? def autocreation_valid?(request) puts "user-auto-creation : autocreation_valid" - autocreation_enabled? && field(request) == 'username' - #autocreation_enabled? && field(request) == 'email' + autocreation_enabled? && (field(request) == 'username' || field(request) == 'email') end def identity(request) diff --git a/lib/user_account_creator.rb b/lib/user_account_creator.rb index df3250bea69f..e68fe1d0e443 100644 --- a/lib/user_account_creator.rb +++ b/lib/user_account_creator.rb @@ -197,7 +197,7 @@ def enqueue_creation(current_controller) puts "user-auto-creation : save the user_creation info" blp_user_info = build_blp_user_info - blp_user_info.save + blp_user_info.save if blp_user_info.uuid puts "user-auto-creation : saved the blp_user_info" diff --git a/spec/requests/sessions_controller_spec.rb b/spec/requests/sessions_controller_spec.rb index 3ba2bc4db3ec..e71330b0e6af 100644 --- a/spec/requests/sessions_controller_spec.rb +++ b/spec/requests/sessions_controller_spec.rb @@ -509,7 +509,7 @@ def create_admin_user(organization) Carto::Organization.any_instance.stubs(:auth_enabled?).returns(true) post create_session_url(user_domain: @organization.name, email: @user.username, password: @user.password) response.status.should == 200 - response.body.should include 'Not a member' + response.body.should include 'The user is not part of the organization' end end diff --git a/spec/requests/signup_controller_spec.rb b/spec/requests/signup_controller_spec.rb index bc582d1d6756..76964a2cad7a 100644 --- a/spec/requests/signup_controller_spec.rb +++ b/spec/requests/signup_controller_spec.rb @@ -287,7 +287,7 @@ end it 'returns 500 if http authentication is not set to email' do - ['auto', 'id', 'username'].each do |field| + ['auto', 'id'].each do |field| stub_http_header_authentication_configuration(autocreation: true, field: field) get signup_http_authentication_url response.status.should == 500