FEATURE: Allow invites redemption with Omniauth providers.

FEATURE: Allow invites redemption with Omniauth providers.

diff --git a/app/assets/javascripts/discourse/app/controllers/invites-show.js b/app/assets/javascripts/discourse/app/controllers/invites-show.js
index 1b5eb23..3890643 100644
--- a/app/assets/javascripts/discourse/app/controllers/invites-show.js
+++ b/app/assets/javascripts/discourse/app/controllers/invites-show.js
@@ -1,5 +1,5 @@
 import { alias, notEmpty, or, readOnly } from "@ember/object/computed";
-import Controller from "@ember/controller";
+import Controller, { inject as controller } from "@ember/controller";
 import DiscourseURL from "discourse/lib/url";
 import EmberObject from "@ember/object";
 import I18n from "I18n";
@@ -14,6 +14,7 @@ import { emailValid } from "discourse/lib/utilities";
 import { findAll as findLoginMethods } from "discourse/models/login-method";
 import getUrl from "discourse-common/lib/get-url";
 import { isEmpty } from "@ember/utils";
+import { wavingHandURL } from "discourse/lib/waving-hand-url";
 
 export default Controller.extend(
   PasswordValidation,
@@ -21,6 +22,8 @@ export default Controller.extend(
   NameValidation,
   UserFieldsValidation,
   {
+    createAccount: controller(),
+
     invitedBy: readOnly("model.invited_by"),
     email: alias("model.email"),
     accountUsername: alias("model.username"),
@@ -28,6 +31,7 @@ export default Controller.extend(
     successMessage: null,
     errorMessage: null,
     userFields: null,
+    authOptions: null,
     inviteImageUrl: getUrl("/images/envelope.svg"),
     isInviteLink: readOnly("model.is_invite_link"),
     submitDisabled: or(
@@ -45,6 +49,20 @@ export default Controller.extend(
       this.rejectedEmails = [];
     },
 
+    authenticationComplete(options) {
+      const props = {
+        accountUsername: options.username,
+        accountName: options.name,
+        authOptions: EmberObject.create(options),
+      };
+
+      if (this.isInviteLink) {
+        props.email = options.email;
+      }
+
+      this.setProperties(props);
+    },
+
     @discourseComputed
     welcomeTitle() {
       return I18n.t("invites.welcome_to", {
@@ -63,14 +81,43 @@ export default Controller.extend(
     },
 
     @discourseComputed
+    externalAuthsOnly() {
+      return (
+        !this.siteSettings.enable_local_logins && this.externalAuthsEnabled
+      );
+    },
+
+    @discourseComputed(
+      "externalAuthsOnly",
+      "authOptions",
+      "emailValidation.failed"
+    )
+    shouldDisplayForm(externalAuthsOnly, authOptions, emailValidationFailed) {
+      return (
+        this.siteSettings.enable_local_logins ||
+        (externalAuthsOnly && authOptions && !emailValidationFailed)
+      );
+    },
+
+    @discourseComputed
     fullnameRequired() {
       return (
         this.siteSettings.full_name_required || this.siteSettings.enable_names
       );
     },
 
-    @discourseComputed("email", "rejectedEmails.[]")
-    emailValidation(email, rejectedEmails) {
+    @discourseComputed(
+      "email",
+      "rejectedEmails.[]",
+      "authOptions.email",
+      "authOptions.email_valid"
+    )
+    emailValidation(
+      email,
+      rejectedEmails,
+      externalAuthEmail,
+      externalAuthEmailValid
+    ) {
       // If blank, fail without a reason
       if (isEmpty(email)) {
         return EmberObject.create({
@@ -85,6 +132,28 @@ export default Controller.extend(
         });
       }
 
+      if (externalAuthEmail) {
+        const provider = this.createAccount.authProviderDisplayName(
+          this.get("authOptions.auth_provider")
+        );
+
+        if (externalAuthEmail === email && externalAuthEmailValid) {
+          return EmberObject.create({
+            ok: true,
+            reason: I18n.t("user.email.authenticated", {
+              provider,
+            }),
+          });
+        } else {
+          return EmberObject.create({
+            failed: true,
+            reason: I18n.t("user.email.invite_auth_email_invalid", {
+              provider,
+            }),
+          });
+        }
+      }
+
       if (emailValid(email)) {
         return EmberObject.create({
           ok: true,
@@ -98,6 +167,9 @@ export default Controller.extend(
       });
     },
 
+    @discourseComputed
+    wavingHandURL: () => wavingHandURL(),
+
     actions: {
       submit() {
         const userFields = this.userFields;
@@ -158,6 +230,12 @@ export default Controller.extend(
             this.set("errorMessage", extractError(error));
           });
       },
+
+      externalLogin(provider) {
+        provider.doLogin({
+          origin: window.location.href,
+        });
+      },
     },
   }
 );
diff --git a/app/assets/javascripts/discourse/app/initializers/auth-complete.js b/app/assets/javascripts/discourse/app/initializers/auth-complete.js
index 261f51e..13029e4 100644
--- a/app/assets/javascripts/discourse/app/initializers/auth-complete.js
+++ b/app/assets/javascripts/discourse/app/initializers/auth-complete.js
@@ -13,10 +13,14 @@ export default {
 
     if (lastAuthResult) {
       const router = container.lookup("router:main");
+
       router.one("didTransition", () => {
+        const controllerName =
+          router.currentPath === "invites.show" ? "invites-show" : "login";
+
         next(() => {
-          let loginController = container.lookup("controller:login");
-          loginController.authenticationComplete(JSON.parse(lastAuthResult));
+          let controller = container.lookup(`controller:${controllerName}`);
+          controller.authenticationComplete(JSON.parse(lastAuthResult));
         });
       });
     }
diff --git a/app/assets/javascripts/discourse/app/templates/components/login-buttons.hbs b/app/assets/javascripts/discourse/app/templates/components/login-buttons.hbs
index 07a10e5..bc2bc0a 100644
--- a/app/assets/javascripts/discourse/app/templates/components/login-buttons.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/login-buttons.hbs
@@ -9,4 +9,4 @@
     {{/if}}
     {{b.title}}
   </button>
-{{/each}}
\ No newline at end of file
+{{/each}}
diff --git a/app/assets/javascripts/discourse/app/templates/invites/show.hbs b/app/assets/javascripts/discourse/app/templates/invites/show.hbs
index 8739fc3..db455bb 100644
--- a/app/assets/javascripts/discourse/app/templates/invites/show.hbs
+++ b/app/assets/javascripts/discourse/app/templates/invites/show.hbs
@@ -1,5 +1,9 @@
 <div class="container invites-show clearfix">
-  <h2>{{welcomeTitle}}</h2>
+  <div class="login-welcome-header">
+    <h1 class="login-title">{{welcomeTitle}}</h1>
+    <img src={{wavingHandURL}} alt="" class="waving-hand">
+    <p class="login-subheader">{{i18n "create_account.subheader_title"}}</p>
+  </div>
 
   <div class="two-col">
     <div class="col-image">
@@ -19,71 +23,84 @@
         {{#unless isInviteLink}}
           <p>
             {{html-safe yourEmailMessage}}
-            {{#if externalAuthsEnabled}}
+            {{#unless externalAuthsOnly}}
               {{i18n "invites.social_login_available"}}
-            {{/if}}
+            {{/unless}}
           </p>
         {{/unless}}
 
-        <form>
-
-          {{#if isInviteLink}}
-            <div class="input email-input">
-              <label>{{i18n "user.email.title"}}</label>
-              {{input type="email" value=email id="new-account-email" name="email" autofocus="autofocus"}}
+        {{#if externalAuthsOnly}}
+          {{#if authOptions}}
+            {{#unless isInviteLink}}
               {{input-tip validation=emailValidation id="account-email-validation"}}
-              <div class="instructions">{{i18n "user.email.instructions"}}</div>
-            </div>
+            {{/unless}}
+          {{else}}
+            {{login-buttons externalLogin=(action "externalLogin")}}
           {{/if}}
+        {{/if}}
 
-          <div class="input username-input">
-            <label>{{i18n "user.username.title"}}</label>

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

GitHub sha: ce04db86

This commit appears in #12254 which was approved by davidtaylorhq. It was merged by tgxworld.

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