feat: fix bug in signup and reset phone and email (#1396)

* fix: fix bug in signup and reset phone and email

* delete useless addition
This commit is contained in:
Mr Forest 2022-12-11 15:52:36 +08:00 committed by GitHub
parent ef836acfe9
commit eca2527bc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 6 deletions

View File

@ -47,6 +47,7 @@ func (c *ApiController) SendVerificationCode() {
checkKey := c.Ctx.Request.Form.Get("checkKey")
checkUser := c.Ctx.Request.Form.Get("checkUser")
applicationId := c.Ctx.Request.Form.Get("applicationId")
method := c.Ctx.Request.Form.Get("method")
remoteAddr := util.GetIPFromRequest(c.Ctx.Request)
if destType == "" {
@ -119,7 +120,7 @@ func (c *ApiController) SendVerificationCode() {
}
userByEmail := object.GetUserByEmail(organization.Name, dest)
if userByEmail == nil {
if userByEmail == nil && method != "signup" && method != "reset" {
c.ResponseError(c.T("verification:the user does not exist, please sign up first"))
return
}
@ -136,7 +137,7 @@ func (c *ApiController) SendVerificationCode() {
}
userByPhone := object.GetUserByPhone(organization.Name, dest)
if userByPhone == nil {
if userByPhone == nil && method != "signup" && method != "reset" {
c.ResponseError(c.T("verification:the user does not exist, please sign up first"))
return
}

View File

@ -92,6 +92,7 @@ export const ResetModal = (props) => {
<CountDownInput
textBefore={i18next.t("code:Code You Received")}
onChange={setCode}
method={"reset"}
onButtonClickArgs={[dest, destType, Setting.getApplicationName(application)]}
application={application}
/>

View File

@ -355,12 +355,14 @@ class ForgetPage extends React.Component {
{this.state.verifyType === "email" ? (
<CountDownInput
disabled={this.state.username === "" || this.state.verifyType === ""}
method={"forget"}
onButtonClickArgs={[this.state.email, "email", Setting.getApplicationName(this.state.application), this.state.name]}
application={application}
/>
) : (
<CountDownInput
disabled={this.state.username === "" || this.state.verifyType === ""}
method={"forget"}
onButtonClickArgs={[this.state.phone, "phone", Setting.getApplicationName(this.state.application), this.state.name]}
application={application}
/>

View File

@ -725,6 +725,7 @@ class LoginPage extends React.Component {
>
<CountDownInput
disabled={this.state.username?.length === 0 || !this.state.validEmailOrPhone}
method={"login"}
onButtonClickArgs={[this.state.username, this.state.validEmail ? "email" : "phone", Setting.getApplicationName(application)]}
application={application}
/>

View File

@ -373,6 +373,7 @@ class SignupPage extends React.Component {
>
<CountDownInput
disabled={!this.state.validEmail}
method={"signup"}
onButtonClickArgs={[this.state.email, "email", Setting.getApplicationName(application)]}
application={application}
/>
@ -426,6 +427,7 @@ class SignupPage extends React.Component {
>
<CountDownInput
disabled={!this.state.validPhone}
method={"signup"}
onButtonClickArgs={[this.state.phone, "phone", Setting.getApplicationName(application)]}
application={application}
/>

View File

@ -109,11 +109,12 @@ export function setPassword(userOwner, userName, oldPassword, newPassword) {
}).then(res => res.json());
}
export function sendCode(checkType, checkId, checkKey, dest, type, applicationId, checkUser) {
export function sendCode(checkType, checkId, checkKey, method, dest, type, applicationId, checkUser) {
const formData = new FormData();
formData.append("checkType", checkType);
formData.append("checkId", checkId);
formData.append("checkKey", checkKey);
formData.append("method", method);
formData.append("dest", dest);
formData.append("type", type);
formData.append("applicationId", applicationId);

View File

@ -22,7 +22,7 @@ import {CaptchaWidget} from "./CaptchaWidget";
const {Search} = Input;
export const CountDownInput = (props) => {
const {disabled, textBefore, onChange, onButtonClickArgs, application} = props;
const {disabled, textBefore, onChange, onButtonClickArgs, application, method} = props;
const [visible, setVisible] = React.useState(false);
const [key, setKey] = React.useState("");
const [captchaImg, setCaptchaImg] = React.useState("");
@ -53,7 +53,7 @@ export const CountDownInput = (props) => {
const handleOk = () => {
setVisible(false);
setButtonLoading(true);
UserBackend.sendCode(checkType, checkId, key, ...onButtonClickArgs).then(res => {
UserBackend.sendCode(checkType, checkId, key, method, ...onButtonClickArgs).then(res => {
setKey("");
setButtonLoading(false);
if (res) {
@ -70,7 +70,7 @@ export const CountDownInput = (props) => {
const loadCaptcha = () => {
UserBackend.getCaptcha(application.owner, application.name, false).then(res => {
if (res.type === "none") {
UserBackend.sendCode("none", "", "", ...onButtonClickArgs).then(res => {
UserBackend.sendCode("none", "", "", method, ...onButtonClickArgs).then(res => {
if (res) {
handleCountDown(60);
}