feat: add terms of use in signin page (#1476)

* feat: extract terms of use renderer

* fix: layout

* fix: form styling

* fix: required state

* feat: application terms of use setting

* fix: refactor getTermsOfUseContent

* fix: refactor renderers
This commit is contained in:
Chell
2023-01-19 11:39:24 +01:00
committed by GitHub
parent f5b7f8cb45
commit d10b1347a8
4 changed files with 127 additions and 67 deletions

View File

@ -53,12 +53,16 @@ class LoginPage extends React.Component {
samlResponse: "",
relayState: "",
redirectUrl: "",
isTermsOfUseVisible: false,
termsOfUseContent: "",
};
if (this.state.type === "cas" && props.match?.params.casApplicationName !== undefined) {
this.state.owner = props.match?.params.owner;
this.state.applicationName = props.match?.params.casApplicationName;
}
this.form = React.createRef();
}
componentDidMount() {
@ -122,7 +126,9 @@ class LoginPage extends React.Component {
this.onUpdateApplication(application);
this.setState({
application: application,
});
}, () => Setting.getTermsOfUseContent(this.state.application.termsOfUse, res => {
this.setState({termsOfUseContent: res});
}));
});
} else {
OrganizationBackend.getDefaultApplication("admin", this.state.owner)
@ -132,7 +138,9 @@ class LoginPage extends React.Component {
this.setState({
application: res.data,
applicationName: res.data.name,
});
}, () => Setting.getTermsOfUseContent(this.state.application.termsOfUse, res => {
this.setState({termsOfUseContent: res});
}));
} else {
this.onUpdateApplication(null);
Setting.showMessage("error", res.msg);
@ -383,6 +391,7 @@ class LoginPage extends React.Component {
onFinish={(values) => {this.onFinish(values);}}
style={{width: "300px"}}
size="large"
ref={this.form}
>
<Form.Item
hidden={true}
@ -456,11 +465,20 @@ class LoginPage extends React.Component {
}
</Row>
<Form.Item>
<Form.Item name="autoSignin" valuePropName="checked" noStyle>
<Checkbox style={{float: "left"}} disabled={!application.enablePassword}>
{i18next.t("login:Auto sign in")}
</Checkbox>
</Form.Item>
{
Setting.isAgreementRequired(application) ?
Setting.renderAgreement(true, () => {
this.setState({
isTermsOfUseVisible: true,
});
}, true) : (
<Form.Item name="autoSignin" valuePropName="checked" noStyle>
<Checkbox style={{float: "left"}} disabled={!application.enablePassword}>
{i18next.t("login:Auto sign in")}
</Checkbox>
</Form.Item>
)
}
{
Setting.renderForgetLink(application, i18next.t("login:Forgot password?"))
}
@ -827,6 +845,19 @@ class LoginPage extends React.Component {
{
this.renderForm(application)
}
{
Setting.renderModal(this.state.isTermsOfUseVisible, () => {
this.form.current.setFieldsValue({agreement: true});
this.setState({
isTermsOfUseVisible: false,
});
}, () => {
this.form.current.setFieldsValue({agreement: false});
this.setState({
isTermsOfUseVisible: false,
});
}, this.state.termsOfUseContent)
}
</div>
</div>
</div>