diff --git a/app/assets/javascripts/discourse/app/controllers/invites-show.js b/app/assets/javascripts/discourse/app/controllers/invites-show.js index 1b5eb23e0b4..3890643ee69 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", { @@ -62,6 +80,25 @@ export default Controller.extend( return findLoginMethods().length > 0; }, + @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 ( @@ -69,8 +106,18 @@ export default Controller.extend( ); }, - @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 261f51e41b9..13029e40442 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 07a10e5c124..bc2bc0aba98 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}} -{{/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 8739fc39246..db455bb7f55 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 @@
{{i18n "create_account.subheader_title"}}
+{{html-safe yourEmailMessage}} - {{#if externalAuthsEnabled}} + {{#unless externalAuthsOnly}} {{i18n "invites.social_login_available"}} - {{/if}} + {{/unless}}
{{/unless}} -