From 8080b10b3bd92aa8da61d0ae81a4ecfc48745880 Mon Sep 17 00:00:00 2001 From: June <55494127+notdu@users.noreply.github.com> Date: Tue, 27 Jun 2023 23:38:48 +0700 Subject: [PATCH] feat: show code signin page with password disabled (#2021) --- web/src/auth/LoginPage.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/web/src/auth/LoginPage.js b/web/src/auth/LoginPage.js index aa76eb8a..30016e7b 100644 --- a/web/src/auth/LoginPage.js +++ b/web/src/auth/LoginPage.js @@ -49,7 +49,6 @@ class LoginPage extends React.Component { username: null, validEmailOrPhone: false, validEmail: false, - loginMethod: "password", enableCaptchaModal: CaptchaRule.Never, openCaptchaModal: false, verifyCaptcha: undefined, @@ -83,6 +82,8 @@ class LoginPage extends React.Component { componentDidUpdate(prevProps, prevState, snapshot) { if (prevProps.application !== this.props.application) { + this.setState({loginMethod: this.getDefaultLoginMethod(this.props.application)}); + const captchaProviderItems = this.getCaptchaProviderItems(this.props.application); if (captchaProviderItems) { if (captchaProviderItems.some(providerItem => providerItem.rule === "Always")) { @@ -187,6 +188,20 @@ class LoginPage extends React.Component { return this.props.application; } + getDefaultLoginMethod(application) { + if (application.enablePassword) { + return "password"; + } + if (application.enableCodeSignin) { + return "verificationCode"; + } + if (application.enableWebAuthn) { + return "webAuthn"; + } + + return "password"; + } + onUpdateAccount(account) { this.props.onUpdateAccount(account); } @@ -430,7 +445,8 @@ class LoginPage extends React.Component { ); } - if (application.enablePassword) { + const showForm = application.enablePassword || application.enableCodeSignin || application.enableWebAuthn; + if (showForm) { let loginWidth = 320; if (Setting.getLanguage() === "fr") { loginWidth += 20; @@ -515,7 +531,6 @@ class LoginPage extends React.Component { id="input" prefix={} placeholder={(this.state.loginMethod === "verificationCode") ? i18next.t("login:Email or phone") : i18next.t("login:username, Email or phone")} - disabled={!application.enablePassword} onChange={e => { this.setState({ username: e.target.value, @@ -530,7 +545,7 @@ class LoginPage extends React.Component {
- + {i18next.t("login:Auto sign in")} @@ -544,7 +559,6 @@ class LoginPage extends React.Component { type="primary" htmlType="submit" style={{width: "100%", marginBottom: "5px"}} - disabled={!application.enablePassword} > { this.state.loginMethod === "webAuthn" ? i18next.t("login:Sign in with WebAuthn") : @@ -805,14 +819,14 @@ class LoginPage extends React.Component { renderMethodChoiceBox() { const application = this.getApplicationObj(); const items = []; - items.push({label: i18next.t("general:Password"), key: "password"}); + application.enablePassword ? items.push({label: i18next.t("general:Password"), key: "password"}) : null; application.enableCodeSignin ? items.push({label: i18next.t("login:Verification code"), key: "verificationCode"}) : null; application.enableWebAuthn ? items.push({label: i18next.t("login:WebAuthn"), key: "webAuthn"}) : null; - if (application.enableCodeSignin || application.enableWebAuthn) { + if (items.length > 1) { return (
- { + { this.setState({loginMethod: key}); }} centered> @@ -937,7 +951,7 @@ class LoginPage extends React.Component { } const visibleOAuthProviderItems = (application.providers === null) ? [] : application.providers.filter(providerItem => this.isProviderVisible(providerItem)); - if (this.props.preview !== "auto" && !application.enablePassword && visibleOAuthProviderItems.length === 1) { + if (this.props.preview !== "auto" && !application.enablePassword && !application.enableCodeSignin && !application.enableWebAuthn && visibleOAuthProviderItems.length === 1) { Setting.goToLink(Provider.getAuthUrl(application, visibleOAuthProviderItems[0].provider, "signup")); return (