FEATURE: sso_overrides_(email|username|name) for all auth methods

FEATURE: sso_overrides_(email|username|name) for all auth methods

These settings previously applied only to discourse-sso. Now they work for all external authentication methods.

diff --git a/app/assets/javascripts/discourse/app/controllers/create-account.js b/app/assets/javascripts/discourse/app/controllers/create-account.js
index dc8ee4d..a74aa54 100644
--- a/app/assets/javascripts/discourse/app/controllers/create-account.js
+++ b/app/assets/javascripts/discourse/app/controllers/create-account.js
@@ -2,7 +2,7 @@ import getURL from "discourse-common/lib/get-url";
 import I18n from "I18n";
 import { A } from "@ember/array";
 import { isEmpty } from "@ember/utils";
-import { notEmpty, or, not } from "@ember/object/computed";
+import { notEmpty, and } from "@ember/object/computed";
 import Controller, { inject as controller } from "@ember/controller";
 import { ajax } from "discourse/lib/ajax";
 import ModalFunctionality from "discourse/mixins/modal-functionality";
@@ -69,7 +69,8 @@ export default Controller.extend(
       return false;
     },
 
-    usernameRequired: not("authOptions.omit_username"),
+    usernameDisabled: and("authOptions", "!authOptions.can_edit_username"),
+    nameDisabled: and("authOptions", "!authOptions.can_edit_name"),
 
     @discourseComputed
     fullnameRequired() {
diff --git a/app/assets/javascripts/discourse/app/controllers/login.js b/app/assets/javascripts/discourse/app/controllers/login.js
index 9edefd6..36e686d 100644
--- a/app/assets/javascripts/discourse/app/controllers/login.js
+++ b/app/assets/javascripts/discourse/app/controllers/login.js
@@ -389,6 +389,6 @@ export default Controller.extend(ModalFunctionality, {
       authOptions: EmberObject.create(options)
     });
 
-    showModal("createAccount");
+    showModal("createAccount", { modalClass: "create-account" });
   }
 });
diff --git a/app/assets/javascripts/discourse/app/templates/modal/create-account.hbs b/app/assets/javascripts/discourse/app/templates/modal/create-account.hbs
index df8acfc..e3bee67 100644
--- a/app/assets/javascripts/discourse/app/templates/modal/create-account.hbs
+++ b/app/assets/javascripts/discourse/app/templates/modal/create-account.hbs
@@ -15,7 +15,11 @@
                 <tr class="input create-account-email">
                   <td class="label"><label for="new-account-email">{{i18n "user.email.title"}}</label></td>
                   <td>
-                    {{input type="email" value=accountEmail id="new-account-email" disabled=emailValidated name="email" autofocus="autofocus"}}
+                    {{#if emailValidated}}
+                      <span class="value">{{accountEmail}}</span>
+                    {{else}}
+                      {{input type="email" value=accountEmail id="new-account-email" name="email" autofocus="autofocus"}}
+                    {{/if}}
                   </td>
                 </tr>
 
@@ -25,19 +29,21 @@
                   <td><label>{{i18n "user.email.instructions"}}</label></td>
                 </tr>
 
-                {{#if usernameRequired}}
-                  <tr class="input">
-                    <td class="label"><label for="new-account-username">{{i18n "user.username.title"}}</label></td>
-                    <td>
+                <tr class="input">
+                  <td class="label"><label for="new-account-username">{{i18n "user.username.title"}}</label></td>
+                  <td>
+                    {{#if usernameDisabled}}
+                      <span class="value">{{accountUsername}}</span>
+                    {{else}}
                       {{input value=accountUsername id="new-account-username" name="username" maxlength=maxUsernameLength autocomplete="discourse"}}
-                    </td>
-                  </tr>
-                  <tr class="instructions">
-                    <td></td>
-                    {{input-tip validation=usernameValidation id="username-validation"}}
-                    <td><label>{{i18n "user.username.instructions"}}</label></td>
-                  </tr>
-                {{/if}}
+                    {{/if}}
+                  </td>
+                </tr>
+                <tr class="instructions">
+                  <td></td>
+                  {{input-tip validation=usernameValidation id="username-validation"}}
+                  <td><label>{{i18n "user.username.instructions"}}</label></td>
+                </tr>
 
                 {{#if fullnameRequired}}
                   <tr class="input">
@@ -45,7 +51,11 @@
                       <label for="new-account-name">{{i18n "user.name.title"}}</label>
                     </td>
                     <td>
-                      {{text-field value=accountName id="new-account-name"}}
+                      {{#if nameDisabled}}
+                        <span class="value">{{accountName}}</span>
+                      {{else}}
+                        {{text-field value=accountName id="new-account-name"}}
+                      {{/if}}
                     </td>
                   </tr>
                   <tr class="instructions">
diff --git a/app/assets/stylesheets/common/base/login.scss b/app/assets/stylesheets/common/base/login.scss
index 6f75cf3..494dcfd 100644
--- a/app/assets/stylesheets/common/base/login.scss
+++ b/app/assets/stylesheets/common/base/login.scss
@@ -69,6 +69,10 @@
     margin-top: 0.5em;
   }
 
+  tr.input span.value {
+    margin-left: 10px;
+  }
+
   .user-field {
     > label {
       margin-top: 0.75em;
diff --git a/app/assets/stylesheets/desktop/login.scss b/app/assets/stylesheets/desktop/login.scss
index 188f6ef..f2ec4bd 100644
--- a/app/assets/stylesheets/desktop/login.scss
+++ b/app/assets/stylesheets/desktop/login.scss
@@ -97,7 +97,7 @@
 .has-alt-auth {
   .tip,
   td label {
-    max-width: 250px;
+    max-width: 100%;
   }
 }
 
diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb
index 4bcd8c8..fff323a 100644
--- a/app/controllers/users/omniauth_callbacks_controller.rb
+++ b/app/controllers/users/omniauth_callbacks_controller.rb
@@ -137,6 +137,7 @@ class Users::OmniauthCallbacksController < ApplicationController
     elsif ScreenedIpAddress.block_admin_login?(user, request.remote_ip)
       @auth_result.admin_not_allowed_from_ip_address = true
     elsif Guardian.new(user).can_access_forum? && user.active # log on any account that is active with forum access
+      user.save! if @auth_result.apply_user_attributes!
       log_on_user(user)
       Invite.invalidate_for_email(user.email) # invite link can't be used to log in anymore
       session[:authentication] = nil # don't carry around old auth info, perhaps move elsewhere
diff --git a/app/services/user_authenticator.rb b/app/services/user_authenticator.rb
index 1cc3761..d5fdb91 100644
--- a/app/services/user_authenticator.rb
+++ b/app/services/user_authenticator.rb
@@ -6,7 +6,7 @@ class UserAuthenticator
     @user = user
     @session = session
     if session[:authentication] && session[:authentication].is_a?(Hash)
-      @auth_result = Auth::Result.from_session_data(session[:authentication])
+      @auth_result = Auth::Result.from_session_data(session[:authentication], user: user)
     end
     @authenticator_finder = authenticator_finder
   end
@@ -14,6 +14,7 @@ class UserAuthenticator
   def start
     if authenticated?
       @user.active = true
+      @auth_result.apply_user_attributes!
     else
       @user.password_required!
     end
@@ -38,7 +39,10 @@ class UserAuthenticator
   end
 
   def authenticated?
-    @auth_result && @auth_result.email.downcase == @user.email.downcase && @auth_result.email_valid.to_s == "true"
+    return false if !@auth_result
+    return false if @auth_result.email.downcase != @user.email.downcase
+    return false if @auth_result.email_valid != true # strong check for truth, in case we have another object type
+    true
   end
 
   private
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 03d621d..1b03951 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -1632,9 +1632,9 @@ en:

[... diff too long, it was truncated ...]

GitHub sha: 977766e7

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/where-is-the-button-to-enable-the-username-input-field-modal-create-account/162548/2