feat(新增): 用户注册完成
Signed-off-by: bunny <1319900154@qq.com>
This commit is contained in:
parent
98fac3ddb8
commit
dd8d37e343
|
@ -22,7 +22,7 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
|||
protected void addCorsMappings(CorsRegistry registry) {
|
||||
log.info("WebMvcConfiguration===>开始跨域注册表...");
|
||||
|
||||
registry.addMapping("/**")// 添加路径规则
|
||||
registry.addMapping("/admin/**")// 添加路径规则
|
||||
.allowCredentials(true)// 是否允许在跨域的情况下传递Cookie
|
||||
.allowedOriginPatterns("*")// 允许请求来源的域规则
|
||||
.allowedMethods("*").allowedHeaders("*");// 允许所有的请求头
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.atguigu.exception.BunnyException;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class StringEmptyUtil {
|
||||
public class EmptyUtil {
|
||||
/**
|
||||
* 判断内容是否为空
|
||||
*
|
||||
|
@ -16,4 +16,16 @@ public class StringEmptyUtil {
|
|||
throw new BunnyException(null, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断内容是否为空
|
||||
*
|
||||
* @param val 值
|
||||
* @param errorMessage 如果为空的错误信息
|
||||
*/
|
||||
public void isNotEmpty(Object val, String errorMessage) {
|
||||
if (val != null) {
|
||||
throw new BunnyException(null, errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,4 +25,8 @@ public class MessageConstant {
|
|||
public static final String FIND_ID_IS_NOT_EMPTY = "查询ID不能为空";
|
||||
public static final String MESSAGE_CODE_NOT_PASS = "短信验证码未过期";
|
||||
public static final String MESSAGE_CODE_UNAUTHORIZED = "短信验证码未授权,请联系管理员";
|
||||
public static final String VERIFICATION_CODE_ERROR = "验证码错误";
|
||||
public static final String USER_DOES_NOT_EXIST = "用户不存在";
|
||||
public static final String USER_DOES_IS_EXIST = "用户已存在";
|
||||
public static final String VERIFICATION_CODE_IS_EMPTY = "请先发送验证码";
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.atguigu.constant.MessageConstant;
|
|||
import com.atguigu.spzx.manger.mapper.BrandMapper;
|
||||
import com.atguigu.spzx.manger.service.BrandService;
|
||||
import com.atguigu.spzx.model.entity.product.Brand;
|
||||
import com.atguigu.utils.StringEmptyUtil;
|
||||
import com.atguigu.utils.EmptyUtil;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
@ -18,7 +18,7 @@ public class BrandServiceImpl implements BrandService {
|
|||
@Autowired
|
||||
private BrandMapper brandMapper;
|
||||
@Autowired
|
||||
private StringEmptyUtil emptyUtil;
|
||||
private EmptyUtil emptyUtil;
|
||||
|
||||
/**
|
||||
* 品牌列表查询
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.atguigu.spzx.manger.service.CategoryBrandService;
|
|||
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
|
||||
import com.atguigu.spzx.model.entity.product.Brand;
|
||||
import com.atguigu.spzx.model.entity.product.CategoryBrand;
|
||||
import com.atguigu.utils.StringEmptyUtil;
|
||||
import com.atguigu.utils.EmptyUtil;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
@ -21,7 +21,7 @@ public class CategoryBrandServiceImpl implements CategoryBrandService {
|
|||
@Autowired
|
||||
private CategoryBrandMapper categoryBrandMapper;
|
||||
@Autowired
|
||||
private StringEmptyUtil emptyUtil;
|
||||
private EmptyUtil emptyUtil;
|
||||
|
||||
/**
|
||||
* 分类品牌列表
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.atguigu.exception.BunnyException;
|
|||
import com.atguigu.spzx.manger.mapper.ProductSpecMapper;
|
||||
import com.atguigu.spzx.manger.service.ProductSpecService;
|
||||
import com.atguigu.spzx.model.entity.product.ProductSpec;
|
||||
import com.atguigu.utils.StringEmptyUtil;
|
||||
import com.atguigu.utils.EmptyUtil;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
@ -19,7 +19,7 @@ public class ProductSpecServiceImpl implements ProductSpecService {
|
|||
@Autowired
|
||||
private ProductSpecMapper productSpecMapper;
|
||||
@Autowired
|
||||
private StringEmptyUtil emptyUtil;
|
||||
private EmptyUtil emptyUtil;
|
||||
|
||||
/**
|
||||
* 列表查询
|
||||
|
|
|
@ -8,8 +8,8 @@ import com.atguigu.spzx.manger.service.SysMenuService;
|
|||
import com.atguigu.spzx.manger.service.module.SysMenuServiceImplModule;
|
||||
import com.atguigu.spzx.model.entity.system.SysMenu;
|
||||
import com.atguigu.spzx.model.vo.system.SysMenuVo;
|
||||
import com.atguigu.utils.EmptyUtil;
|
||||
import com.atguigu.utils.MenuHelper;
|
||||
import com.atguigu.utils.StringEmptyUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -20,7 +20,7 @@ public class SysMenuServiceImpl implements SysMenuService {
|
|||
@Autowired
|
||||
private SysMenuMapper sysMenuMapper;
|
||||
@Autowired
|
||||
private StringEmptyUtil emptyUtil;
|
||||
private EmptyUtil emptyUtil;
|
||||
@Autowired
|
||||
private SysMenuServiceImplModule sysMenuServiceImplModule;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import com.atguigu.spzx.model.dto.system.AssginRoleDto;
|
|||
import com.atguigu.spzx.model.dto.system.SysRoleDto;
|
||||
import com.atguigu.spzx.model.entity.system.SysRole;
|
||||
import com.atguigu.spzx.model.vo.system.AllRolesVo;
|
||||
import com.atguigu.utils.StringEmptyUtil;
|
||||
import com.atguigu.utils.EmptyUtil;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
@ -24,7 +24,7 @@ public class SysRoleServiceImpl implements SysRoleService {
|
|||
@Autowired
|
||||
private SysRoleUserMapper sysRoleUserMapper;
|
||||
@Autowired
|
||||
private StringEmptyUtil emptyUtil;
|
||||
private EmptyUtil emptyUtil;
|
||||
|
||||
/**
|
||||
* 查询角色信息返回分页
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.atguigu.spzx.model.dto.system.SysUserDto;
|
|||
import com.atguigu.spzx.model.entity.system.SysUser;
|
||||
import com.atguigu.spzx.model.vo.result.ResultCodeEnum;
|
||||
import com.atguigu.spzx.model.vo.system.LoginVo;
|
||||
import com.atguigu.utils.StringEmptyUtil;
|
||||
import com.atguigu.utils.EmptyUtil;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit;
|
|||
@Service
|
||||
public class SysUserServiceImpl implements SysUserService {
|
||||
@Autowired
|
||||
StringEmptyUtil stringEmptyUtil;
|
||||
EmptyUtil emptyUtil;
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
@Autowired
|
||||
|
@ -47,11 +47,11 @@ public class SysUserServiceImpl implements SysUserService {
|
|||
String key = loginDto.getCodeKey();
|
||||
// 得到Redis中验证码
|
||||
String code = (String) redisTemplate.opsForValue().get(key);
|
||||
stringEmptyUtil.isEmpty(userName, ExceptionConstant.USERNAME_IS_EMPTY);
|
||||
stringEmptyUtil.isEmpty(password, ExceptionConstant.PASSWORD_IS_EMPTY);
|
||||
stringEmptyUtil.isEmpty(captcha, ExceptionConstant.CAPTCHA_IS_EMPTY);
|
||||
stringEmptyUtil.isEmpty(key, ExceptionConstant.KEY_IS_EMPTY);
|
||||
stringEmptyUtil.isEmpty(code, ExceptionConstant.VERIFICATION_CODE_IS_EMPTY);
|
||||
emptyUtil.isEmpty(userName, ExceptionConstant.USERNAME_IS_EMPTY);
|
||||
emptyUtil.isEmpty(password, ExceptionConstant.PASSWORD_IS_EMPTY);
|
||||
emptyUtil.isEmpty(captcha, ExceptionConstant.CAPTCHA_IS_EMPTY);
|
||||
emptyUtil.isEmpty(key, ExceptionConstant.KEY_IS_EMPTY);
|
||||
emptyUtil.isEmpty(code, ExceptionConstant.VERIFICATION_CODE_IS_EMPTY);
|
||||
|
||||
// 验证码不匹配
|
||||
assert code != null;
|
||||
|
@ -115,7 +115,7 @@ public class SysUserServiceImpl implements SysUserService {
|
|||
public void saveSysUser(SysUser sysUser) {
|
||||
// 判断用户名不能为空
|
||||
String username = sysUser.getUserName();
|
||||
stringEmptyUtil.isEmpty(username, "用户名不能为空");
|
||||
emptyUtil.isEmpty(username, "用户名不能为空");
|
||||
|
||||
SysUser dbUser = sysUserMapper.selectByUsername(sysUser.getUserName());
|
||||
// 如果用户已存在
|
||||
|
@ -139,7 +139,7 @@ public class SysUserServiceImpl implements SysUserService {
|
|||
*/
|
||||
@Override
|
||||
public void updateSysUser(SysUser sysUser) {
|
||||
stringEmptyUtil.isEmpty(sysUser.getId(), MessageConstant.UPDATE_ID_IS_NOT_EMPTY);
|
||||
emptyUtil.isEmpty(sysUser.getId(), MessageConstant.UPDATE_ID_IS_NOT_EMPTY);
|
||||
sysUserMapper.updateSysUser(sysUser);
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ public class SysUserServiceImpl implements SysUserService {
|
|||
*/
|
||||
@Override
|
||||
public void deleteById(Long userId) {
|
||||
stringEmptyUtil.isEmpty(userId, MessageConstant.DELETE_ID_IS_NOT_EMPTY);
|
||||
emptyUtil.isEmpty(userId, MessageConstant.DELETE_ID_IS_NOT_EMPTY);
|
||||
sysUserMapper.deleteById(userId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,8 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description="注册对象")
|
||||
@Schema(description = "注册对象")
|
||||
public class UserRegisterDto {
|
||||
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
|
||||
|
@ -17,6 +16,5 @@ public class UserRegisterDto {
|
|||
private String nickName;
|
||||
|
||||
@Schema(description = "手机验证码")
|
||||
private String code ;
|
||||
|
||||
private String code;
|
||||
}
|
|
@ -20,16 +20,16 @@ spring:
|
|||
locator:
|
||||
enabled: true
|
||||
# 解决跨域
|
||||
# globalcors:
|
||||
# cors-configurations:
|
||||
# '[/**]':
|
||||
# allowedOriginPatterns: "*"
|
||||
# # 允许请求中携带的头信息
|
||||
# allowedHeaders: "*"
|
||||
# # 运行跨域的请求方式
|
||||
# allowedMethods: "*"
|
||||
# # 跨域检测的有效期,单位s
|
||||
# maxAge: 36000
|
||||
globalcors:
|
||||
cors-configurations:
|
||||
'[/**]':
|
||||
allowedOriginPatterns: "*"
|
||||
# 允许请求中携带的头信息
|
||||
allowedHeaders: "*"
|
||||
# 运行跨域的请求方式
|
||||
allowedMethods: "*"
|
||||
# 跨域检测的有效期,单位s
|
||||
maxAge: 36000
|
||||
# 路由
|
||||
routes:
|
||||
- id: service-product
|
||||
|
|
|
@ -34,7 +34,6 @@ public class IndexController {
|
|||
List<Category> categoryList = categoryService.selectOneCategory();
|
||||
// 根据销量排序,获取前十条数据
|
||||
List<ProductSku> productSkuList = productService.selectProductSkuBySale();
|
||||
|
||||
IndexVo vo = IndexVo.builder().categoryList(categoryList).productSkuList(productSkuList).build();
|
||||
return Result.success(vo);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package com.atguigu.user;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableCaching// 开启缓存注解
|
||||
@MapperScan("com.atguigu.user.mapper")
|
||||
@ComponentScan("com.atguigu")
|
||||
@Slf4j
|
||||
public class UserApplication {
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.atguigu.user.controller;
|
||||
|
||||
import com.atguigu.spzx.model.dto.h5.UserRegisterDto;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import com.atguigu.user.service.UserInfoService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Tag(name = "会员用户接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/user/userInfo")
|
||||
public class UserInfoController {
|
||||
@Autowired
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@Operation(summary = "会员注册")
|
||||
@PostMapping("register")
|
||||
public Result<String> register(@RequestBody UserRegisterDto userRegisterDto) {
|
||||
userInfoService.register(userRegisterDto);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.atguigu.user.mapper;
|
||||
|
||||
import com.atguigu.spzx.model.entity.user.UserInfo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface UserInfoMapper {
|
||||
/**
|
||||
* 查询用户
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 用户信息
|
||||
*/
|
||||
UserInfo selectByUsername(String username);
|
||||
|
||||
/**
|
||||
* 保存用户信息
|
||||
*
|
||||
* @param userInfo 用户信息
|
||||
*/
|
||||
void save(UserInfo userInfo);
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.atguigu.user.service;
|
||||
|
||||
import com.atguigu.spzx.model.dto.h5.UserRegisterDto;
|
||||
|
||||
public interface UserInfoService {
|
||||
/**
|
||||
* 会员注册
|
||||
*
|
||||
* @param userRegisterDto 注册对象
|
||||
*/
|
||||
void register(UserRegisterDto userRegisterDto);
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package com.atguigu.user.service.impl;
|
||||
|
||||
import com.atguigu.constant.MessageConstant;
|
||||
import com.atguigu.exception.BunnyException;
|
||||
import com.atguigu.spzx.model.dto.h5.UserRegisterDto;
|
||||
import com.atguigu.spzx.model.entity.user.UserInfo;
|
||||
import com.atguigu.user.mapper.UserInfoMapper;
|
||||
import com.atguigu.user.service.UserInfoService;
|
||||
import com.atguigu.utils.EmptyUtil;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class UserInfoServiceImpl implements UserInfoService {
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
@Autowired
|
||||
private UserInfoMapper userInfoMapper;
|
||||
@Autowired
|
||||
private EmptyUtil emptyUtil;
|
||||
|
||||
/**
|
||||
* 会员注册
|
||||
*
|
||||
* @param userRegisterDto 注册对象
|
||||
*/
|
||||
@Override
|
||||
public void register(UserRegisterDto userRegisterDto) {
|
||||
emptyUtil.isEmpty(userRegisterDto.getUsername(), MessageConstant.SAVE_DTO_IS_NULL);
|
||||
// 获取数据
|
||||
String username = userRegisterDto.getUsername();
|
||||
String password = userRegisterDto.getPassword();
|
||||
String code = userRegisterDto.getCode();
|
||||
|
||||
// 从Redis中获取发送的验证码
|
||||
Object redisCode = redisTemplate.opsForValue().get(username);
|
||||
emptyUtil.isEmpty(redisCode, MessageConstant.VERIFICATION_CODE_IS_EMPTY);
|
||||
if (!Objects.equals(String.valueOf(redisCode), code)) {
|
||||
throw new BunnyException(MessageConstant.VERIFICATION_CODE_ERROR);
|
||||
}
|
||||
|
||||
// 校验用户名不能相同
|
||||
UserInfo userInfo = userInfoMapper.selectByUsername(username);
|
||||
emptyUtil.isNotEmpty(userInfo, MessageConstant.USER_DOES_IS_EXIST);
|
||||
|
||||
userInfo = new UserInfo();
|
||||
BeanUtils.copyProperties(userRegisterDto, userInfo);
|
||||
userInfo.setPassword(DigestUtils.md5DigestAsHex(password.getBytes()));
|
||||
userInfo.setPhone(username);
|
||||
userInfo.setStatus(1);
|
||||
userInfo.setStatus(0);
|
||||
userInfo.setAvatar("https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eoj0hHXhgJNOTSOFsS4uZs8x1ConecaVOB8eIl115xmJZcT4oCicvia7wMEufibKtTLqiaJeanU2Lpg3w/132");
|
||||
|
||||
// 保存用户信息
|
||||
userInfoMapper.save(userInfo);
|
||||
|
||||
// 删除Redis中的数据
|
||||
redisTemplate.delete(username);
|
||||
}
|
||||
}
|
|
@ -37,7 +37,7 @@ logging:
|
|||
|
||||
mybatis:
|
||||
type-aliases-package: com.atguigu.spzx.model
|
||||
mapper-locations: classpath:/mapper/*/*.xml
|
||||
mapper-locations: classpath:/mapper/*.xml
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
map-underscore-to-camel-case: true
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.atguigu.user.mapper.UserInfoMapper">
|
||||
<!-- 用于select查询公用抽取的列 -->
|
||||
<sql id="columns">
|
||||
id,username,password,nick_name,avatar,sex,phone,memo,open_id,union_id,last_login_ip,last_login_time,status,create_time,update_time,is_deleted
|
||||
</sql>
|
||||
|
||||
<!-- 保存用户信息 -->
|
||||
<insert id="save">
|
||||
insert into user_info (id, username, password, nick_name, avatar, sex, phone, memo, open_id, union_id,
|
||||
last_login_ip, last_login_time, status)
|
||||
values (#{id}, #{username}, #{password}, #{nickName}, #{avatar}, #{sex}, #{phone}, #{memo}, #{openId},
|
||||
#{unionId}, #{lastLoginIp}, #{lastLoginTime}, #{status})
|
||||
</insert>
|
||||
|
||||
<!-- 查询用户 -->
|
||||
<select id="selectByUsername" resultType="com.atguigu.spzx.model.entity.user.UserInfo">
|
||||
select
|
||||
<include refid="columns"/>
|
||||
from user_info
|
||||
where username = #{username}
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue