您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

477 行
27 KiB

  1. import { useFormik } from 'formik';
  2. import * as yup from 'yup';
  3. import * as React from "react";
  4. import * as HttpUtils from "utils/HttpUtils";
  5. import * as UrlUtils from "utils/ApiPathConst";
  6. import { useNavigate } from "react-router-dom";
  7. import { useDispatch } from "react-redux";
  8. import { handleLogoutFunction,
  9. // handleLogin
  10. } from 'auth/index';
  11. import useJwt from "auth/jwt/useJwt";
  12. import {
  13. Grid,
  14. Typography,
  15. Button,
  16. // RadioGroup,
  17. // Dialog, DialogTitle, DialogContent, DialogActions,
  18. Stack,
  19. InputLabel,
  20. // OutlinedInput,
  21. FormHelperText,
  22. TextField,
  23. IconButton, InputAdornment,
  24. // Box,
  25. // FormControl
  26. } from '@mui/material';
  27. import Loadable from 'components/Loadable';
  28. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  29. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  30. // import ForwardIcon from '@mui/icons-material/Forward';
  31. import MainCard from 'components/MainCard';
  32. import {PNSPS_LONG_BUTTON_THEME} from "themes/buttonConst";
  33. import {ThemeProvider} from "@emotion/react";
  34. import {FormattedMessage, useIntl} from "react-intl";
  35. import { EyeInvisibleOutlined, EyeOutlined } from '@ant-design/icons';
  36. import axios from 'axios';
  37. import { useParams,Link } from 'react-router-dom';
  38. import CancelOutlinedIcon from '@mui/icons-material/CancelOutlined';
  39. // import LocaleContext from "components/I18nProvider";
  40. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  41. const Index = () => {
  42. const dispatch = useDispatch()
  43. const navigate = useNavigate()
  44. const [showPassword, setShowPassword] = React.useState(false);
  45. const [showConfirmPassword, setshowConfirmPassword] = React.useState(false);
  46. const [isLoading, setLoding] = React.useState(true);
  47. const [verifyState, setVerifyState] = React.useState(null)
  48. const [enterUseEffect, setEnterUseEffect] = React.useState(false)
  49. const [username, setUsername] = React.useState("")
  50. // const { setLocale } = React.useContext(LocaleContext);
  51. const params = useParams()
  52. const intl = useIntl();
  53. React.useEffect(() => {
  54. console.log(params);
  55. setEnterUseEffect(true)
  56. }, []);
  57. React.useEffect(() => {
  58. // console.log("if (enterUseEffect) handleVerify()");
  59. if (enterUseEffect){
  60. handleVerify()
  61. }
  62. }, [enterUseEffect])
  63. const handleVerify = async () => {
  64. console.log(params);
  65. await axios.get(UrlUtils.GET_FORGOT_PASSWORD_VERIFY_USER_ACCOUNT, {
  66. params: {
  67. email: decodeURIComponent(params.email),
  68. emailVerifyHash: decodeURIComponent(params.verifyCode)
  69. }
  70. }).then(
  71. (response)=>{
  72. if (response.status === 200 && response.data) {
  73. console.log(response)
  74. setUsername(response.data.username)
  75. setVerifyState(true)
  76. } else {
  77. setVerifyState(false)
  78. }
  79. setLoding(false)
  80. }
  81. ).catch(error => {
  82. console.log(error)
  83. setVerifyState(false)
  84. setLoding(false)
  85. });
  86. }
  87. const goLogin = async (values) =>{
  88. dispatch(handleLogoutFunction());
  89. HttpUtils.post({
  90. url: UrlUtils.POST_FORGOT_PASSWORD_NEW_PASSWORD,
  91. params:{
  92. username: username,
  93. newPassword: values.password
  94. },
  95. onSuccess: () => {
  96. useJwt
  97. .login({ username: username, password: values.password })
  98. .then((
  99. // response
  100. ) => {
  101. // console.log(response)
  102. navigate('/forgot/password/success');
  103. location.reload()
  104. // setSumitting(false)
  105. })
  106. .catch((error) => {
  107. console.error(error)
  108. });
  109. },
  110. onFail: (response)=>{
  111. console.log("Fail");
  112. console.log(response);
  113. // window.location.assign("/iamsmart/loginFail");
  114. },
  115. onError:(error)=>{
  116. console.log(error);
  117. // window.location.assign("/iamsmart/loginFail");
  118. }
  119. });
  120. }
  121. const BackgroundHead = {
  122. backgroundImage: `url(${titleBackgroundImg})`,
  123. width: 'auto',
  124. height: 'auto',
  125. backgroundSize: 'contain',
  126. backgroundRepeat: 'no-repeat',
  127. backgroundColor: '#0C489E',
  128. backgroundPosition: 'right'
  129. }
  130. const handleClickShowPassword = () => {
  131. setShowPassword(!showPassword);
  132. };
  133. const handleClickShowConfirmPassword = () => {
  134. setshowConfirmPassword(!showConfirmPassword);
  135. };
  136. const handleMouseDownPassword = (event) => {
  137. event.preventDefault();
  138. };
  139. const changePassword = (
  140. // value
  141. ) => {
  142. // const temp = strengthIndicator(value);
  143. // setLevel(strengthColorChi(temp));
  144. };
  145. const formik = useFormik({
  146. enableReinitialize: true,
  147. initialValues: {
  148. // username: '',
  149. password: '',
  150. confirmPassword: '',
  151. // emailVerifyHash: '',
  152. },
  153. validationSchema: yup.object().shape({
  154. // emailVerifyHash: yup.string().required(intl.formatMessage({id: 'requireSecurityCode'})),
  155. // username: yup.string().required(intl.formatMessage({id: 'requireUsername'})),
  156. password: yup.string().min(8, intl.formatMessage({id: 'atLeast8CharPassword'}))
  157. .required(intl.formatMessage({id: 'requirePassword'}))
  158. .matches(/^\S*$/, { message: (intl.formatMessage({id: 'noSpacePassword'}))})
  159. .matches(/^(?=.*[a-z])/, { message: intl.formatMessage({id: 'atLeastOneSmallLetter'})})
  160. .matches(/^(?=.*[A-Z])/, { message: intl.formatMessage({id: 'atLeastOneCapLetter'})})
  161. .matches(/^(?=.*[0-9])/, { message: intl.formatMessage({id: 'atLeast1Number'})})
  162. .matches(/^(?=.*\W)/, { message: intl.formatMessage({id: 'atLeast1SpecialChar'})}),
  163. confirmPassword: yup.string().min(8, intl.formatMessage({id: 'atLeast8CharPassword'}))
  164. .required(intl.formatMessage({id: 'pleaseConfirmPassword'}))
  165. .oneOf([yup.ref('password'), null], intl.formatMessage({id: 'samePassword'})),
  166. }),
  167. onSubmit: values => {
  168. // console.log(values)
  169. goLogin(values)
  170. }
  171. });
  172. const handleCCPChange = (e) => {
  173. e.preventDefault();
  174. };
  175. return (
  176. isLoading || verifyState == null ?
  177. <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
  178. <Grid item>
  179. <LoadingComponent />
  180. </Grid>
  181. </Grid>
  182. :
  183. <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" alignItems="center">
  184. <Grid item xs={12} md={12} width="100%" >
  185. <div style={BackgroundHead}>
  186. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  187. <Typography ml={15} color='#FFF' variant="h4" sx={{display: { xs: 'none', sm: 'none', md: 'block' }}}>
  188. <FormattedMessage id="forgotUserPassword"/>
  189. </Typography>
  190. </Stack>
  191. </div>
  192. </Grid>
  193. {/* <Grid item xs={12} width={{xs:"90%", sm:"90%", md:"60%", lg:"60%"}}>
  194. <Button
  195. aria-label={intl.formatMessage({id: 'back'})}
  196. title={intl.formatMessage({id: 'back'})}
  197. sx={{ ml: 0, mt: 2.5 }} style={{ border: '2px solid' }} variant="outlined" onClick={() => { navigate(-1) }}
  198. >
  199. <ForwardIcon style={{ height: 30, width: 50, transform: "rotate(180deg)" }} />
  200. </Button>
  201. </Grid> */}
  202. {/* <Grid item xs={12}>
  203. <Typography variant="pnspsFormParagraphBold">申請公共啟事</Typography>
  204. </Grid> */}
  205. <Grid item xs={12} md={12} width={{ sx:"90%", sm:"90%",md: "60%", xs: "90%" }}>
  206. <MainCard
  207. sx={{
  208. maxWidth: { xs: 400, sm:730, md:800, lg: 1000 },
  209. margin: { sm: 0, md: 3 },
  210. '& > *': {
  211. flexGrow: 1,
  212. flexBasis: '50%'
  213. }
  214. }}
  215. content={false}
  216. border={false}
  217. boxShadow
  218. >
  219. <form onSubmit={formik.handleSubmit}>
  220. {verifyState ?
  221. // SUCCESS page
  222. <Grid container spacing={4} sx={{ minHeight: {xs:"80vh", sm:"50vh", md: "50vh", lg:"70vh", xl:"50vh"} }} direction="column" justifyContent="flex-start" alignItems="center">
  223. <Grid container direction="column" alignItems="center">
  224. <Grid item xs={12} md={12} lg={12} sx={{ mb: 1, mt:5, }}>
  225. <Typography display="inline" variant="h4">
  226. <FormattedMessage id="verifySuccess"/>
  227. </Typography>
  228. </Grid>
  229. <Grid item xs={12} md={12} lg={12} sx={{ mb: 1,}}>
  230. <InputLabel htmlFor="email-login-title3">
  231. <Typography variant="h5" >
  232. <FormattedMessage id="setNewPassword"/>
  233. </Typography>
  234. </InputLabel>
  235. </Grid>
  236. </Grid>
  237. {/* <Grid item xs={12} md={12} lg={12} width={{xs:"70%", sm:"60%",md:"50%", lg:"50%"}}>
  238. <Grid container direction="row" justifyContent="flex-start">
  239. <Grid item xs={12} md={12} lg={12}>
  240. <TextField
  241. fullWidth
  242. onChange={formik.handleChange}
  243. id="emailVerifyHash"
  244. name="emailVerifyHash"
  245. label={intl.formatMessage({id: 'securityCode'}) + ":"}
  246. placeholder={intl.formatMessage({id: 'securityCode'})}
  247. defaultValue={formik.values.emailVerifyHash}
  248. value={formik.values.emailVerifyHash}
  249. error={Boolean(formik.touched.emailVerifyHash && formik.errors.emailVerifyHash)}
  250. onBlur={formik.handleBlur}
  251. inputProps={{
  252. maxLength: 50,
  253. onKeyDown: (e) => {
  254. if (e.key === 'Enter') {
  255. e.preventDefault();
  256. }
  257. },
  258. }}
  259. InputLabelProps={{
  260. shrink: true
  261. }}
  262. />
  263. </Grid>
  264. {formik.touched.emailVerifyHash && formik.errors.emailVerifyHash && (
  265. <FormHelperText error id="standard-weight-helper-text-username-login">
  266. {formik.errors.emailVerifyHash}
  267. </FormHelperText>
  268. )}
  269. </Grid>
  270. </Grid> */}
  271. <Grid item xs={12} md={12} lg={12} width={{xs:"70%", sm:"60%",md:"50%", lg:"50%"}}>
  272. <Grid container direction="row" justifyContent="flex-start">
  273. <Grid item xs={12} md={12} lg={12}>
  274. <TextField
  275. fullWidth
  276. id="username"
  277. name="username"
  278. label={intl.formatMessage({id: 'userLoginName'}) + ":"}
  279. placeholder={intl.formatMessage({id: 'userLoginName'})}
  280. // defaultValue={username}
  281. value={username}
  282. disabled={true} />
  283. </Grid>
  284. </Grid>
  285. </Grid>
  286. <Grid item xs={12} md={12} lg={12} width={{xs:"70%", sm:"60%",md:"50%", lg:"50%"}}>
  287. <Grid container direction="row" justifyContent="flex-start">
  288. <Grid item xs={12} md={12} lg={12}>
  289. <TextField
  290. fullWidth
  291. autoFocus
  292. onChange={(e) => {
  293. formik.handleChange(e);
  294. changePassword(e.target.value);
  295. }}
  296. id="password"
  297. type={showPassword ? 'text' : 'password'}
  298. name="password"
  299. label={intl.formatMessage({id: 'newPassword'}) + ":"}
  300. placeholder={intl.formatMessage({id: 'newPassword'})}
  301. // defaultValue={formik.values.password.trim()}
  302. value={formik.values.password.trim()}
  303. error={Boolean(formik.touched.password && formik.errors.password)}
  304. onBlur={formik.handleBlur}
  305. inputProps={{
  306. onKeyDown: (e) => {
  307. if (e.key === 'Enter') {
  308. e.preventDefault();
  309. }
  310. },
  311. }}
  312. InputLabelProps={{
  313. shrink: true
  314. }}
  315. InputProps={{
  316. endAdornment:(
  317. <InputAdornment position="end">
  318. <IconButton
  319. aria-label="toggle password visibility"
  320. onClick={handleClickShowPassword}
  321. onMouseDown={handleMouseDownPassword}
  322. edge="end"
  323. size="large"
  324. >
  325. {showPassword ? <EyeOutlined /> : <EyeInvisibleOutlined />}
  326. </IconButton>
  327. </InputAdornment>
  328. )
  329. }}
  330. />
  331. </Grid>
  332. {/* <FormControl fullWidth sx={{ mt: 2 }}>
  333. <Grid container spacing={2} alignItems="center">
  334. <Grid item>
  335. <Box sx={{ bgcolor: level?.color, width: 85, height: 8, borderRadius: '7px' }} />
  336. </Grid>
  337. <Grid item>
  338. <Typography variant="subtitle1">
  339. <FormattedMessage id={level ? level?.label : "pwWeak" }/>
  340. </Typography>
  341. </Grid>
  342. </Grid>
  343. </FormControl> */}
  344. {formik.touched.password && formik.errors.password && (
  345. <FormHelperText error id="helper-text-password-signup">
  346. {formik.errors.password}
  347. </FormHelperText>
  348. )}
  349. </Grid>
  350. </Grid>
  351. <Grid item xs={12} md={12} lg={12} width={{xs:"70%", sm:"60%",md:"50%", lg:"50%"}}>
  352. <Grid container direction="row" justifyContent="flex-start">
  353. <Grid item xs={12} md={12} lg={12}>
  354. <TextField
  355. fullWidth
  356. onChange={(e) => {
  357. formik.handleChange(e);
  358. // changePassword(e.target.value);
  359. }}
  360. id="confirmPassword"
  361. type={showConfirmPassword ? 'text' : 'password'}
  362. name="confirmPassword"
  363. label={intl.formatMessage({id: 'confirmPassword'}) + ":"}
  364. placeholder={intl.formatMessage({id: 'confirmPassword'})}
  365. // defaultValue={formik.values.confirmPassword.trim()}
  366. value={formik.values.confirmPassword.trim()}
  367. error={Boolean(formik.touched.confirmPassword && formik.errors.confirmPassword)}
  368. onBlur={formik.handleBlur}
  369. onCut={handleCCPChange}
  370. onCopy={handleCCPChange}
  371. onPaste={handleCCPChange}
  372. inputProps={{
  373. maxLength: 50,
  374. onKeyDown: (e) => {
  375. if (e.key === 'Enter') {
  376. e.preventDefault();
  377. }
  378. },
  379. }}
  380. InputLabelProps={{
  381. shrink: true
  382. }}
  383. InputProps={{
  384. endAdornment:(
  385. <InputAdornment position="end">
  386. <IconButton
  387. aria-label="toggle password visibility"
  388. onClick={handleClickShowConfirmPassword}
  389. onMouseDown={handleMouseDownPassword}
  390. edge="end"
  391. size="large"
  392. >
  393. {showConfirmPassword ? <EyeOutlined /> : <EyeInvisibleOutlined />}
  394. </IconButton>
  395. </InputAdornment>
  396. )
  397. }}
  398. />
  399. </Grid>
  400. {formik.touched.confirmPassword && formik.errors.confirmPassword && (
  401. <FormHelperText error id="helper-text-confirmPassword-signup">
  402. {formik.errors.confirmPassword}
  403. </FormHelperText>
  404. )}
  405. </Grid>
  406. <Grid container spacing={2} alignItems="center">
  407. <Grid item sx={{ mt: 1 }}>
  408. <Typography variant="subtitle1">
  409. •<FormattedMessage id="pwRemark1" /><br />
  410. •<FormattedMessage id="pwRemark2" /><br />
  411. •<FormattedMessage id="pwRemark3" /><br />
  412. •<FormattedMessage id="pwRemark4" /><br />
  413. •<FormattedMessage id="pwRemark5"/><br />
  414. </Typography>
  415. </Grid>
  416. </Grid>
  417. </Grid>
  418. <Grid item xs={12} md={12} lg={12} mt={1} sx={{mb:3}}>
  419. <ThemeProvider theme={PNSPS_LONG_BUTTON_THEME}>
  420. <Button
  421. aria-label={intl.formatMessage({id: 'confirm'})}
  422. variant="contained"
  423. type="submit"
  424. // onClick={()=>goLogin()}
  425. >
  426. <FormattedMessage id="confirm"/>
  427. </Button>
  428. </ThemeProvider>
  429. </Grid>
  430. </Grid>
  431. :
  432. // ERROR page
  433. <Grid container spacing={4} sx={{ minHeight: {xs:"80vh", sm:"70vh", md: "70vh", lg:"70vh", xl:"50vh"} }} direction="column" justifyContent="flex-start" alignItems="center">
  434. <Grid item xs={12} md={12} lg={12} sx={{ mb: 1, mt:5,}}>
  435. {/* <Button disabled={true} hidden={true} variant="contained" type="submit" sx={{ fontSize: 12,height:'25px'}}>Submit</Button> */}
  436. <CancelOutlinedIcon color="error" sx={{ width: "200px", height: "200px" }} />
  437. </Grid>
  438. <Grid item xs={12} md={12} lg={12} sx={{ mb: 1, mt:5,}}>
  439. <Typography display="inline" variant="h4">
  440. <FormattedMessage id="verifyFail"/>
  441. </Typography>
  442. </Grid>
  443. <Grid item xs={12} md={12} lg={12} sx={{ mb: 1, mt:5,}}>
  444. <Button color="error" variant="outlined" component={Link} to="/login">
  445. <Typography variant="h5">
  446. <FormattedMessage id="backToLogin"/>
  447. </Typography>
  448. </Button>
  449. </Grid>
  450. </Grid>
  451. }
  452. </form>
  453. </MainCard>
  454. </Grid>
  455. </Grid>
  456. );
  457. };
  458. export default Index;