diff --git a/controllers/webauthn.go b/controllers/webauthn.go index b364f635..9f11ea65 100644 --- a/controllers/webauthn.go +++ b/controllers/webauthn.go @@ -16,6 +16,7 @@ package controllers import ( "bytes" + "fmt" "io" "github.com/casdoor/casdoor/object" @@ -100,7 +101,7 @@ func (c *ApiController) WebAuthnSigninBegin() { userName := c.Input().Get("name") user := object.GetUserByFields(userOwner, userName) if user == nil { - c.ResponseError("Please Giveout Owner and Username.") + c.ResponseError(fmt.Sprintf("The user: %s/%s doesn't exist", userOwner, userName)) return } options, sessionData, err := webauthnObj.BeginLogin(user) diff --git a/web/craco.config.js b/web/craco.config.js index 0eee20d3..59d04392 100644 --- a/web/craco.config.js +++ b/web/craco.config.js @@ -43,7 +43,7 @@ module.exports = { options: { lessLoaderOptions: { lessOptions: { - modifyVars: {"@primary-color": "rgb(45,120,213)"}, + modifyVars: {"@primary-color": "rgb(45,120,213)", "@border-radius-base": "5px"}, javascriptEnabled: true, }, }, diff --git a/web/src/auth/LoginPage.js b/web/src/auth/LoginPage.js index aa01be9b..862288d4 100644 --- a/web/src/auth/LoginPage.js +++ b/web/src/auth/LoginPage.js @@ -41,7 +41,6 @@ class LoginPage extends React.Component { owner: props.owner !== undefined ? props.owner : (props.match === undefined ? null : props.match.params.owner), application: null, mode: props.mode !== undefined ? props.mode : (props.match === undefined ? null : props.match.params.mode), // "signup" or "signin" - isCodeSignin: false, msg: null, username: null, validEmailOrPhone: false, @@ -349,7 +348,7 @@ class LoginPage extends React.Component { }, { validator: (_, value) => { - if (this.state.isCodeSignin) { + if (this.state.loginMethod === "verificationCode") { if (this.state.email !== "" && !Setting.isValidEmail(this.state.username) && !Setting.isValidPhone(this.state.username)) { this.setState({validEmailOrPhone: false}); return Promise.reject(i18next.t("login:The input is not valid Email or Phone!")); @@ -372,7 +371,7 @@ class LoginPage extends React.Component { } - placeholder={this.state.isCodeSignin ? i18next.t("login:Email or phone") : i18next.t("login:username, Email or phone")} + 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({ @@ -399,29 +398,17 @@ class LoginPage extends React.Component { - { - this.state.loginMethod === "password" ? - ( - - ) : - ( - - ) - } + { this.renderFooter(application) } @@ -479,19 +466,6 @@ class LoginPage extends React.Component { } else { return ( - - { - !application.enableCodeSignin ? null : ( - { - this.setState({ - isCodeSignin: !this.state.isCodeSignin, - }); - }}> - {this.state.isCodeSignin ? i18next.t("login:Sign in with password") : i18next.t("login:Sign in with code")} - - ) - } - { !application.enableSignUp ? null : ( @@ -639,7 +613,23 @@ class LoginPage extends React.Component { renderPasswordOrCodeInput() { const application = this.getApplicationObj(); if (this.state.loginMethod === "password") { - return this.state.isCodeSignin ? ( + return ( + + + } + type="password" + placeholder={i18next.t("login:Password")} + disabled={!application.enablePassword} + /> + + + ); + } else if (this.state.loginMethod === "verificationCode") { + return ( - ) : ( - - - } - type="password" - placeholder={i18next.t("login:Password")} - disabled={!application.enablePassword} - /> - - ); + } else { + return null; } } renderMethodChoiceBox() { const application = this.getApplicationObj(); - if (application.enableWebAuthn) { + if (application.enableCodeSignin || application.enableWebAuthn) { return (
- {this.setState({loginMethod: key});}} centered> + {this.setState({loginMethod: key});}} centered> - + { + !application.enableCodeSignin ? null : ( + + ) + } + { + !application.enableWebAuthn ? null : ( + + ) + }
); diff --git a/web/src/locales/de/data.json b/web/src/locales/de/data.json index 57a5d060..d99d667a 100644 --- a/web/src/locales/de/data.json +++ b/web/src/locales/de/data.json @@ -277,12 +277,12 @@ "Please input your username, Email or phone!": "Bitte geben Sie Ihren Benutzernamen, E-Mail oder Telefon ein!", "Sign In": "Anmelden", "Sign in with WebAuthn": "Sign in with WebAuthn", - "Sign in with code": "Mit Code anmelden", - "Sign in with password": "Mit Passwort anmelden", "Sign in with {type}": "Mit {type} anmelden", "Signing in...": "Anmelden...", "The input is not valid Email or Phone!": "Die Eingabe ist keine gültige E-Mail oder Telefon!", "To access": "Zu Zugriff", + "Verification Code": "Verification Code", + "WebAuthn": "WebAuthn", "sign up now": "jetzt anmelden", "username, Email or phone": "Benutzername, E-Mail oder Telefon" }, diff --git a/web/src/locales/en/data.json b/web/src/locales/en/data.json index fd42752f..135a000a 100644 --- a/web/src/locales/en/data.json +++ b/web/src/locales/en/data.json @@ -277,12 +277,12 @@ "Please input your username, Email or phone!": "Please input your username, Email or phone!", "Sign In": "Sign In", "Sign in with WebAuthn": "Sign in with WebAuthn", - "Sign in with code": "Sign in with code", - "Sign in with password": "Sign in with password", "Sign in with {type}": "Sign in with {type}", "Signing in...": "Signing in...", "The input is not valid Email or Phone!": "The input is not valid Email or Phone!", "To access": "To access", + "Verification Code": "Verification Code", + "WebAuthn": "WebAuthn", "sign up now": "sign up now", "username, Email or phone": "username, Email or phone" }, diff --git a/web/src/locales/fr/data.json b/web/src/locales/fr/data.json index 3c7c7a2c..12bf9af1 100644 --- a/web/src/locales/fr/data.json +++ b/web/src/locales/fr/data.json @@ -277,12 +277,12 @@ "Please input your username, Email or phone!": "Veuillez entrer votre nom d'utilisateur, votre e-mail ou votre téléphone!", "Sign In": "Se connecter", "Sign in with WebAuthn": "Sign in with WebAuthn", - "Sign in with code": "Se connecter avec le code", - "Sign in with password": "Se connecter avec le mot de passe", "Sign in with {type}": "Se connecter avec {type}", "Signing in...": "Connexion en cours...", "The input is not valid Email or Phone!": "L'entrée n'est pas valide Email ou Téléphone !", "To access": "Pour accéder à", + "Verification Code": "Verification Code", + "WebAuthn": "WebAuthn", "sign up now": "inscrivez-vous maintenant", "username, Email or phone": "nom d'utilisateur, e-mail ou téléphone" }, diff --git a/web/src/locales/ja/data.json b/web/src/locales/ja/data.json index 60ca9637..b5736f78 100644 --- a/web/src/locales/ja/data.json +++ b/web/src/locales/ja/data.json @@ -277,12 +277,12 @@ "Please input your username, Email or phone!": "ユーザー名、メールアドレスまたは電話番号を入力してください。", "Sign In": "サインイン", "Sign in with WebAuthn": "Sign in with WebAuthn", - "Sign in with code": "コードでサインイン", - "Sign in with password": "パスワードでサインイン", "Sign in with {type}": "{type} でサインイン", "Signing in...": "サインイン中...", "The input is not valid Email or Phone!": "入力されたメールアドレスまたは電話番号が正しくありません。", "To access": "アクセスするには", + "Verification Code": "Verification Code", + "WebAuthn": "WebAuthn", "sign up now": "今すぐサインアップ", "username, Email or phone": "ユーザー名、メールアドレスまたは電話番号" }, diff --git a/web/src/locales/ko/data.json b/web/src/locales/ko/data.json index 1d03875f..36b82770 100644 --- a/web/src/locales/ko/data.json +++ b/web/src/locales/ko/data.json @@ -277,12 +277,12 @@ "Please input your username, Email or phone!": "Please input your username, Email or phone!", "Sign In": "Sign In", "Sign in with WebAuthn": "Sign in with WebAuthn", - "Sign in with code": "Sign in with code", - "Sign in with password": "Sign in with password", "Sign in with {type}": "Sign in with {type}", "Signing in...": "Signing in...", "The input is not valid Email or Phone!": "The input is not valid Email or Phone!", "To access": "To access", + "Verification Code": "Verification Code", + "WebAuthn": "WebAuthn", "sign up now": "sign up now", "username, Email or phone": "username, Email or phone" }, diff --git a/web/src/locales/ru/data.json b/web/src/locales/ru/data.json index 5fff91c7..f8408816 100644 --- a/web/src/locales/ru/data.json +++ b/web/src/locales/ru/data.json @@ -277,12 +277,12 @@ "Please input your username, Email or phone!": "Пожалуйста, введите ваше имя пользователя, адрес электронной почты или телефон!", "Sign In": "Войти", "Sign in with WebAuthn": "Sign in with WebAuthn", - "Sign in with code": "Войти с помощью кода", - "Sign in with password": "Войти с помощью пароля", "Sign in with {type}": "Войти с помощью {type}", "Signing in...": "Вход...", "The input is not valid Email or Phone!": "Введен неверный адрес электронной почты или телефон!", "To access": "На доступ", + "Verification Code": "Verification Code", + "WebAuthn": "WebAuthn", "sign up now": "зарегистрироваться", "username, Email or phone": "имя пользователя, адрес электронной почты или телефон" }, diff --git a/web/src/locales/zh/data.json b/web/src/locales/zh/data.json index 9790c9ac..705a0be1 100644 --- a/web/src/locales/zh/data.json +++ b/web/src/locales/zh/data.json @@ -277,12 +277,12 @@ "Please input your username, Email or phone!": "请输入您的用户名、Email或手机号!", "Sign In": "登录", "Sign in with WebAuthn": "WebAuthn登录", - "Sign in with code": "验证码登录", - "Sign in with password": "密码登录", "Sign in with {type}": "{type}登录", "Signing in...": "正在登录...", "The input is not valid Email or Phone!": "您输入的电子邮箱格式或手机号有误!", "To access": "访问", + "Verification Code": "验证码", + "WebAuthn": "Web身份验证", "sign up now": "立即注册", "username, Email or phone": "用户名、Email或手机号" },