用户注册

This commit is contained in:
Bunny 2023-12-26 16:18:31 +08:00
parent ff030bf22d
commit e0efbea83a
13 changed files with 276 additions and 30 deletions

View File

@ -4,25 +4,20 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="6ee93b58-a7e0-45a0-9e98-4c363b192afb" name="Changes" comment="商品详情">
<change afterPath="$PROJECT_DIR$/spzx-common/common-util/src/main/java/cn/bunny/common/HttpUtils.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/User.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/config/RedisConfig.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/controller/SmsController.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/service/SmsService.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/service/impl/SmsServiceImpl.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/resources/application-dev.yml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/resources/application.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
<list default="true" id="6ee93b58-a7e0-45a0-9e98-4c363b192afb" name="Changes" comment="发送验证码">
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/controller/UserinfoController.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/mapper/UserinfoMapper.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/service/UserinfoService.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/service/impl/UserinfoServiceImpl.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/resources/logback-spring.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/resources/mapper/UserinfoMapper.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/resources/mybatis-config.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-common/common-service/src/main/java/cn/bunny/config/Knife4jConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-common/common-service/src/main/java/cn/bunny/config/Knife4jConfig.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-common/common-util/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-common/common-util/pom.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-server-gateway/src/main/resources/application-dev.yml" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-server-gateway/src/main/resources/application-dev.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/config/RedisConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/config/RedisConfig.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/service/imp/ProductServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/service/imp/ProductServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-service/service-product/src/main/resources/application-dev.yml" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-product/src/main/resources/application-dev.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-service/service-user/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-user/pom.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/web/App.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/BrandController.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/BrandController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/CategoryController.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/CategoryController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/ProductController.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-product/src/main/java/cn/bunny/web/product/controller/ProductController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/controller/SmsController.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/controller/SmsController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-service/service-user/src/main/resources/application-dev.yml" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/resources/application-dev.yml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -32,9 +27,9 @@
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="mybatis-mapper" />
<option value="Interface" />
<option value="Class" />
<option value="mybatis-mapper" />
</list>
</option>
</component>
@ -86,7 +81,7 @@
"code.cleanup.on.save": "true",
"git-widget-placeholder": "master",
"jdk.selected.JAVA_MODULE": "21",
"last_opened_file_path": "F:/File/Java/spzx-parent/spzx-service/service-user/src/main/java/cn/bunny/user",
"last_opened_file_path": "F:/File/Java/spzx-parent/spzx-service/service-user/src/main/resources",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
@ -110,8 +105,8 @@
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="F:\File\Java\spzx-parent\spzx-service\service-user\src\main\java\cn\bunny\user" />
<recent name="F:\File\Java\spzx-parent\spzx-service\service-user\src\main\resources" />
<recent name="F:\File\Java\spzx-parent\spzx-service\service-user\src\main\java\cn\bunny\user" />
<recent name="F:\File\Java\spzx-parent\spzx-service\service-product\src\main\java\cn\bunny\web\product" />
<recent name="F:\File\Java\spzx-parent\spzx-server-gateway\src\main\resources" />
<recent name="F:\File\Java\spzx-parent\spzx-service\service-product\src\main\resources" />
@ -201,7 +196,7 @@
<updated>1703487755445</updated>
<workItem from="1703487757122" duration="903000" />
<workItem from="1703488670206" duration="5932000" />
<workItem from="1703549556395" duration="20239000" />
<workItem from="1703549556395" duration="23992000" />
</task>
<task id="LOCAL-00001" summary="前端接口初始化;显示商品页面">
<option name="closed" value="true" />
@ -267,7 +262,15 @@
<option name="project" value="LOCAL" />
<updated>1703567148967</updated>
</task>
<option name="localTasksCounter" value="9" />
<task id="LOCAL-00009" summary="发送验证码">
<option name="closed" value="true" />
<created>1703574739774</created>
<option name="number" value="00009" />
<option name="presentableId" value="LOCAL-00009" />
<option name="project" value="LOCAL" />
<updated>1703574739774</updated>
</task>
<option name="localTasksCounter" value="10" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -281,7 +284,8 @@
<MESSAGE value="根据品牌进行查询" />
<MESSAGE value="修改不用的引用" />
<MESSAGE value="商品详情" />
<option name="LAST_COMMIT_MESSAGE" value="商品详情" />
<MESSAGE value="发送验证码" />
<option name="LAST_COMMIT_MESSAGE" value="发送验证码" />
</component>
<component name="XDebuggerManager">
<pin-to-top-manager>

View File

@ -5,6 +5,7 @@ import cn.bunny.common.spzx.model.vo.common.Result;
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
import cn.bunny.web.product.service.BrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -12,8 +13,9 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Tag(name = "品牌接口")
@RestController
@RequestMapping(value="/api/product/brand")
@RequestMapping(value = "/api/product/brand")
public class BrandController {
@Resource
private BrandService brandService;

View File

@ -13,18 +13,18 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@Tag(name = "分类接口管理")
@RequestMapping(value="/api/product/category")
@RestController
@RequestMapping(value = "/api/product/category")
// @CrossOrigin
public class CategoryController {
@Resource
private CategoryService categoryService;
@Operation(summary = "获取分类树形数据",description = "按照树型方式进行封装")
@Operation(summary = "获取分类树形数据", description = "按照树型方式进行封装")
@GetMapping("findCategoryTree")
public Result findCategoryTree() {
List<Category> categoryList= categoryService.findCategoryTree();
List<Category> categoryList = categoryService.findCategoryTree();
return Result.build(categoryList, ResultCodeEnum.SUCCESS);
}
}

View File

@ -9,12 +9,14 @@ import cn.bunny.web.product.service.ProductService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Tag(name = "商品接口")
@RestController
@RequestMapping("/api/product")
public class ProductController {

View File

@ -4,12 +4,14 @@ import cn.bunny.common.spzx.model.vo.common.Result;
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
import cn.bunny.user.service.SmsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Tag(name = "发送验证码")
@RestController
@RequestMapping("/api/user/sms")
public class SmsController {

View File

@ -0,0 +1,28 @@
package cn.bunny.user.controller;
import cn.bunny.common.spzx.model.dto.h5.UserRegisterDto;
import cn.bunny.common.spzx.model.vo.common.Result;
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
import cn.bunny.user.service.UserinfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
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 {
@Resource
private UserinfoService userinfoService;
@Operation(summary = "会员注册")
@PostMapping("register")
public Result register(@RequestBody UserRegisterDto userRegisterDto) {
userinfoService.register(userRegisterDto);
return Result.build(null, ResultCodeEnum.SUCCESS);
}
}

View File

@ -0,0 +1,15 @@
package cn.bunny.user.mapper;
import cn.bunny.common.spzx.model.entity.user.UserInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface UserinfoMapper {
// 校验用户名不重复
UserInfo getByUsername(@Param("username") String username);
// 封装添加数据调用方法调用添加数据
void save(UserInfo userInfo);
}

View File

@ -0,0 +1,9 @@
package cn.bunny.user.service;
import cn.bunny.common.spzx.model.dto.h5.UserRegisterDto;
public interface UserinfoService {
// 会员注册
void register(UserRegisterDto userLoginDto);
}

View File

@ -0,0 +1,53 @@
package cn.bunny.user.service.impl;
import cn.bunny.common.exception.BunnyException;
import cn.bunny.common.spzx.model.dto.h5.UserRegisterDto;
import cn.bunny.common.spzx.model.entity.user.UserInfo;
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
import cn.bunny.user.mapper.UserinfoMapper;
import cn.bunny.user.service.UserinfoService;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
@Service
public class UserinfoServiceImpl implements UserinfoService {
@Resource
private RedisTemplate redisTemplate;
@Resource
private UserinfoMapper userinfoMapper;
// 会员注册
@Override
public void register(UserRegisterDto userRegisterDto) {
// 1. userLoginDto获取数据
String username = userRegisterDto.getUsername();
String password = userRegisterDto.getPassword();
String nickName = userRegisterDto.getNickName();
String code = userRegisterDto.getCode();
// 2. 从Redis获取发送验证码
String redisCode = (String) redisTemplate.opsForValue().get(username);
// 3. 获取输入验证码进行对比
if (!redisCode.equals(code)) {
throw new BunnyException(ResultCodeEnum.VALIDATECODE_ERROR);
}
// 4. 校验用户名不重复
UserInfo userInfo = userinfoMapper.getByUsername(username);
if (userInfo != null) {
throw new BunnyException(ResultCodeEnum.USER_NAME_IS_EXISTS);
}
// 5. 封装添加数据调用方法调用添加数据
userInfo = new UserInfo();
userInfo.setUsername(username);
userInfo.setNickName(nickName);
userInfo.setPassword(DigestUtils.md5DigestAsHex(password.getBytes()));
userInfo.setPhone(username);
userInfo.setStatus(1);
userInfo.setSex(0);
userInfo.setAvatar("http://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eoj0hHXhgJNOTSOFsS4uZs8x1ConecaVOB8eIl115xmJZcT4oCicvia7wMEufibKtTLqiaJeanU2Lpg3w/132");
userinfoMapper.save(userInfo);
// 6. 从Redis中删除发送验证码
redisTemplate.delete(username);
}
}

View File

@ -19,4 +19,8 @@ spring:
data:
redis:
port: 6379
host: 192.168.2.156
host: 192.168.2.156
mybatis:
config-location: classpath:mybatis-config.xml
mapper-locations: classpath:/mapper/*.xml

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<contextName>logback</contextName>
<!-- 日志的输出目录 -->
<property name="log.path" value="D://logs//service-product//logs" />
<!--控制台日志格式:彩色日志-->
<!-- magenta:洋红 -->
<!-- boldMagenta:粗红-->
<!-- cyan:青色 -->
<!-- white:白色 -->
<!-- magenta:洋红 -->
<property name="CONSOLE_LOG_PATTERN" value="%yellow(%date{yyyy-MM-dd HH:mm:ss}) %highlight([%-5level]) %green(%logger) %msg%n"/>
<!--文件日志格式-->
<property name="FILE_LOG_PATTERN" value="%date{yyyy-MM-dd HH:mm:ss} [%-5level] %thread %file:%line %logger %msg%n" />
<!--编码-->
<property name="ENCODING" value="UTF-8" />
<!-- 控制台日志 -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!-- 临界值过滤器 -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<charset>${ENCODING}</charset>
</encoder>
</appender>
<!-- 文件日志 -->
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${log.path}//log.log</file>
<append>true</append>
<encoder>
<pattern>%date{yyyy-MM-dd HH:mm:ss} %msg%n</pattern>
<charset>${ENCODING}</charset>
</encoder>
</appender>
<!-- 开发环境 -->
<springProfile name="dev">
<!-- com.atguigu日志记录器业务程序INFO级别 -->
<logger name="com.atguigu" level="INFO" />
<!-- 根日志记录器INFO级别 -->
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
</springProfile>
</configuration>

View File

@ -0,0 +1,55 @@
<?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="cn.bunny.user.mapper.UserinfoMapper">
<resultMap id="userInfoMap" type="cn.bunny.common.spzx.model.entity.user.UserInfo" autoMapping="true"/>
<!-- 用于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>
<!-- 校验用户名不重复 -->
<select id="selectByUsername" resultMap="userInfoMap">
select *
from user_info
where username = #{username}
</select>
<select id="getByUsername" resultType="cn.bunny.common.spzx.model.entity.user.UserInfo">
select
<include refid="columns"/>
from user_info
where
username = #{username}
</select>
<!-- 封装添加数据,调用方法调用添加数据 -->
<insert id="save" useGeneratedKeys="true" keyProperty="id">
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>
</mapper>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC
"-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 设置驼峰标识 -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
<!-- 打印SQL语句 -->
<setting name="logImpl" value="STDOUT_LOGGING"/>
</settings>
<plugins>
<!-- 分页插件 -->
<plugin interceptor="com.github.pagehelper.PageInterceptor"/>
</plugins>
</configuration>