|
@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
+import shop.alien.entity.result.R;
|
|
|
import shop.alien.entity.store.LifeSys;
|
|
import shop.alien.entity.store.LifeSys;
|
|
|
import shop.alien.entity.store.UserLoginInfo;
|
|
import shop.alien.entity.store.UserLoginInfo;
|
|
|
import shop.alien.entity.store.vo.SystemLoginVo;
|
|
import shop.alien.entity.store.vo.SystemLoginVo;
|
|
@@ -66,11 +68,11 @@ public class SystemServiceImpl implements SystemService {
|
|
|
new LambdaQueryWrapper<LifeSys>()
|
|
new LambdaQueryWrapper<LifeSys>()
|
|
|
.eq(LifeSys::getUserName, username)
|
|
.eq(LifeSys::getUserName, username)
|
|
|
);
|
|
);
|
|
|
- if (lifeSys != null && encryptToMD5(lifeSys.getUserPassword()).equals(password)) {
|
|
|
|
|
|
|
+ if (lifeSys != null && lifeSys.getUserPassword().equals(encryptToMD5(password))) {
|
|
|
Map<String, String> tokenMap = new HashMap<>();
|
|
Map<String, String> tokenMap = new HashMap<>();
|
|
|
tokenMap.put("phone", "123456");
|
|
tokenMap.put("phone", "123456");
|
|
|
tokenMap.put("userName", lifeSys.getUserName());
|
|
tokenMap.put("userName", lifeSys.getUserName());
|
|
|
- tokenMap.put("userId", lifeSys.getId());
|
|
|
|
|
|
|
+ tokenMap.put("userId", String.valueOf(lifeSys.getId()));
|
|
|
tokenMap.put("userType", "web");
|
|
tokenMap.put("userType", "web");
|
|
|
//存入token
|
|
//存入token
|
|
|
result.setToken(JwtUtil.createJWT("web_" + lifeSys.getId(), lifeSys.getUserName(), JSONObject.toJSONString(tokenMap), effectiveTimeIntLong));
|
|
result.setToken(JwtUtil.createJWT("web_" + lifeSys.getId(), lifeSys.getUserName(), JSONObject.toJSONString(tokenMap), effectiveTimeIntLong));
|
|
@@ -92,6 +94,42 @@ public class SystemServiceImpl implements SystemService {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R<LifeSys> register(String userName, String password, String roleId) {
|
|
|
|
|
+ // 校验必填字段
|
|
|
|
|
+ if (!StringUtils.hasText(userName)) {
|
|
|
|
|
+ return R.fail("用户名不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!StringUtils.hasText(password)) {
|
|
|
|
|
+ return R.fail("密码不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 校验用户名是否已存在
|
|
|
|
|
+ LambdaQueryWrapper<LifeSys> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq(LifeSys::getUserName, userName);
|
|
|
|
|
+ LifeSys existingUser = lifeSysMapper.selectOne(queryWrapper);
|
|
|
|
|
+ if (existingUser != null) {
|
|
|
|
|
+ return R.fail("该用户名已存在,请更换其他用户名");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 创建新用户
|
|
|
|
|
+ LifeSys lifeSys = new LifeSys();
|
|
|
|
|
+ lifeSys.setUserName(userName);
|
|
|
|
|
+ // 密码使用MD5加密后存储
|
|
|
|
|
+ lifeSys.setUserPassword(encryptToMD5(password));
|
|
|
|
|
+ if (StringUtils.hasText(roleId)) {
|
|
|
|
|
+ lifeSys.setRoleId(roleId);
|
|
|
|
|
+ }
|
|
|
|
|
+ lifeSys.setDeleteFlag(0); // 未删除
|
|
|
|
|
+
|
|
|
|
|
+ // 保存用户
|
|
|
|
|
+ int result = lifeSysMapper.insert(lifeSys);
|
|
|
|
|
+ if (result > 0) {
|
|
|
|
|
+ return R.data(lifeSys, "注册成功");
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.fail("注册失败,请稍后重试");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static String encryptToMD5(String input) {
|
|
public static String encryptToMD5(String input) {
|
|
|
try {
|
|
try {
|
|
|
// 获取 MD5 算法的 MessageDigest 实例
|
|
// 获取 MD5 算法的 MessageDigest 实例
|