Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

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