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

Support registration tokens #7275

Merged
merged 24 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5b10be8
Support token authenticated registration
govynnus Dec 3, 2021
39c258a
Backwards compatibility with unstable auth type
govynnus Feb 18, 2022
8d3e1d9
Make LOGIN_TYPE public and readonly
govynnus Apr 10, 2022
1ddf830
Update registration-tokens to latest develop
govynnus Apr 10, 2022
f9a3fe8
Remove line related to skinning
govynnus Apr 10, 2022
47e3a7a
Change empty string to null
govynnus Apr 10, 2022
3a30db6
Use "public"s for new code style
govynnus May 12, 2022
e76180e
Merge branch 'develop' into registration-tokens
govynnus May 16, 2022
939a5ec
Change input to AccessibleButton
govynnus May 16, 2022
6fa9204
Add more detail regarding source of token
govynnus May 16, 2022
8e911d6
Merge remote-tracking branch 'upstream/develop' into registration-tokens
govynnus Sep 10, 2022
f489cd5
Fix lint error
govynnus Aug 12, 2022
6cb3260
Change null back to ""
govynnus Sep 10, 2022
3ebb998
Disable submit button when no token entered
govynnus Sep 10, 2022
a19b417
Add test for registration tokens
govynnus Sep 10, 2022
73e0f8a
Merge remote-tracking branch 'upstream/develop' into registration-tokens
govynnus Sep 24, 2022
43a3e4e
Merge remote-tracking branch 'upstream/develop' into registration-tokens
govynnus Oct 19, 2022
1881fa5
Merge remote-tracking branch 'upstream/master' into registration-tokens
govynnus Jan 17, 2023
04911e1
Merge remote-tracking branch 'upstream/develop' into registration-tokens
govynnus Jan 17, 2023
aea870d
Fix linting errors
govynnus Jan 18, 2023
3636932
Fix test for registration tokens
govynnus Jan 18, 2023
a632da7
Merge remote-tracking branch 'upstream/develop' into registration-tokens
govynnus Jan 18, 2023
3a944c0
Merge branch 'develop' into registration-tokens
andybalaam Jan 24, 2023
284ba03
Add missing type
andybalaam Jan 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions src/components/views/auth/InteractiveAuthEntryComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,92 @@ export class MsisdnAuthEntry extends React.Component<IMsisdnAuthEntryProps, IMsi
}
}

interface IRegistrationTokenAuthEntryState {
registrationToken: string;
}

export class RegistrationTokenAuthEntry extends React.Component<IAuthEntryProps, IRegistrationTokenAuthEntryState> {
public static readonly LOGIN_TYPE = AuthType.RegistrationToken;

public constructor(props: IAuthEntryProps) {
super(props);

this.state = {
registrationToken: null,
};
}

public componentDidMount() {
this.props.onPhaseChange(DEFAULT_PHASE);
}

private onSubmit = (e: FormEvent) => {
e.preventDefault();
if (this.props.busy) return;

this.props.submitAuthDict({
// Could be AuthType.RegistrationToken or AuthType.UnstableRegistrationToken
type: this.props.loginType,
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,
});
};

public render() {
const registrationTokenBoxClass = classNames({
"error": this.props.errorText,
});

let submitButtonOrSpinner;
if (this.props.busy) {
submitButtonOrSpinner = <Spinner />;
} else {
submitButtonOrSpinner = (
<AccessibleButton
onClick={this.onSubmit}
kind={this.props.continueKind || 'primary'}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the linter is complaining that the property doesn't exist - we might need to create an interstitial interface which extends IAuthEntryProps to use in the React.Component<> type instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise with continueText below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for taking a look, I did notice that too when I updated it to develop and just remived those properties (don't know if that's OK?), but I forgot to push!

>{ this.props.continueText || _t("Continue") }</AccessibleButton>
);
}

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

return (
<div>
<p>{ _t("Enter a registration token provided by the homeserver administrator.") }</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 @@ -905,6 +991,9 @@ export default function getEntryComponentForLoginType(loginType: AuthType): ISta
return MsisdnAuthEntry;
case AuthType.Terms:
return TermsAuthEntry;
case AuthType.RegistrationToken:
case AuthType.UnstableRegistrationToken:
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 @@ -2986,6 +2986,8 @@
"Please enter the code it contains:": "Please enter the code it contains:",
"Code": "Code",
"Submit": "Submit",
"Enter a registration token provided by the homeserver administrator.": "Enter a registration token provided by the homeserver administrator.",
"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