From 5b10be8450f19a00b47606169cc42809f54c84c5 Mon Sep 17 00:00:00 2001 From: Callum Brown Date: Fri, 3 Dec 2021 10:23:57 +0000 Subject: [PATCH] Support token authenticated registration https://spec.matrix.org/v1.2/client-server-api/#token-authenticated-registration Signed-off-by: Callum Brown --- .../auth/InteractiveAuthEntryComponents.tsx | 89 +++++++++++++++++++ src/i18n/strings/en_EN.json | 2 + 2 files changed, 91 insertions(+) diff --git a/src/components/views/auth/InteractiveAuthEntryComponents.tsx b/src/components/views/auth/InteractiveAuthEntryComponents.tsx index 63845f0e97c..96653a2e38f 100644 --- a/src/components/views/auth/InteractiveAuthEntryComponents.tsx +++ b/src/components/views/auth/InteractiveAuthEntryComponents.tsx @@ -621,6 +621,93 @@ export class MsisdnAuthEntry extends React.Component { + static LOGIN_TYPE = AuthType.RegistrationToken; + + constructor(props) { + super(props); + + this.state = { + registrationToken: "", + }; + } + + componentDidMount() { + this.props.onPhaseChange(DEFAULT_PHASE); + } + + private onSubmit = (e: FormEvent) => { + e.preventDefault(); + if (this.props.busy) return; + + this.props.submitAuthDict({ + type: AuthType.RegistrationToken, + token: this.state.registrationToken, + }); + }; + + private onRegistrationTokenFieldChange = (ev: ChangeEvent) => { + // enable the submit button if the registration token is non-empty + this.setState({ + registrationToken: ev.target.value, + }); + }; + + render() { + const registrationTokenBoxClass = classNames({ + "error": this.props.errorText, + }); + + let submitButtonOrSpinner; + if (this.props.busy) { + submitButtonOrSpinner = ; + } else { + submitButtonOrSpinner = ( + + ); + } + + let errorSection; + if (this.props.errorText) { + errorSection = ( +
+ { this.props.errorText } +
+ ); + } + + return ( +
+

{ _t("Enter a registration token.") }

+
+ + { errorSection } +
+ { submitButtonOrSpinner } +
+ +
+ ); + } +} + interface ISSOAuthEntryProps extends IAuthEntryProps { continueText?: string; continueKind?: string; @@ -854,6 +941,8 @@ export default function getEntryComponentForLoginType(loginType: AuthType): ISta return MsisdnAuthEntry; case AuthType.Terms: return TermsAuthEntry; + case AuthType.RegistrationToken: + return RegistrationTokenAuthEntry; case AuthType.Sso: case AuthType.SsoUnstable: return SSOAuthEntry; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index e50bd524455..84c85c1f801 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2942,6 +2942,8 @@ "Please enter the code it contains:": "Please enter the code it contains:", "Code": "Code", "Submit": "Submit", + "Enter a registration token.": "Enter a registration token.", + "Registration token": "Registration token", "Something went wrong in confirming your identity. Cancel and try again.": "Something went wrong in confirming your identity. Cancel and try again.", "Start authentication": "Start authentication", "Enter password": "Enter password",