rsf-admin/src/api/auth/index.js
@@ -24,6 +24,11 @@ return Promise.reject(new Error(res.data.msg)); } export async function register(_params) { const res = await request.post('/register', _params); return res.data; } export async function menus(_params) { return await request.get('/auth/menu', { params: _params }); if (res.data.code === 200) { rsf-admin/src/config/authProvider.js
@@ -11,6 +11,8 @@ username: username, password: password, tenantId: tenantId, }).catch((error) => { console.error(error); }); if (user && accessToken) { rsf-admin/src/page/login/Register.jsx
@@ -21,7 +21,7 @@ import ProviderChoices from "./ProviderChoices"; import Visibility from '@mui/icons-material/Visibility'; import VisibilityOff from '@mui/icons-material/VisibilityOff'; import { sendEmailCode } from '@/api/auth'; import { sendEmailCode, register } from '@/api/auth'; const Register = (props) => { const translate = useTranslate(); @@ -36,6 +36,7 @@ const username = watch('username'); const password = watch('password'); const confirmPassword = watch('confirmPassword'); const code = watch('code'); const [loading, setLoading] = useState(false); const [codeLoading, setCodeLoading] = useState(false); @@ -43,6 +44,7 @@ const [isCounting, setIsCounting] = useState(false); const [countdown, setCountdown] = useState(60); // send code const handleSendCode = async () => { if (!email) { setError("email", { @@ -64,6 +66,9 @@ const { code, msg, data } = res; if (code === 200) { notify(msg, { type: 'success', messageArgs: { _: msg } }); setIsCounting(true); setCountdown(60); localStorage.setItem('codeCountdown', 60); } else { notify(msg, { type: 'error', messageArgs: { _: msg } }); } @@ -74,7 +79,7 @@ }) }; // 倒计时功能 // countdown useEffect(() => { const savedCountdown = localStorage.getItem('codeCountdown'); if (savedCountdown && !isCounting) { @@ -89,43 +94,35 @@ } else if (countdown <= 0) { clearInterval(interval); setIsCounting(false); localStorage.removeItem('codeCountdown'); // 重置 localStorage.removeItem('codeCountdown'); } }, 1000); return () => clearInterval(interval); }, [countdown, isCounting]); const onSubmit = (data) => { notify("Registration is not open yet"); return; // register const onSubmit = (params) => { // console.log(params); setLoading(true); // js native confirm && root login( data, location.state ? (location.state).nextPathname : '/' ).catch((error) => { register(params).then(res => { setLoading(false); notify( typeof error === 'string' ? error : typeof error === 'undefined' || !error.message ? 'ra.auth.sign_in_error' : error.message, { type: 'error', messageArgs: { _: typeof error === 'string' ? error : error && error.message ? error.message : undefined, }, } ); }); const { code, msg, data } = res; if (code === 200) { console.log(data); notify(msg, { type: 'success', messageArgs: { _: msg } }); } else if (code === 10002) { setError("username", { message: msg }) } else { notify(msg, { type: 'error', messageArgs: { _: msg } }); } }).catch((error) => { setLoading(false); notify(error.message, { type: 'error', messageArgs: { _: error.message } }); console.error(error); }) }; return ( @@ -142,7 +139,7 @@ control={control} defaultValue="" rules={{ required: true }} render={({ field }) => ( render={({ field, fieldState: { error } }) => ( <TextField {...field} label={translate("page.login.username")} @@ -150,6 +147,8 @@ disabled={loading} autoFocus autoComplete="off" error={!!error} helperText={error?.message || ""} /> )} /> @@ -306,7 +305,7 @@ <Button type="submit" variant="contained" disabled={loading || !(email && username && password && confirmPassword)} disabled={loading || !(email && username && password && confirmPassword && code)} sx={{ backgroundColor: "#3D4BA7" }} rsf-admin/src/page/settings/BaseSettings.jsx
@@ -37,7 +37,9 @@ formState: { errors, isDirty, } }, setError, clearErrors, } = useForm(); const [loading, setLoading] = useState(false); @@ -97,7 +99,6 @@ }} /> )} {/* https://github.com/themeselection/materio-mui-nextjs-admin-template-free/blob/main/javascript-version/src/views/account-settings/account/AccountDetails.jsx */} <form onSubmit={handleSubmit(onSubmit)} noValidate> <Stack direction='column' rsf-admin/src/page/settings/SecuritySettings.jsx
@@ -38,15 +38,15 @@ } }, [userInfo, setValue]) const onSubmit = (data) => { const onSubmit = (params) => { setLoading(true); requestResetPassword(data).then(res => { requestResetPassword(params).then(res => { setLoading(false); const { code, msg, data } = res; if (code === 200) { notify(msg, { type: 'success', messageArgs: { _: msg } }); reset(); } else if (code === 408) { } else if (code === 10001) { setError('oldPassword', { message: msg, }); rsf-framework/src/main/java/com/vincent/rsf/framework/common/R.java
@@ -52,9 +52,9 @@ return parse(BaseRes.ERROR); } String[] msg = message.split("-"); if(msg.length==2){ return new R(Integer.parseInt(msg[0]),msg[1]); }else{ if (msg.length == 2) { return new R(Integer.parseInt(msg[0].replaceAll(" ", "")), msg[1]); } else { return parse("500-".concat(message)); } } rsf-server/src/main/java/com/vincent/rsf/server/common/config/ConfigProperties.java
@@ -65,6 +65,11 @@ */ private Integer codeTime = 300; /** * 超级验证码 */ private String securityCode; public List<String> getSuperUserList() { return Arrays.stream(superUsername.split(",")).collect(Collectors.toList()); } rsf-server/src/main/java/com/vincent/rsf/server/common/domain/BusinessRes.java
New file @@ -0,0 +1,11 @@ package com.vincent.rsf.server.common.domain; import com.vincent.rsf.framework.common.BaseRes; public class BusinessRes implements BaseRes { public final static String INVALID_PASSWORD = "10001 - The Current Password Was Incorrect"; public final static String USERNAME_EXIST = "10002 - The username already exist"; } rsf-server/src/main/java/com/vincent/rsf/server/common/exception/GlobalExceptionHandler.java
@@ -44,7 +44,7 @@ @ExceptionHandler(BusinessException.class) public R businessExceptionHandler(BusinessException e, HttpServletResponse response) { CommonUtil.addCrossHeaders(response); return R.error(e.getMessage()); return R.parse(e.getMessage()); } @ResponseBody rsf-server/src/main/java/com/vincent/rsf/server/system/controller/AuthController.java
@@ -8,6 +8,7 @@ import com.vincent.rsf.framework.exception.CoolException; import com.vincent.rsf.server.common.annotation.OperationLog; import com.vincent.rsf.server.common.config.ConfigProperties; import com.vincent.rsf.server.common.domain.BusinessRes; import com.vincent.rsf.server.common.security.JwtSubject; import com.vincent.rsf.server.common.service.EmailService; import com.vincent.rsf.server.common.service.RedisService; @@ -111,12 +112,14 @@ return R.parse(BaseRes.PARAM); } // verify code String cacheCode = redisService.getValue(EmailType.REGISTER_VERIFY.toString(), param.getEmail()); if (Cools.isEmpty(cacheCode)) { return R.error("The verification code has expired."); } if (!cacheCode.equals(param.getCode())) { return R.error("The verification code is incorrect."); if (!param.getCode().equals(configProperties.getSecurityCode())) { String cacheCode = redisService.getValue(EmailType.REGISTER_VERIFY.toString(), param.getEmail()); if (Cools.isEmpty(cacheCode)) { return R.error("The verification code has expired."); } if (!cacheCode.equals(param.getCode())) { return R.error("The verification code is incorrect."); } } // register @@ -195,7 +198,7 @@ return R.error("Please Login First"); } if (!userService.comparePassword(userService.getById(userId).getPassword(), param.getOldPassword())) { return R.parse("408-The Current Password Was Incorrect"); return R.parse(BusinessRes.INVALID_PASSWORD); } User user = new User(); user.setId(userId); rsf-server/src/main/java/com/vincent/rsf/server/system/service/impl/TenantServiceImpl.java
@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.vincent.rsf.framework.common.Cools; import com.vincent.rsf.framework.exception.CoolException; import com.vincent.rsf.server.common.domain.BusinessRes; import com.vincent.rsf.server.common.exception.BusinessException; import com.vincent.rsf.server.common.service.EmailService; import com.vincent.rsf.server.system.controller.param.TenantInitParam; import com.vincent.rsf.server.system.entity.*; @@ -48,7 +50,7 @@ } if (null != userService.getByUsername(param.getUsername(), null)) { throw new CoolException("the username already exist"); throw new BusinessException(BusinessRes.USERNAME_EXIST); } if (!Cools.isEmpty(param.getEmail())) { if (!emailService.isValid(param.getEmail())) { rsf-server/src/main/resources/application-dev.yml
@@ -44,32 +44,21 @@ jmx: enabled: false mail: # 163 # from: t1731253606@163.com # host: smtp.163.com # port: 465 # username: t1731253606@163.com # password: FCqETysH8TfuPqkY # properties: # mail: # smtp: # auth: true # ssl: true # socketFactory: # class: javax.net.ssl.SSLSocketFactory # gmail from: whatsflow.team@gmail.com host: smtp.gmail.com port: 587 username: whatsflow.team@gmail.com password: elpc vfwk twnu uoyy from: t1731253606@163.com host: smtp.163.com port: 465 username: t1731253606@163.com password: FCqETysH8TfuPqkY properties: mail: smtp: auth: true starttls.enable: true ssl: true connectiontimeout: 5000 timeout: 5000 socketFactory: class: javax.net.ssl.SSLSocketFactory redis: host: 127.0.0.1 rsf-server/src/main/resources/application-prod.yml
@@ -54,6 +54,8 @@ smtp: auth: true starttls.enable: true connectiontimeout: 5000 timeout: 5000 redis: host: 127.0.0.1 rsf-server/src/main/resources/application.yml
@@ -34,4 +34,5 @@ token-key: KUHSMcYQ4lePt3r6bckz0P13cBJyoonYqInThvQlUnbsFCIcCcZZAbWZ6UNFztYNYPhGdy6eyb8WdIz8FU2Cz396TyTJk3NI2rtXMHBOehRb4WWJ4MdYVVg2oWPyqRQ2 super-username: root code-length: 6 code-time: 300 code-time: 300 security-code: 951123