Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Support token authenticated registration
Browse files Browse the repository at this point in the history
  • Loading branch information
govynnus committed Feb 16, 2022
1 parent 0e3b559 commit 5b10be8
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
89 changes: 89 additions & 0 deletions src/components/views/auth/InteractiveAuthEntryComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,93 @@ export class MsisdnAuthEntry extends React.Component<IMsisdnAuthEntryProps, IMsi
}
}

interface IRegistrationTokenAuthEntryState {
registrationToken: string;
}

@replaceableComponent("views.auth.RegistrationTokenAuthEntry")
export class RegistrationTokenAuthEntry extends React.Component<IAuthEntryProps, IRegistrationTokenAuthEntryState> {
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<HTMLInputElement>) => {
// 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 = <Spinner />;
} else {
submitButtonOrSpinner = (
<input type="submit"
className="mx_Dialog_primary"
disabled={!this.state.registrationToken}
value={_t("Continue")}
/>
);
}

let errorSection;
if (this.props.errorText) {
errorSection = (
<div className="error" role="alert">
{ this.props.errorText }
</div>
);
}

return (
<div>
<p>{ _t("Enter a registration token.") }</p>
<form onSubmit={this.onSubmit} className="mx_InteractiveAuthEntryComponents_registrationTokenSection">
<Field
className={registrationTokenBoxClass}
type="text"
name="registrationTokenField"
label={_t("Registration token")}
autoFocus={true}
value={this.state.registrationToken}
onChange={this.onRegistrationTokenFieldChange}
/>
{ errorSection }
<div className="mx_button_row">
{ submitButtonOrSpinner }
</div>
</form>
</div>
);
}
}

interface ISSOAuthEntryProps extends IAuthEntryProps {
continueText?: string;
continueKind?: string;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5b10be8

Please sign in to comment.