会员登录
This commit is contained in:
parent
e0efbea83a
commit
5ba73606ca
|
@ -4,20 +4,12 @@
|
||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="6ee93b58-a7e0-45a0-9e98-4c363b192afb" name="Changes" comment="发送验证码">
|
<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$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="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-user/src/main/java/cn/bunny/user/controller/UserinfoController.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/controller/UserinfoController.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-user/src/main/java/cn/bunny/user/mapper/UserinfoMapper.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/mapper/UserinfoMapper.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/service/UserinfoService.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/service/UserinfoService.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/java/cn/bunny/user/service/impl/UserinfoServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/service/impl/UserinfoServiceImpl.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>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
@ -196,7 +188,7 @@
|
||||||
<updated>1703487755445</updated>
|
<updated>1703487755445</updated>
|
||||||
<workItem from="1703487757122" duration="903000" />
|
<workItem from="1703487757122" duration="903000" />
|
||||||
<workItem from="1703488670206" duration="5932000" />
|
<workItem from="1703488670206" duration="5932000" />
|
||||||
<workItem from="1703549556395" duration="23992000" />
|
<workItem from="1703549556395" duration="25117000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="前端接口初始化;显示商品页面">
|
<task id="LOCAL-00001" summary="前端接口初始化;显示商品页面">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
|
@ -270,7 +262,15 @@
|
||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1703574739774</updated>
|
<updated>1703574739774</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="10" />
|
<task id="LOCAL-00010" summary="用户注册">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1703578711882</created>
|
||||||
|
<option name="number" value="00010" />
|
||||||
|
<option name="presentableId" value="LOCAL-00010" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1703578711882</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="11" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
|
@ -285,7 +285,8 @@
|
||||||
<MESSAGE value="修改不用的引用" />
|
<MESSAGE value="修改不用的引用" />
|
||||||
<MESSAGE value="商品详情" />
|
<MESSAGE value="商品详情" />
|
||||||
<MESSAGE value="发送验证码" />
|
<MESSAGE value="发送验证码" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="发送验证码" />
|
<MESSAGE value="用户注册" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="用户注册" />
|
||||||
</component>
|
</component>
|
||||||
<component name="XDebuggerManager">
|
<component name="XDebuggerManager">
|
||||||
<pin-to-top-manager>
|
<pin-to-top-manager>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package cn.bunny.user.controller;
|
package cn.bunny.user.controller;
|
||||||
|
|
||||||
|
import cn.bunny.common.spzx.model.dto.h5.UserLoginDto;
|
||||||
import cn.bunny.common.spzx.model.dto.h5.UserRegisterDto;
|
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.Result;
|
||||||
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
|
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
|
||||||
|
@ -19,6 +20,13 @@ public class UserinfoController {
|
||||||
@Resource
|
@Resource
|
||||||
private UserinfoService userinfoService;
|
private UserinfoService userinfoService;
|
||||||
|
|
||||||
|
@Operation(summary = "会员登录")
|
||||||
|
@PostMapping("login")
|
||||||
|
public Result login(@RequestBody UserLoginDto userLoginDto) {
|
||||||
|
String token = userinfoService.login(userLoginDto);
|
||||||
|
return Result.build(token, ResultCodeEnum.SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
@Operation(summary = "会员注册")
|
@Operation(summary = "会员注册")
|
||||||
@PostMapping("register")
|
@PostMapping("register")
|
||||||
public Result register(@RequestBody UserRegisterDto userRegisterDto) {
|
public Result register(@RequestBody UserRegisterDto userRegisterDto) {
|
||||||
|
|
|
@ -12,4 +12,7 @@ public interface UserinfoMapper {
|
||||||
|
|
||||||
// 封装添加数据,调用方法调用添加数据
|
// 封装添加数据,调用方法调用添加数据
|
||||||
void save(UserInfo userInfo);
|
void save(UserInfo userInfo);
|
||||||
|
|
||||||
|
// 根据用户名查询数据库,得到用户信息
|
||||||
|
UserInfo selectByUsername(String username);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package cn.bunny.user.service;
|
package cn.bunny.user.service;
|
||||||
|
|
||||||
|
import cn.bunny.common.spzx.model.dto.h5.UserLoginDto;
|
||||||
import cn.bunny.common.spzx.model.dto.h5.UserRegisterDto;
|
import cn.bunny.common.spzx.model.dto.h5.UserRegisterDto;
|
||||||
|
|
||||||
public interface UserinfoService {
|
public interface UserinfoService {
|
||||||
// 会员注册
|
// 会员注册
|
||||||
void register(UserRegisterDto userLoginDto);
|
void register(UserRegisterDto userLoginDto);
|
||||||
|
|
||||||
|
// 会员登录
|
||||||
|
String login(UserLoginDto userLoginDto);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,21 @@
|
||||||
package cn.bunny.user.service.impl;
|
package cn.bunny.user.service.impl;
|
||||||
|
|
||||||
import cn.bunny.common.exception.BunnyException;
|
import cn.bunny.common.exception.BunnyException;
|
||||||
|
import cn.bunny.common.spzx.model.dto.h5.UserLoginDto;
|
||||||
import cn.bunny.common.spzx.model.dto.h5.UserRegisterDto;
|
import cn.bunny.common.spzx.model.dto.h5.UserRegisterDto;
|
||||||
import cn.bunny.common.spzx.model.entity.user.UserInfo;
|
import cn.bunny.common.spzx.model.entity.user.UserInfo;
|
||||||
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
|
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
|
||||||
import cn.bunny.user.mapper.UserinfoMapper;
|
import cn.bunny.user.mapper.UserinfoMapper;
|
||||||
import cn.bunny.user.service.UserinfoService;
|
import cn.bunny.user.service.UserinfoService;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.DigestUtils;
|
import org.springframework.util.DigestUtils;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserinfoServiceImpl implements UserinfoService {
|
public class UserinfoServiceImpl implements UserinfoService {
|
||||||
@Resource
|
@Resource
|
||||||
|
@ -50,4 +55,31 @@ public class UserinfoServiceImpl implements UserinfoService {
|
||||||
// 6. 从Redis中删除发送验证码
|
// 6. 从Redis中删除发送验证码
|
||||||
redisTemplate.delete(username);
|
redisTemplate.delete(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 会员登录
|
||||||
|
@Override
|
||||||
|
public String login(UserLoginDto userLoginDto) {
|
||||||
|
// 1. dto获取用户名和密码
|
||||||
|
String username = userLoginDto.getUsername();
|
||||||
|
String password = userLoginDto.getPassword();
|
||||||
|
// 2. 根据用户名查询数据库,得到用户信息
|
||||||
|
UserInfo userInfo = userinfoMapper.selectByUsername(username);
|
||||||
|
// 3. 比较密码是否一致
|
||||||
|
String database_password = userInfo.getPassword();
|
||||||
|
String md5_password = DigestUtils.md5DigestAsHex(password.getBytes());
|
||||||
|
if (!database_password.equals(md5_password)) {
|
||||||
|
throw new BunnyException(ResultCodeEnum.LOGIN_ERROR);
|
||||||
|
}
|
||||||
|
// 4. 校验用户名是否禁用
|
||||||
|
if (userInfo.getStatus() == 0) {
|
||||||
|
throw new BunnyException(ResultCodeEnum.ACCOUNT_STOP);
|
||||||
|
}
|
||||||
|
// 5. 生成token
|
||||||
|
String token = UUID.randomUUID().toString().replaceAll("-", "");
|
||||||
|
// 6. 把用户名信息放到redis中
|
||||||
|
redisTemplate.opsForValue().set("user:spzx" + token,
|
||||||
|
JSON.toJSONString(userInfo), 30, TimeUnit.DAYS);
|
||||||
|
// 7. 返回token
|
||||||
|
return token;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue