登录(修改)
parent
e0ba3f4023
commit
595a49f175
|
@ -4,6 +4,9 @@ import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author:Chen
|
* @Author:Chen
|
||||||
|
@ -16,7 +19,6 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
|
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
|
||||||
@EnableFeignClients
|
@EnableFeignClients
|
||||||
public class MallAuthApplication {
|
public class MallAuthApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(MallAuthApplication.class);
|
SpringApplication.run(MallAuthApplication.class);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.mall.auth.config;
|
||||||
|
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
public class ConfirmCallbackConfig implements RabbitTemplate.ConfirmCallback {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init(){
|
||||||
|
rabbitTemplate.setConfirmCallback(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void confirm(CorrelationData correlationData, boolean b, String s) {
|
||||||
|
if(b){//消费者投递broker 状态,true表示成功
|
||||||
|
log.info("消息发送成功!");
|
||||||
|
}else{
|
||||||
|
log.error("消息发送异常,异常原因:{}",s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.mall.auth.config;
|
||||||
|
|
||||||
|
import org.springframework.amqp.core.ReturnedMessage;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ReturnCallbackConfig implements RabbitTemplate.ReturnsCallback {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init(){
|
||||||
|
rabbitTemplate.setReturnsCallback(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void returnedMessage(ReturnedMessage returnedMessage) {
|
||||||
|
System.out.println("消息"+returnedMessage.getMessage().toString()+"被交换机"+returnedMessage.getExchange()+"回退!"
|
||||||
|
+"退回原因为:"+returnedMessage.getReplyText());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
package com.mall.auth.controller;
|
||||||
|
|
||||||
|
import com.mall.auth.service.AuthService;
|
||||||
|
import com.mall.common.domain.UserInfo;
|
||||||
|
import com.mall.common.domain.request.LoginRequest;
|
||||||
|
import com.mall.common.domain.vo.LoginVo;
|
||||||
|
import com.mall.common.domain.vo.UserInfoVo;
|
||||||
|
import com.mall.common.result.Result;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: lzh
|
||||||
|
* @CreateTime: 2024-04-22 17:00
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@Slf4j
|
||||||
|
public class AuthController {
|
||||||
|
@Autowired
|
||||||
|
private AuthService authService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号密码登录接口
|
||||||
|
* @param loginVo
|
||||||
|
* @return Result
|
||||||
|
*/
|
||||||
|
@PostMapping("/login")
|
||||||
|
public Result login(@RequestBody LoginVo loginVo){
|
||||||
|
Result result = authService.login(loginVo);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送验证码接口
|
||||||
|
* @param loginRequest
|
||||||
|
* @return Result
|
||||||
|
*/
|
||||||
|
@PostMapping("send/code/{phone}")
|
||||||
|
public Result sendCode(@RequestBody LoginRequest loginRequest){
|
||||||
|
Result result = authService.sendCode(loginRequest);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号登录接口
|
||||||
|
* @param loginRequest
|
||||||
|
* @return Result
|
||||||
|
*/
|
||||||
|
@PostMapping("phoneLogin")
|
||||||
|
public Result phoneLogin(@RequestBody LoginRequest loginRequest) {
|
||||||
|
Result result = authService.phoneLogin(loginRequest);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号注册接口
|
||||||
|
* @param userInfoVo
|
||||||
|
* @return Result
|
||||||
|
*/
|
||||||
|
@PostMapping("phoneRegister")
|
||||||
|
public Result phoneRegister(@RequestBody UserInfoVo userInfoVo) {
|
||||||
|
Result result = authService.phoneRegister(userInfoVo);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户信息接口
|
||||||
|
* @return Result
|
||||||
|
*/
|
||||||
|
@GetMapping("getUserInfo")
|
||||||
|
public Result<UserInfo> userInfo() {
|
||||||
|
Result<UserInfo> result = authService.userInfo();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.mall.auth.feign;
|
||||||
|
|
||||||
|
import com.mall.common.domain.UserInfo;
|
||||||
|
import com.mall.common.result.Result;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: lzh
|
||||||
|
* @CreateTime: 2024-04-22 17:16
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@FeignClient(name = "czk-user")
|
||||||
|
public interface UserServiceFeign {
|
||||||
|
@PostMapping("findLogin/{username}/{password}")
|
||||||
|
public Result<UserInfo> findLogin(@PathVariable String username,@PathVariable String password);
|
||||||
|
|
||||||
|
@GetMapping("findPhone/{phone}")
|
||||||
|
public Result<UserInfo> findPhone(@PathVariable("phone") String phone);
|
||||||
|
|
||||||
|
@PostMapping("register")
|
||||||
|
public Result<UserInfo> register(@RequestBody UserInfo userInfo);
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.mall.auth.service;
|
||||||
|
|
||||||
|
import com.mall.common.domain.UserInfo;
|
||||||
|
import com.mall.common.domain.request.LoginRequest;
|
||||||
|
import com.mall.common.domain.vo.LoginVo;
|
||||||
|
import com.mall.common.domain.vo.UserInfoVo;
|
||||||
|
import com.mall.common.result.Result;
|
||||||
|
|
||||||
|
public interface AuthService {
|
||||||
|
Result login(LoginVo loginVo);
|
||||||
|
|
||||||
|
Result sendCode(LoginRequest loginRequest);
|
||||||
|
|
||||||
|
Result phoneLogin(LoginRequest loginRequest);
|
||||||
|
|
||||||
|
Result phoneRegister(UserInfoVo userInfo);
|
||||||
|
|
||||||
|
Result<UserInfo> userInfo();
|
||||||
|
}
|
|
@ -0,0 +1,157 @@
|
||||||
|
package com.mall.auth.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import cn.hutool.crypto.SecureUtil;
|
||||||
|
import com.mall.auth.feign.UserServiceFeign;
|
||||||
|
import com.mall.auth.service.AuthService;
|
||||||
|
import com.mall.common.constant.JwtConstants;
|
||||||
|
import com.mall.common.constant.TokenConstants;
|
||||||
|
import com.mall.common.domain.UserInfo;
|
||||||
|
import com.mall.common.domain.request.LoginRequest;
|
||||||
|
import com.mall.common.domain.response.JwtResponse;
|
||||||
|
import com.mall.common.domain.vo.LoginVo;
|
||||||
|
import com.mall.common.domain.vo.UserInfoVo;
|
||||||
|
import com.mall.common.redis.RedisCache;
|
||||||
|
import com.mall.common.result.BizException;
|
||||||
|
import com.mall.common.result.Result;
|
||||||
|
import com.mall.common.utils.IdUtils;
|
||||||
|
import com.mall.common.utils.JwtUtils;
|
||||||
|
import com.mall.common.utils.StringUtils;
|
||||||
|
import io.jsonwebtoken.lang.Assert;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: lzh
|
||||||
|
* @CreateTime: 2024-04-22 17:01
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Log4j2
|
||||||
|
public class AuthServiceImpl implements AuthService {
|
||||||
|
@Autowired
|
||||||
|
private RedisCache redisCache;
|
||||||
|
@Autowired
|
||||||
|
private HttpServletRequest request;
|
||||||
|
@Autowired
|
||||||
|
private UserServiceFeign userServiceFeign;
|
||||||
|
@Autowired
|
||||||
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result login(LoginVo loginVo) {
|
||||||
|
Result<UserInfo> result = userServiceFeign.findLogin(loginVo.getUsername(),loginVo.getPassword());
|
||||||
|
UserInfo data = result.getData();
|
||||||
|
Assert.notNull(
|
||||||
|
data,"用户不存在"
|
||||||
|
);
|
||||||
|
// String password = SecureUtil.md5(
|
||||||
|
// loginVo.getPassword()+ "|" + data.getSalt()
|
||||||
|
// );
|
||||||
|
if (!loginVo.getPassword().equals(data.getPassword())){
|
||||||
|
throw new BizException("密码错误");
|
||||||
|
}
|
||||||
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
|
map.put(JwtConstants.USER_KEY,data.getId());
|
||||||
|
String token = JwtUtils.createToken(map);
|
||||||
|
redisCache.setCacheObject(TokenConstants.LOGIN_TOKEN_KEY+token,data,TokenConstants.EXPIRATION, TimeUnit.HOURS);
|
||||||
|
JwtResponse jwtResponse = new JwtResponse();
|
||||||
|
jwtResponse.setToken(token);
|
||||||
|
jwtResponse.setEndTim(TokenConstants.EXPIRATION);
|
||||||
|
return Result.success(jwtResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result sendCode(LoginRequest loginRequest) {
|
||||||
|
Result<UserInfo> result = userServiceFeign.findPhone(loginRequest.getPhone());
|
||||||
|
UserInfo data = result.getData();
|
||||||
|
Assert.notNull(
|
||||||
|
data,"请注册"
|
||||||
|
);
|
||||||
|
String code = RandomUtil.randomNumbers(6);
|
||||||
|
redisCache.setCacheObject("send_code"+loginRequest.getPhone(),code);
|
||||||
|
//rabbitTemplate发消息
|
||||||
|
// rabbitTemplate.convertAndSend(RabbitConstants.SEND_CODE_BY_PHONE,"",message -> {
|
||||||
|
// message.getMessageProperties().setMessageId(UUID.randomUUID().toString().replaceAll("-",""));
|
||||||
|
// return message;
|
||||||
|
// });
|
||||||
|
return Result.success("发送成功,验证码为:"+code);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result phoneLogin(LoginRequest loginRequest) {
|
||||||
|
Result<UserInfo> result = userServiceFeign.findPhone(loginRequest.getPhone());
|
||||||
|
UserInfo data = result.getData();
|
||||||
|
Assert.notNull(
|
||||||
|
data,"请注册"
|
||||||
|
);
|
||||||
|
if (StringUtils.isAllBlank(loginRequest.getCode(),loginRequest.getCode())){
|
||||||
|
throw new BizException(408,"手机号验证码为空");
|
||||||
|
}
|
||||||
|
String code = redisCache.getCacheObject("send_code" + loginRequest.getPhone());
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(code)){
|
||||||
|
throw new BizException(408,"验证码已过期");
|
||||||
|
}
|
||||||
|
if (!loginRequest.getCode().equals(code)){
|
||||||
|
throw new BizException(408,"验证码错误");
|
||||||
|
}
|
||||||
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
|
String userKey = IdUtils.genId();
|
||||||
|
map.put(JwtConstants.USER_KEY,userKey);
|
||||||
|
String token = JwtUtils.createToken(map);
|
||||||
|
redisCache.setCacheObject(TokenConstants.LOGIN_TOKEN_KEY+token,data,TokenConstants.EXPIRATION, TimeUnit.HOURS);
|
||||||
|
JwtResponse jwtResponse = new JwtResponse();
|
||||||
|
jwtResponse.setToken(token);
|
||||||
|
jwtResponse.setEndTim(TokenConstants.EXPIRATION);
|
||||||
|
return Result.success(jwtResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result phoneRegister(UserInfoVo userInfoVo) {
|
||||||
|
String salt = RandomUtil.randomNumbers(6);
|
||||||
|
String password = SecureUtil.md5(userInfoVo.getPassword()+ "|" + salt);
|
||||||
|
UserInfo userInfo = UserInfo.builder()
|
||||||
|
.username(userInfoVo.getUsername())
|
||||||
|
.password(password)
|
||||||
|
.salt(salt)
|
||||||
|
.nickname(userInfoVo.getNickname())
|
||||||
|
.phone(userInfoVo.getPhone())
|
||||||
|
.email(userInfoVo.getEmail())
|
||||||
|
.header(userInfoVo.getHeader())
|
||||||
|
.gender(userInfoVo.getGender())
|
||||||
|
.birthday(userInfoVo.getBirthday())
|
||||||
|
.city(userInfoVo.getCity())
|
||||||
|
.role(userInfoVo.getRole())
|
||||||
|
.sign(userInfoVo.getSign())
|
||||||
|
.sourceType(userInfoVo.getSourceType())
|
||||||
|
.integration(userInfoVo.getIntegration())
|
||||||
|
.status(userInfoVo.getStatus())
|
||||||
|
.identityFront(userInfoVo.getIdentityFront())
|
||||||
|
.identityReverse(userInfoVo.getIdentityReverse())
|
||||||
|
.identityAuthentication(userInfoVo.getIdentityAuthentication())
|
||||||
|
.checkState(userInfoVo.getCheckState())
|
||||||
|
.createTime(new Date())
|
||||||
|
.build();
|
||||||
|
userServiceFeign.register(userInfo);
|
||||||
|
return Result.success("注册成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<UserInfo> userInfo() {
|
||||||
|
String token = request.getHeader(TokenConstants.LOGIN_TOKEN_KEY);
|
||||||
|
if (StringUtils.isBlank(token)){
|
||||||
|
throw new BizException(401,"未登录");
|
||||||
|
}
|
||||||
|
UserInfo userInfo = redisCache.getCacheObject(TokenConstants.LOGIN_TOKEN_KEY + token);
|
||||||
|
return Result.success(userInfo);
|
||||||
|
}
|
||||||
|
}
|
|
@ -78,11 +78,11 @@
|
||||||
<!-- <version>3.3.0</version>-->
|
<!-- <version>3.3.0</version>-->
|
||||||
<!-- </dependency>-->
|
<!-- </dependency>-->
|
||||||
<!--糊涂工具-->
|
<!--糊涂工具-->
|
||||||
<!-- <dependency>-->
|
<dependency>
|
||||||
<!-- <groupId>cn.hutool</groupId>-->
|
<groupId>cn.hutool</groupId>
|
||||||
<!-- <artifactId>hutool-all</artifactId>-->
|
<artifactId>hutool-all</artifactId>
|
||||||
<!-- <version>4.1.1</version>-->
|
<version>4.1.1</version>
|
||||||
<!-- </dependency>-->
|
</dependency>
|
||||||
<!--FastJson2 json工具-->
|
<!--FastJson2 json工具-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.fastjson2</groupId>
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
|
@ -153,6 +153,21 @@
|
||||||
<artifactId>tomcat-embed-core</artifactId>
|
<artifactId>tomcat-embed-core</artifactId>
|
||||||
<version>9.0.83</version>
|
<version>9.0.83</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--RabbitMQ依赖-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>redis.clients</groupId>
|
||||||
|
<artifactId>jedis</artifactId>
|
||||||
|
<version>3.8.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun</groupId>
|
||||||
|
<artifactId>dysmsapi20170525</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,108 @@
|
||||||
|
package com.mall.common.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户实体类
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@TableName("user_info")
|
||||||
|
public class UserInfo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
/**
|
||||||
|
* 盐
|
||||||
|
*/
|
||||||
|
private String salt;
|
||||||
|
/**
|
||||||
|
* 昵称
|
||||||
|
*/
|
||||||
|
private String nickname;
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
private String phone;
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
private String email;
|
||||||
|
/**
|
||||||
|
* 头像
|
||||||
|
*/
|
||||||
|
private String header;
|
||||||
|
/**
|
||||||
|
* 性别
|
||||||
|
*/
|
||||||
|
private Integer gender;
|
||||||
|
/**
|
||||||
|
* 生日
|
||||||
|
*/
|
||||||
|
private Date birthday;
|
||||||
|
/**
|
||||||
|
* 城市
|
||||||
|
*/
|
||||||
|
private String city;
|
||||||
|
/**
|
||||||
|
* 角色
|
||||||
|
*/
|
||||||
|
private String role;
|
||||||
|
/**
|
||||||
|
* 个性签名
|
||||||
|
*/
|
||||||
|
private String sign;
|
||||||
|
/**
|
||||||
|
* 来源
|
||||||
|
*/
|
||||||
|
private Integer sourceType;
|
||||||
|
/**
|
||||||
|
* 积分
|
||||||
|
*/
|
||||||
|
private int integration;
|
||||||
|
/**
|
||||||
|
* 用户状态
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
/**
|
||||||
|
* 身份证正面
|
||||||
|
*/
|
||||||
|
private String identityFront;
|
||||||
|
/**
|
||||||
|
* 身份证反面
|
||||||
|
*/
|
||||||
|
private String identityReverse;
|
||||||
|
/**
|
||||||
|
* 身份证视频认证
|
||||||
|
*/
|
||||||
|
private String identityAuthentication;
|
||||||
|
/**
|
||||||
|
* 审核状态
|
||||||
|
*/
|
||||||
|
private Integer checkState;
|
||||||
|
/**
|
||||||
|
* 注册时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.mall.common.domain.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: lzh
|
||||||
|
* @CreateTime: 2024-04-22 18:48
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class LoginRequest {
|
||||||
|
private String phone;
|
||||||
|
private String code;
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.mall.common.domain.response;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: lzh
|
||||||
|
* @CreateTime: 2024-04-22 18:34
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class JwtResponse {
|
||||||
|
private String token;
|
||||||
|
private Long endTim;
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.mall.common.domain.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: lzh
|
||||||
|
* @CreateTime: 2024-04-22 17:03
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class LoginVo {
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
}
|
|
@ -0,0 +1,105 @@
|
||||||
|
package com.mall.common.domain.vo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: lzh
|
||||||
|
* @CreateTime: 2024-04-22 19:45
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class UserInfoVo {
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
/**
|
||||||
|
* 盐
|
||||||
|
*/
|
||||||
|
private String salt;
|
||||||
|
/**
|
||||||
|
* 昵称
|
||||||
|
*/
|
||||||
|
private String nickname;
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
private String phone;
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
private String email;
|
||||||
|
/**
|
||||||
|
* 头像
|
||||||
|
*/
|
||||||
|
private String header;
|
||||||
|
/**
|
||||||
|
* 性别
|
||||||
|
*/
|
||||||
|
private Integer gender;
|
||||||
|
/**
|
||||||
|
* 生日
|
||||||
|
*/
|
||||||
|
private Date birthday;
|
||||||
|
/**
|
||||||
|
* 城市
|
||||||
|
*/
|
||||||
|
private String city;
|
||||||
|
/**
|
||||||
|
* 角色
|
||||||
|
*/
|
||||||
|
private String role;
|
||||||
|
/**
|
||||||
|
* 个性签名
|
||||||
|
*/
|
||||||
|
private String sign;
|
||||||
|
/**
|
||||||
|
* 来源
|
||||||
|
*/
|
||||||
|
private Integer sourceType;
|
||||||
|
/**
|
||||||
|
* 积分
|
||||||
|
*/
|
||||||
|
private int integration;
|
||||||
|
/**
|
||||||
|
* 用户状态
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
/**
|
||||||
|
* 身份证正面
|
||||||
|
*/
|
||||||
|
private String identityFront;
|
||||||
|
/**
|
||||||
|
* 身份证反面
|
||||||
|
*/
|
||||||
|
private String identityReverse;
|
||||||
|
/**
|
||||||
|
* 身份证视频认证
|
||||||
|
*/
|
||||||
|
private String identityAuthentication;
|
||||||
|
/**
|
||||||
|
* 审核状态
|
||||||
|
*/
|
||||||
|
private Integer checkState;
|
||||||
|
/**
|
||||||
|
* 注册时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
package com.mall.common.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.aliyun.dysmsapi20170525.Client;
|
||||||
|
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
|
||||||
|
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
||||||
|
import com.aliyun.teaopenapi.models.Config;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信工具类
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
public class TelSmsUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限
|
||||||
|
*/
|
||||||
|
private static String accessKeyId = "LTAIEVXszCmcd1T5";
|
||||||
|
private static String accessKeySecret = "2zHwciQXln8wExSEnkIYtRTSwLeRNd";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信访问域名
|
||||||
|
*/
|
||||||
|
private static String endpoint = "dysmsapi.aliyuncs.com";
|
||||||
|
/**
|
||||||
|
* 短信签名
|
||||||
|
*/
|
||||||
|
private static String signName = "登录验证";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例化短信对象
|
||||||
|
*/
|
||||||
|
private static Client client;
|
||||||
|
|
||||||
|
static {
|
||||||
|
log.info("初始化短信服务开始");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
try {
|
||||||
|
client = initClient();
|
||||||
|
log.info("初始化短信成功:{}",signName);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
log.info("初始化短信服务结束:耗时:{}MS",(System.currentTimeMillis()-startTime));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 初始化短信对象
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private static Client initClient() throws Exception{
|
||||||
|
Config config = new Config()
|
||||||
|
// 您的AccessKey ID
|
||||||
|
.setAccessKeyId(accessKeyId)
|
||||||
|
// 您的AccessKey Secret
|
||||||
|
.setAccessKeySecret(accessKeySecret);
|
||||||
|
// 访问的域名
|
||||||
|
config.endpoint = endpoint;
|
||||||
|
return new Client(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送单条短信
|
||||||
|
* @param tel
|
||||||
|
* @param templateCode SMS_153991546
|
||||||
|
* @param sendDataMap
|
||||||
|
*/
|
||||||
|
public static String sendSms(String tel , String templateCode , Map<String,String> sendDataMap){
|
||||||
|
SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
||||||
|
.setPhoneNumbers(tel)
|
||||||
|
.setSignName(signName)
|
||||||
|
.setTemplateCode(templateCode)
|
||||||
|
.setTemplateParam(JSONObject.toJSONString(sendDataMap));
|
||||||
|
SendSmsResponse sendSmsResponse = null;
|
||||||
|
try {
|
||||||
|
log.info("发送短信验证码:消息内容是:【{}】", JSONObject.toJSONString(sendDataMap));
|
||||||
|
sendSmsResponse = client.sendSms(sendSmsRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("短信发送异常,手机号:【{}】,短信内容:【{}】,异常信息:【{}】", tel, sendDataMap, e);
|
||||||
|
}
|
||||||
|
return JSONObject.toJSONString(sendSmsResponse.getBody());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package com.mall;
|
package com.mall;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@ -12,8 +13,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
* @Description: TODO
|
* @Description: TODO
|
||||||
*/
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@MapperScan("com.mall.system.mapper")
|
||||||
public class MallSystemApplication {
|
public class MallSystemApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(MallSystemApplication.class);
|
SpringApplication.run(MallSystemApplication.class, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.mall.system.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.mall.common.domain.UserInfo;
|
||||||
|
import com.mall.common.result.Result;
|
||||||
|
import com.mall.system.service.UserService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: lzh
|
||||||
|
* @CreateTime: 2024-04-22 17:05
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询用户名和密码
|
||||||
|
* @return userInfo
|
||||||
|
*/
|
||||||
|
@PostMapping("findLogin/{username}")
|
||||||
|
public Result<UserInfo> findLogin(@PathVariable String username){
|
||||||
|
LambdaQueryWrapper<UserInfo> userInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
userInfoLambdaQueryWrapper.eq(UserInfo::getUsername,username);
|
||||||
|
UserInfo userInfo = userService.getOne(userInfoLambdaQueryWrapper);
|
||||||
|
return Result.success(userInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询手机号
|
||||||
|
* @return userInfo
|
||||||
|
*/
|
||||||
|
@GetMapping("findPhone/{phone}")
|
||||||
|
public Result<UserInfo> findPhone(@PathVariable("phone") String phone){
|
||||||
|
Result result = userService.findPhone(phone);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册
|
||||||
|
* @return userInfo
|
||||||
|
*/
|
||||||
|
@PostMapping("register")
|
||||||
|
public Result<UserInfo> register(@RequestBody UserInfo userInfo){
|
||||||
|
userService.register(userInfo);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.mall.system.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.mall.common.domain.UserInfo;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: lzh
|
||||||
|
* @CreateTime: 2024-04-22 17:13
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface UserMapper extends BaseMapper<UserInfo> {
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.mall.system.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.mall.common.domain.UserInfo;
|
||||||
|
import com.mall.common.result.Result;
|
||||||
|
|
||||||
|
public interface UserService extends IService<UserInfo> {
|
||||||
|
|
||||||
|
Result findPhone(String phone);
|
||||||
|
|
||||||
|
void register(UserInfo userInfo);
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.mall.system.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.mall.common.domain.UserInfo;
|
||||||
|
import com.mall.common.result.Result;
|
||||||
|
import com.mall.system.mapper.UserMapper;
|
||||||
|
import com.mall.system.service.UserService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: lzh
|
||||||
|
* @CreateTime: 2024-04-22 17:06
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class UserServiceImpl extends ServiceImpl<UserMapper, UserInfo>
|
||||||
|
implements UserService {
|
||||||
|
@Resource
|
||||||
|
private UserMapper userMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result findPhone(String phone) {
|
||||||
|
UserInfo userInfo = this.getOne(new QueryWrapper<UserInfo>().lambda()
|
||||||
|
.eq(UserInfo::getPhone, phone));
|
||||||
|
return Result.success(userInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register(UserInfo userInfo) {
|
||||||
|
//校验手机号
|
||||||
|
if (this.getOne(new QueryWrapper<UserInfo>().lambda()
|
||||||
|
.eq(UserInfo::getPhone, userInfo.getPhone())) != null) {
|
||||||
|
throw new RuntimeException("手机号已存在");
|
||||||
|
}
|
||||||
|
this.save(userInfo);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue