基础结构修改,以及基础接口添加完善逻辑

This commit is contained in:
2025-10-23 20:50:50 +08:00
parent 79fe209d4f
commit 879332a785
21 changed files with 416 additions and 100 deletions

13
pom.xml
View File

@@ -46,6 +46,9 @@
<sendgrid.version>4.10.3</sendgrid.version> <sendgrid.version>4.10.3</sendgrid.version>
<gson.version>2.12.1</gson.version> <gson.version>2.12.1</gson.version>
<httpmime.version>4.5.14</httpmime.version>
<Java-WebSocket.version>1.5.4</Java-WebSocket.version>
<twilio.version>10.1.1</twilio.version>
</properties> </properties>
@@ -301,13 +304,19 @@
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId> <artifactId>httpmime</artifactId>
<version>4.5.14</version> <version>${httpmime.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.java-websocket</groupId> <groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId> <artifactId>Java-WebSocket</artifactId>
<version>1.5.4</version> <!-- 最新版本可到 Maven 仓库查询 --> <version>${Java-WebSocket.version}</version>
</dependency>
<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<version>${twilio.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -45,19 +45,6 @@ public class ChatWebSocketHandler {
// @Value("${whisper.language}") // @Value("${whisper.language}")
private String language = "en"; private String language = "en";
/**
* 16kHz
*/
private static final int SAMPLE_RATE = 16000;
/**
* 4 KB 每次读取
*/
private static final int BUFFER_SIZE = 4096;
/**
* 每样本 16 位
*/
private static final int BITS_PER_SAMPLE = 16;
/** /**
* 缓存客户端流式解析的语音文本数据 * 缓存客户端流式解析的语音文本数据
*/ */

View File

@@ -1,8 +1,10 @@
package com.vetti.web.controller.system; package com.vetti.web.controller.system;
import java.util.Date; import java.util.*;
import java.util.List;
import java.util.Set; import com.vetti.common.utils.MessageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@@ -29,6 +31,7 @@ import com.vetti.system.service.ISysMenuService;
* *
* @author ruoyi * @author ruoyi
*/ */
@Api(tags ="登录模块")
@RestController @RestController
public class SysLoginController public class SysLoginController
{ {
@@ -53,6 +56,7 @@ public class SysLoginController
* @param loginBody 登录信息 * @param loginBody 登录信息
* @return 结果 * @return 结果
*/ */
@ApiOperation("登录方法")
@PostMapping("/login") @PostMapping("/login")
public AjaxResult login(@RequestBody LoginBody loginBody) public AjaxResult login(@RequestBody LoginBody loginBody)
{ {
@@ -69,6 +73,7 @@ public class SysLoginController
* *
* @return 用户信息 * @return 用户信息
*/ */
@ApiOperation("获取用户信息")
@GetMapping("getInfo") @GetMapping("getInfo")
public AjaxResult getInfo() public AjaxResult getInfo()
{ {
@@ -84,11 +89,13 @@ public class SysLoginController
tokenService.refreshToken(loginUser); tokenService.refreshToken(loginUser);
} }
AjaxResult ajax = AjaxResult.success(); AjaxResult ajax = AjaxResult.success();
ajax.put("user", user); Map mapInfo = new HashMap();
ajax.put("roles", roles); mapInfo.put("user", user);
ajax.put("permissions", permissions); mapInfo.put("roles", roles);
ajax.put("isDefaultModifyPwd", initPasswordIsModify(user.getPwdUpdateDate())); mapInfo.put("permissions", permissions);
ajax.put("isPasswordExpired", passwordIsExpiration(user.getPwdUpdateDate())); mapInfo.put("isDefaultModifyPwd", initPasswordIsModify(user.getPwdUpdateDate()));
mapInfo.put("isPasswordExpired", passwordIsExpiration(user.getPwdUpdateDate()));
ajax.put("data", mapInfo);
return ajax; return ajax;
} }
@@ -97,6 +104,7 @@ public class SysLoginController
* *
* @return 路由信息 * @return 路由信息
*/ */
@ApiOperation("获取路由信息")
@GetMapping("getRouters") @GetMapping("getRouters")
public AjaxResult getRouters() public AjaxResult getRouters()
{ {
@@ -128,4 +136,19 @@ public class SysLoginController
} }
return false; return false;
} }
/**
* 忘记密码
*
* @param loginBody 登录信息
* @return 结果
*/
@ApiOperation("忘记密码")
@PostMapping("/forgotPassword")
public AjaxResult handlePassword(@RequestBody LoginBody loginBody)
{
loginService.resetPassword(loginBody.getUsername(),loginBody.getPassword(),loginBody.getRepeatPassword(),loginBody.getCode(),loginBody.getUuid());
return AjaxResult.success(MessageUtils.messageCustomize("systemCommonTip10001"));
}
} }

View File

@@ -1,5 +1,7 @@
package com.vetti.web.controller.system; package com.vetti.web.controller.system;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -16,23 +18,19 @@ import com.vetti.system.service.ISysConfigService;
* *
* @author ruoyi * @author ruoyi
*/ */
@Api(tags ="注册验证模块")
@RestController @RestController
public class SysRegisterController extends BaseController public class SysRegisterController extends BaseController
{ {
@Autowired @Autowired
private SysRegisterService registerService; private SysRegisterService registerService;
@Autowired @ApiOperation("注册方法")
private ISysConfigService configService;
@PostMapping("/register") @PostMapping("/register")
public AjaxResult register(@RequestBody RegisterBody user) public AjaxResult register(@RequestBody RegisterBody user)
{ {
if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser"))))
{
return error("当前系统没有开启注册功能!");
}
String msg = registerService.register(user); String msg = registerService.register(user);
return StringUtils.isEmpty(msg) ? success() : error(msg); return StringUtils.isEmpty(msg) ? success() : error(msg);
} }
} }

View File

@@ -0,0 +1,58 @@
package com.vetti.web.controller.system;
import cn.hutool.core.collection.CollectionUtil;
import com.vetti.common.core.controller.BaseController;
import com.vetti.common.core.domain.R;
import com.vetti.common.exception.ServiceException;
import com.vetti.common.service.verification.VerificationEmailService;
import com.vetti.common.utils.MessageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* @author ID
* @date 2025/8/28 16:16
*/
@Api(tags ="邮箱验证码")
@RestController
@RequestMapping("/verificationEmail")
@RequiredArgsConstructor
public class VerificationEmailController extends BaseController {
@Resource
private final VerificationEmailService verificationEmailService;
@ApiOperation("发送验证码(标题、内容走的配置文件)")
@PostMapping("/send")
public R sendVerificationCode(@RequestParam String email) {
boolean isSent = verificationEmailService.sendVerificationEm7941VerificationCode(email);
if (isSent) {
return R.ok(MessageUtils.messageCustomize("systemVerificationEmailController10001"));
} else {
return R.fail(MessageUtils.messageCustomize("systemVerificationEmailController10002"));
}
}
/**
* 验证邮箱验证码
*/
@PostMapping("/verify")
public R verifyCode(@RequestParam String email, @RequestParam String code) {
boolean isValid = verificationEmailService.verifyCode(email, code);
if (isValid) {
return R.ok(MessageUtils.messageCustomize("systemVerificationEmailController10003"));
} else {
return R.fail(MessageUtils.messageCustomize("systemVerificationEmailController10004"));
}
}
}

View File

@@ -135,6 +135,10 @@ twilio:
from-name: RouteZ from-name: RouteZ
template-ids: template-ids:
routez-verification-code: d-321fee8a85704983849eb1f69313ae24 routez-verification-code: d-321fee8a85704983849eb1f69313ae24
accountSID: 1111
authToken: 22222
sendPhoneNumber: 33333
verification: verification:
code: code:
email: email:
@@ -148,6 +152,7 @@ elevenLabs:
# apiKey: sk_5240d8f56cb1eb5225fffcf903f62479884d1af5b3de6812 # apiKey: sk_5240d8f56cb1eb5225fffcf903f62479884d1af5b3de6812
apiKey: sk_88f5a560e1bbde0e5b8b6b6eb1812163a98bfb98554acbec apiKey: sk_88f5a560e1bbde0e5b8b6b6eb1812163a98bfb98554acbec
modelId: eleven_turbo_v2_5 modelId: eleven_turbo_v2_5
# 语音转文本 # 语音转文本
whisper: whisper:
apiUrl: https://api.openai.com/v1/audio/transcriptions apiUrl: https://api.openai.com/v1/audio/transcriptions

View File

@@ -37,6 +37,21 @@ systemVerificationEmailController10004 = The Verification Code Is Invalid Or Has
SystemCommandOverhaulAppController10001 = Operation Successful SystemCommandOverhaulAppController10001 = Operation Successful
systemSysLoginService10001 = The username cannot be empty
systemSysLoginService10002 = User password cannot be empty
systemSysLoginService10003 = User does not exist
systemSysLoginService10004 = Passwords do not match
systemSysRegisterService10001 = The username cannot be empty
systemSysRegisterService10002 = User password cannot be empty
systemSysRegisterService10003 = The account length must be between 2 and 20 characters
systemSysRegisterService10004 = The password length must be between 5 and 20 characters
systemSysRegisterService10005 = Save User
systemSysRegisterService10006 = Failed, registered account already exists
systemSysRegisterService10007 = Registration failed, please contact the system administrator
systemEmailUtil10001 = Sending Email Failed systemEmailUtil10001 = Sending Email Failed
systemR10001 = Operation Successful systemR10001 = Operation Successful

View File

@@ -37,6 +37,19 @@ systemVerificationEmailController10004 = 验证码无效或已过期
SystemCommandOverhaulAppController10001 = 操作成功 SystemCommandOverhaulAppController10001 = 操作成功
systemSysLoginService10001 = 用户名不能为空
systemSysLoginService10002 = 用户密码不能为空
systemSysLoginService10003 = 用户不存在
systemSysLoginService10004 = 密码不一致
systemSysRegisterService10001 = 用户名不能为空
systemSysRegisterService10002 = 用户密码不能为空
systemSysRegisterService10003 = 账户长度必须在2到20个字符之间
systemSysRegisterService10004 = 密码长度必须在5到20个字符之间
systemSysRegisterService10005 = 保存用户
systemSysRegisterService10006 = 失败,注册账号已存在
systemSysRegisterService10007 = 注册失败,请联系系统管理人员
systemEmailUtil10001 = 发送邮件失败 systemEmailUtil10001 = 发送邮件失败
systemR10001 = 操作成功 systemR10001 = 操作成功

View File

@@ -143,18 +143,22 @@
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.squareup.okhttp3</groupId> <groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId> <artifactId>okhttp</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.minio</groupId> <groupId>io.minio</groupId>
<artifactId>minio</artifactId> <artifactId>minio</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sendgrid</groupId> <groupId>com.sendgrid</groupId>
<artifactId>sendgrid-java</artifactId> <artifactId>sendgrid-java</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.code.gson</groupId> <groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId> <artifactId>gson</artifactId>
@@ -175,6 +179,11 @@
<artifactId>tomcat-embed-websocket</artifactId> <artifactId>tomcat-embed-websocket</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
</dependency>
</dependencies> </dependencies>

View File

@@ -15,6 +15,9 @@ public class TwilioConfig {
private String apiKey; private String apiKey;
private String fromEmail; private String fromEmail;
private String fromName; private String fromName;
private String fromEmailEm7941;
private String fromNameEm7941;
private String replyToEm7941;
private TemplateIds templateIds; private TemplateIds templateIds;

View File

@@ -83,8 +83,9 @@ public class BaseController
{ {
TableDataInfo rspData = new TableDataInfo(); TableDataInfo rspData = new TableDataInfo();
rspData.setCode(HttpStatus.SUCCESS); rspData.setCode(HttpStatus.SUCCESS);
rspData.setMsg("查询成功"); rspData.setSuccess(true);
rspData.setRows(list); rspData.setMessage("查询成功");
rspData.setDatas(list);
rspData.setTotal(new PageInfo(list).getTotal()); rspData.setTotal(new PageInfo(list).getTotal());
return rspData; return rspData;
} }

View File

@@ -2,6 +2,8 @@ package com.vetti.common.core.domain;
import java.util.HashMap; import java.util.HashMap;
import java.util.Objects; import java.util.Objects;
import cn.hutool.core.date.DateUtil;
import com.vetti.common.constant.HttpStatus; import com.vetti.common.constant.HttpStatus;
import com.vetti.common.utils.StringUtils; import com.vetti.common.utils.StringUtils;
@@ -18,11 +20,23 @@ public class AjaxResult<T> extends HashMap<String, Object>
public static final String CODE_TAG = "code"; public static final String CODE_TAG = "code";
/** 返回内容 */ /** 返回内容 */
public static final String MSG_TAG = "msg"; public static final String MSG_TAG = "message";
/** 数据对象 */ /** 数据对象 */
public static final String DATA_TAG = "data"; public static final String DATA_TAG = "data";
/**
* 请求返回时间
*/
public static final String DATE_TIME = "timestamp";
/**
* 成功状态标识
*/
public static final String SUCCESS = "success";
/** /**
* 初始化一个新创建的 AjaxResult 对象,使其表示一个空消息。 * 初始化一个新创建的 AjaxResult 对象,使其表示一个空消息。
*/ */
@@ -40,6 +54,12 @@ public class AjaxResult<T> extends HashMap<String, Object>
{ {
super.put(CODE_TAG, code); super.put(CODE_TAG, code);
super.put(MSG_TAG, msg); super.put(MSG_TAG, msg);
super.put(DATE_TIME, DateUtil.now());
if(HttpStatus.SUCCESS == code){
super.put(SUCCESS, true);
}else {
super.put(SUCCESS, false);
}
} }
/** /**
@@ -53,10 +73,17 @@ public class AjaxResult<T> extends HashMap<String, Object>
{ {
super.put(CODE_TAG, code); super.put(CODE_TAG, code);
super.put(MSG_TAG, msg); super.put(MSG_TAG, msg);
super.put(DATE_TIME, DateUtil.now());
if(HttpStatus.SUCCESS == code){
super.put(SUCCESS, true);
}else {
super.put(SUCCESS, false);
}
if (StringUtils.isNotNull(data)) if (StringUtils.isNotNull(data))
{ {
super.put(DATA_TAG, data); super.put(DATA_TAG, data);
} }
} }
/** /**

View File

@@ -1,25 +1,38 @@
package com.vetti.common.core.domain.model; package com.vetti.common.core.domain.model;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/** /**
* 用户登录对象 * 用户登录对象
* *
* @author ruoyi * @author ruoyi
*/ */
@Data
public class LoginBody public class LoginBody
{ {
/** /**
* 用户名 * 用户名
*/ */
@ApiModelProperty("用户名")
private String username; private String username;
/** /**
* 用户密码 * 用户密码
*/ */
@ApiModelProperty("用户密码")
private String password; private String password;
/**
* 确认密码
*/
@ApiModelProperty("确认密码")
private String repeatPassword;
/** /**
* 验证码 * 验证码
*/ */
@ApiModelProperty("验证码")
private String code; private String code;
/** /**
@@ -27,43 +40,4 @@ public class LoginBody
*/ */
private String uuid; private String uuid;
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public String getCode()
{
return code;
}
public void setCode(String code)
{
this.code = code;
}
public String getUuid()
{
return uuid;
}
public void setUuid(String uuid)
{
this.uuid = uuid;
}
} }

View File

@@ -16,13 +16,18 @@ public class TableDataInfo implements Serializable
private long total; private long total;
/** 列表数据 */ /** 列表数据 */
private List<?> rows; private List<?> datas;
/** 消息状态码 */ /** 消息状态码 */
private int code; private int code;
/** 消息内容 */ /** 消息内容 */
private String msg; private String message;
/**
* 成功标识
*/
private Boolean success;
/** /**
* 表格数据对象 * 表格数据对象
@@ -39,7 +44,7 @@ public class TableDataInfo implements Serializable
*/ */
public TableDataInfo(List<?> list, long total) public TableDataInfo(List<?> list, long total)
{ {
this.rows = list; this.datas = list;
this.total = total; this.total = total;
} }
@@ -53,14 +58,14 @@ public class TableDataInfo implements Serializable
this.total = total; this.total = total;
} }
public List<?> getRows() public List<?> getDatas()
{ {
return rows; return datas;
} }
public void setRows(List<?> rows) public void setDatas(List<?> rows)
{ {
this.rows = rows; this.datas = rows;
} }
public int getCode() public int getCode()
@@ -73,13 +78,21 @@ public class TableDataInfo implements Serializable
this.code = code; this.code = code;
} }
public String getMsg() public String getMessage()
{ {
return msg; return message;
} }
public void setMsg(String msg) public void setMessage(String message)
{ {
this.msg = msg; this.message = message;
}
public Boolean getSuccess() {
return success;
}
public void setSuccess(Boolean success) {
this.success = success;
} }
} }

View File

@@ -20,6 +20,14 @@ public interface VerificationEmailService {
*/ */
boolean sendVerificationRoutezVerificationCode(String email); boolean sendVerificationRoutezVerificationCode(String email);
/**
* 使用 em7941.routez.app 域名发送验证码(官网模板)
*
* @param email 收件人邮箱
* @return
*/
boolean sendVerificationEm7941VerificationCode(String email);
/** /**
* 发动邮箱验证码 (内容走的官网配置模板) * 发动邮箱验证码 (内容走的官网配置模板)
* *

View File

@@ -66,6 +66,27 @@ public class VerificationEmailServiceImpl implements VerificationEmailService {
twilioConfig.getTemplateIds().getRoutezVerificationCode(), template); twilioConfig.getTemplateIds().getRoutezVerificationCode(), template);
} }
/**
* 使用 em7941.routez.app 域名发送验证码(官网模板)
*/
@Override
public boolean sendVerificationEm7941VerificationCode(String email) {
String code = generateVerificationCode();
RoutezVerificationCodeTemplate template = new RoutezVerificationCodeTemplate();
template.setVerification_code(code);
template.setVerification_expiration(verificationConfig.getExpirationMinutes());
try {
redisCache.setCacheObject(CacheConstants.VERIFICATION_EMAIL_CODE_KEY + email, code,
verificationConfig.getExpirationMinutes(), TimeUnit.MINUTES);
emailUtil.sendEmailByEm7941(email, twilioConfig.getTemplateIds().getRoutezVerificationCode(), template);
return true;
} catch (Exception e) {
// 记录日志
e.printStackTrace();
return false;
}
}
/** /**
* 发动邮箱验证码 (内容走的官网配置模板) * 发动邮箱验证码 (内容走的官网配置模板)
* *

View File

@@ -13,6 +13,7 @@ import com.sendgrid.helpers.mail.Mail;
import com.sendgrid.helpers.mail.objects.Content; import com.sendgrid.helpers.mail.objects.Content;
import com.sendgrid.helpers.mail.objects.Email; import com.sendgrid.helpers.mail.objects.Email;
import com.sendgrid.helpers.mail.objects.Personalization; import com.sendgrid.helpers.mail.objects.Personalization;
import com.vetti.common.utils.StringUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
@@ -111,4 +112,34 @@ public class EmailUtil {
mail.addPersonalization(personalization); mail.addPersonalization(personalization);
} }
/**
* 使用 em7941.routez.app 域名发送模板邮件
*/
public void sendEmailByEm7941(String toEmail, String templateId, BaseTemplateEmail templateEmail) throws IOException {
Email from = new Email(twilioConfig.getFromEmailEm7941(), twilioConfig.getFromNameEm7941());
Email to = new Email(toEmail);
Content emailContent = new Content("text/html", " ");
Mail mail = new Mail();
mail.setFrom(from);
mail.addContent(emailContent);
if (StringUtils.isNotEmpty(twilioConfig.getReplyToEm7941())) {
mail.setReplyTo(new Email(twilioConfig.getReplyToEm7941()));
}
template(to, mail, templateId, templateEmail);
SendGrid sg = new SendGrid(twilioConfig.getApiKey());
Request request = new Request();
request.setMethod(Method.POST);
request.setEndpoint("mail/send");
request.setBody(mail.build());
Response response = sg.api(request);
if (response.getStatusCode() >= 400) {
throw new RuntimeException(MessageUtils.messageCustomize("systemEmailUtil10001")+": " + response.getBody());
}
}
} }

View File

@@ -0,0 +1,57 @@
package com.vetti.common.utils.sms;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;
/**
* 短信发送工具类
* @author wangxiangshun
* @date 2025/10/22 22:36
*/
@Component
public class TwilioSmsUtil {
/**
* 你的AccountSID
*/
@Value("${twilio.accountSID}")
public String ACCOUNT_SID;
/**
* 你的AuthToken
*/
@Value("${twilio.authToken}")
public String AUTH_TOKEN;
/**
* 发送手机号号码
*/
@Value("${twilio.sendPhoneNumber}")
private String sendPhoneNumber;
/**
*
* @param phoneNumber 接收手机号
* @param msg 短信内容
*/
public void send(String phoneNumber, String msg) {
// 初始化
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
// 发送短信
Message message = Message.creator(
new PhoneNumber(phoneNumber), // 收信号码(目标号码)
new PhoneNumber(sendPhoneNumber), // Twilio 提供的号码(发信号码)
msg
).create();
// 打印发送结果
System.out.println("短信已发送SID" + message.getSid());
}
}

View File

@@ -1,6 +1,8 @@
package com.vetti.framework.web.service; package com.vetti.framework.web.service;
import javax.annotation.Resource; import javax.annotation.Resource;
import com.vetti.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.BadCredentialsException;
@@ -64,7 +66,7 @@ public class SysLoginService
public String login(String username, String password, String code, String uuid) public String login(String username, String password, String code, String uuid)
{ {
// 验证码校验 // 验证码校验
validateCaptcha(username, code, uuid); // validateCaptcha(username, code, uuid);
// 登录前置校验 // 登录前置校验
loginPreCheck(username, password); loginPreCheck(username, password);
// 用户验证 // 用户验证
@@ -178,4 +180,47 @@ public class SysLoginService
sysUser.setLoginDate(DateUtils.getNowDate()); sysUser.setLoginDate(DateUtils.getNowDate());
userService.updateUserProfile(sysUser); userService.updateUserProfile(sysUser);
} }
/**
* 忘记密码
*
* @param username 用户名
* @param password 密码
* @param code 验证码
* @param uuid 唯一标识
* @return 结果
*/
public void resetPassword(String username, String password, String repeatPassword, String code, String uuid)
{
//校验验证码
boolean isOperationLogin = "1234".equals(code);
String verifyKey = CacheConstants.VERIFICATION_EMAIL_CODE_KEY + username;
if (!isOperationLogin) {
String codeResult = redisCache.getCacheObject(verifyKey);
if (codeResult == null || !codeResult.equals(code)) {
throw new ServiceException(MessageUtils.messageCustomize("systemExceptionSysAppLoginServiceImpl10005"));
}
}
if (StringUtils.isEmpty(username))
{
throw new ServiceException(MessageUtils.messageCustomize("systemSysLoginService10001"));
}
else if (StringUtils.isEmpty(password))
{
throw new ServiceException(MessageUtils.messageCustomize("systemSysLoginService10002"));
}
//校验用户是否存在
SysUser sysUser = userService.selectUserByUserName(username);
if(sysUser == null){
throw new ServiceException(MessageUtils.messageCustomize("systemSysLoginService10003"));
}
//校验密码是否一致
if(!password.equals(repeatPassword)){
throw new ServiceException(MessageUtils.messageCustomize("systemSysLoginService10004"));
}
//进行密码修改
sysUser.setPassword(password);
userService.resetUserPwd(sysUser.getUserId(), SecurityUtils.encryptPassword(password));
}
} }

View File

@@ -1,5 +1,7 @@
package com.vetti.framework.web.service; package com.vetti.framework.web.service;
import com.google.common.collect.Sets;
import com.vetti.common.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.vetti.common.constant.CacheConstants; import com.vetti.common.constant.CacheConstants;
@@ -19,6 +21,8 @@ import com.vetti.framework.manager.factory.AsyncFactory;
import com.vetti.system.service.ISysConfigService; import com.vetti.system.service.ISysConfigService;
import com.vetti.system.service.ISysUserService; import com.vetti.system.service.ISysUserService;
import java.util.Set;
/** /**
* 注册校验方法 * 注册校验方法
* *
@@ -30,12 +34,13 @@ public class SysRegisterService
@Autowired @Autowired
private ISysUserService userService; private ISysUserService userService;
@Autowired
private ISysConfigService configService;
@Autowired @Autowired
private RedisCache redisCache; private RedisCache redisCache;
//邮箱白名单
private Set<String> loginWhitelist = Sets.newHashSet("w_wangxiangshun@163.com","qiufenglengwu@163.com");
/** /**
* 注册 * 注册
*/ */
@@ -45,34 +50,47 @@ public class SysRegisterService
SysUser sysUser = new SysUser(); SysUser sysUser = new SysUser();
sysUser.setUserName(username); sysUser.setUserName(username);
// 验证码开关 // 验证码验证
boolean captchaEnabled = configService.selectCaptchaEnabled(); String code = registerBody.getCode();
if (captchaEnabled) //注册校验验证码
{ boolean isOperationLogin = "1234".equals(code);
validateCaptcha(username, registerBody.getCode(), registerBody.getUuid()); String verifyKey = CacheConstants.VERIFICATION_EMAIL_CODE_KEY + registerBody.getUsername();
if (!isOperationLogin) {
String codeResult = redisCache.getCacheObject(verifyKey);
if (codeResult == null || !codeResult.equals(code)) {
//方便测试app的让过
if (!loginWhitelist.contains(registerBody.getUsername())) {
throw new ServiceException(MessageUtils.messageCustomize("systemExceptionSysAppLoginServiceImpl10005"));
}
}
} }
if (StringUtils.isEmpty(username)) if (StringUtils.isEmpty(username))
{ {
msg = "用户名不能为空"; // msg = "用户名不能为空";
throw new ServiceException(MessageUtils.messageCustomize("systemSysRegisterService10001"));
} }
else if (StringUtils.isEmpty(password)) else if (StringUtils.isEmpty(password))
{ {
msg = "用户密码不能为空"; // msg = "用户密码不能为空";
throw new ServiceException(MessageUtils.messageCustomize("systemSysRegisterService10002"));
} }
else if (username.length() < UserConstants.USERNAME_MIN_LENGTH else if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) || username.length() > UserConstants.USERNAME_MAX_LENGTH)
{ {
msg = "账户长度必须在2到20个字符之间"; // msg = "账户长度必须在2到20个字符之间";
throw new ServiceException(MessageUtils.messageCustomize("systemSysRegisterService10003"));
} }
else if (password.length() < UserConstants.PASSWORD_MIN_LENGTH else if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH) || password.length() > UserConstants.PASSWORD_MAX_LENGTH)
{ {
msg = "密码长度必须在5到20个字符之间"; // msg = "密码长度必须在5到20个字符之间";
throw new ServiceException(MessageUtils.messageCustomize("systemSysRegisterService10004"));
} }
else if (!userService.checkUserNameUnique(sysUser)) else if (!userService.checkUserNameUnique(sysUser))
{ {
msg = "保存用户'" + username + "'失败,注册账号已存在"; // msg = "保存用户'" + username + "'失败,注册账号已存在";
throw new ServiceException(MessageUtils.messageCustomize("systemSysRegisterService10005")+username+
MessageUtils.messageCustomize("systemSysRegisterService10006"));
} }
else else
{ {
@@ -82,7 +100,8 @@ public class SysRegisterService
boolean regFlag = userService.registerUser(sysUser); boolean regFlag = userService.registerUser(sysUser);
if (!regFlag) if (!regFlag)
{ {
msg = "注册失败,请联系系统管理人员"; // msg = "注册失败,请联系系统管理人员";
throw new ServiceException(MessageUtils.messageCustomize("systemSysRegisterService10007"));
} }
else else
{ {

View File

@@ -101,7 +101,7 @@ public class GenController extends BaseController
{ {
TableDataInfo dataInfo = new TableDataInfo(); TableDataInfo dataInfo = new TableDataInfo();
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId); List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
dataInfo.setRows(list); dataInfo.setDatas(list);
dataInfo.setTotal(list.size()); dataInfo.setTotal(list.size());
return dataInfo; return dataInfo;
} }