From 7709b5bec4c7f0af65c3c1d2df0d48ed60d451c6 Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 11 Sep 2023 09:38:31 +0800 Subject: [PATCH] add captcha --- .../auth-forms/BusCustomFormWizard.js | 48 ++++++++++++++++++- src/utils/ApiPathConst.js | 1 + 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/pages/authentication/auth-forms/BusCustomFormWizard.js b/src/pages/authentication/auth-forms/BusCustomFormWizard.js index a0bd207..65eb356 100644 --- a/src/pages/authentication/auth-forms/BusCustomFormWizard.js +++ b/src/pages/authentication/auth-forms/BusCustomFormWizard.js @@ -30,7 +30,7 @@ import * as yup from 'yup'; import { strengthColorChi, strengthIndicator } from 'utils/password-strength'; // import {apiPath} from "auth/utils"; import axios from "axios"; -import {POST_PUBLIC_USER_REGISTER} from "utils/ApiPathConst"; +import {POST_PUBLIC_USER_REGISTER, POST_CAPTCHA} from "utils/ApiPathConst"; // import * as HttpUtils from 'utils/HttpUtils'; import Loadable from 'components/Loadable'; @@ -47,6 +47,8 @@ import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline'; import CancelOutlinedIcon from '@mui/icons-material/CancelOutlined'; import { Link } from 'react-router-dom'; +import * as HttpUtils from "../../../utils/HttpUtils" +//import { Invaild } from 'utils/IconUtils'; // ============================|| FIREBASE - REGISTER ||============================ // const BusCustomFormWizard = (props) => { @@ -60,6 +62,9 @@ const BusCustomFormWizard = (props) => { const [isLoading, setLoding] = useState(true); const [updateRows, setUpdateRows] = useState([]); + const [captcha, setCaptcha] = useState([]); + const [captchaImg, setCaptchaImage] = useState([]); + const handleClickShowPassword = () => { setShowPassword(!showPassword); }; @@ -99,6 +104,26 @@ const BusCustomFormWizard = (props) => { useEffect(() => { changePassword(''); + + // if (localStorage.getItem('checkCode') != null){ + // setCaptcha(localStorage.getItem('checkCode')); + // setCaptchaImage(localStorage.getItem('base64Url')); + // localStorage.setItem("checkCode",null); + // localStorage.setItem("base64Url",null); + // }else{ + HttpUtils.post({ + url: POST_CAPTCHA, + params:{width: 100, height: 40}, + onSuccess:(responseData)=>{ + localStorage.setItem("checkCode",responseData.checkCode); + localStorage.setItem("base64Url",responseData.base64Url); + setCaptcha(localStorage.getItem('checkCode')); + setCaptchaImage(localStorage.getItem('base64Url')); + } + }); + // } + + }, []); const checkDataField = (data)=> { @@ -391,6 +416,7 @@ const BusCustomFormWizard = (props) => { fax: yup.string().min(8,'請輸入最少8位數字'), brExpiryDate: yup.string().min(8,'請輸入商業登記證有效日期'), brNo: yup.string().min(8,'請輸入商業登記證號碼'), + captchaField: yup.string().test("match", "Invalid", function(val){return val == captcha;}) }) }); @@ -1030,6 +1056,26 @@ const BusCustomFormWizard = (props) => { + + + + + + + { + const value = event.target.value; + formik.setFieldValue("captchaField",value); + }} + sx={{width:'75%'}} + /> + + + diff --git a/src/utils/ApiPathConst.js b/src/utils/ApiPathConst.js index e148ada..a20a5a5 100644 --- a/src/utils/ApiPathConst.js +++ b/src/utils/ApiPathConst.js @@ -35,6 +35,7 @@ export const GET_FILE_DELETE = apiPath+'/file/delete'; // POST request //Login export const POST_LOGIN = '/login'; +export const POST_CAPTCHA = apiPath+'/captcha'; //register export const POST_PUBLIC_USER_REGISTER = apiPath+'/user/register';