| | |
| | | } |
| | | return Promise.reject(new Error(res.data.msg)); |
| | | } |
| | | |
| | | export async function requestResetPassword(_params) { |
| | | const res = await request.post('/auth/reset/password', _params); |
| | | return res.data; |
| | | } |
| | |
| | | } |
| | | }, |
| | | page: { |
| | | welcome: ' Welcome to the RSF Management System.', |
| | | welcome: ' 欢迎使用RSF管理系统', |
| | | login: { |
| | | title: 'Welcome', |
| | | footer: 'Footer Goes Here', |
| | |
| | | InputAdornment, |
| | | IconButton, |
| | | } from '@mui/material'; |
| | | import { updateUserInfo } from '@/api/auth'; |
| | | import { requestResetPassword } from '@/api/auth'; |
| | | import Visibility from '@mui/icons-material/Visibility'; |
| | | import VisibilityOff from '@mui/icons-material/VisibilityOff'; |
| | | |
| | |
| | | }, [userInfo, setValue]) |
| | | |
| | | const onSubmit = (data) => { |
| | | console.log(data); |
| | | return false; |
| | | |
| | | setLoading(true); |
| | | updateUserInfo({ id: userInfo.id, ...data }).then(res => { |
| | | requestResetPassword(data).then(res => { |
| | | setLoading(false); |
| | | const { code, msg, data } = res; |
| | | if (code === 200) { |
| | | notify(msg, { type: 'success', messageArgs: { _: msg } }); |
| | | reset(); |
| | | } else if (code === 408) { |
| | | setError('oldPassword', { |
| | | message: msg, |
| | | }); |
| | | } else { |
| | | notify(msg, { type: 'error', messageArgs: { _: msg } }); |
| | | setError('oldPassword', { |
| | | type: 'server', // make no sense |
| | | message: res.msg, |
| | | }); |
| | | } |
| | | }).catch((error) => { |
| | | setLoading(false); |
| | |
| | | } |
| | | |
| | | @OperationLog("Reset Password") |
| | | @PostMapping("/auth/password") |
| | | @PostMapping("/auth/reset/password") |
| | | public R resetPassword(@RequestBody UpdatePasswordParam param) { |
| | | if (Cools.isEmpty(param.getOldPassword(), param.getPassword())) { |
| | | if (Cools.isEmpty(param.getOldPassword(), param.getNewPassword())) { |
| | | return R.error("Parameters Cannot Be Empty"); |
| | | } |
| | | Long userId = getLoginUserId(); |
| | |
| | | return R.error("Please Login First"); |
| | | } |
| | | if (!userService.comparePassword(userService.getById(userId).getPassword(), param.getOldPassword())) { |
| | | return R.error("The Origin Password Was Incorrect"); |
| | | return R.parse("408-The Current Password Was Incorrect"); |
| | | } |
| | | User user = new User(); |
| | | user.setId(userId); |
| | | user.setPassword(userService.encodePassword(param.getPassword())); |
| | | user.setPassword(userService.encodePassword(param.getNewPassword())); |
| | | if (userService.updateById(user)) { |
| | | return R.ok("Update Success"); |
| | | return R.ok("Reset Password Success"); |
| | | } |
| | | return R.error("Update Fail"); |
| | | return R.error("Reset Password Fail"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | private String oldPassword; |
| | | |
| | | private String password; |
| | | private String newPassword; |
| | | |
| | | } |