登录注册接口拆分
This commit is contained in:
parent
beef5768d3
commit
cb1e4eed1f
|
|
@ -5,6 +5,8 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sqx.common.annotation.Debounce;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.dto.LoginDTO;
|
||||
import com.sqx.modules.app.dto.RegisterDTO;
|
||||
import com.sqx.modules.app.entity.UserEntity;
|
||||
import com.sqx.modules.app.service.IAppleService;
|
||||
import com.sqx.modules.app.service.UserService;
|
||||
|
|
@ -19,6 +21,7 @@ import io.swagger.annotations.ApiOperation;
|
|||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import weixin.popular.api.SnsAPI;
|
||||
import weixin.popular.bean.sns.SnsToken;
|
||||
|
|
@ -142,7 +145,6 @@ public class AppLoginController {
|
|||
|
||||
|
||||
@RequestMapping(value = "/registerCode", method = RequestMethod.POST)
|
||||
@ApiOperation("app或h5注册或登录")
|
||||
@ResponseBody
|
||||
@Debounce(interval = 2500, value = "#phone")
|
||||
public Result registerCode(@RequestParam String phone,String msg,String platform,Integer sysPhone,
|
||||
|
|
@ -150,6 +152,21 @@ public class AppLoginController {
|
|||
return userService.registerCode(phone,msg,platform,sysPhone,password,inviterCode,wxId,qdCode);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@ResponseBody
|
||||
@Debounce(interval = 2500, value = "#phone")
|
||||
public Result login(@RequestBody @Validated LoginDTO loginDTO) {
|
||||
return userService.login(loginDTO);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/register")
|
||||
@ApiOperation("app或h5注册或登录")
|
||||
@ResponseBody
|
||||
@Debounce(interval = 2500, value = "#phone")
|
||||
public Result register(@RequestBody RegisterDTO registerDTO) {
|
||||
return userService.register(registerDTO);
|
||||
}
|
||||
|
||||
@PostMapping("/bindWxOpenPhone")
|
||||
@ApiOperation("微信公众号绑定手机号")
|
||||
public Result bindWxOpenPhone(Long userId,String phone,String msg){
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
package com.sqx.modules.app.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
@Data
|
||||
public class LoginDTO {
|
||||
@NotEmpty
|
||||
private String phone;
|
||||
@NotEmpty
|
||||
private String password;
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.sqx.modules.app.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
@Data
|
||||
public class RegisterDTO {
|
||||
@NotEmpty
|
||||
private String phone;
|
||||
@NotEmpty
|
||||
private String password;
|
||||
@NotEmpty
|
||||
private String msg;
|
||||
@NotEmpty
|
||||
private String platform;
|
||||
private String inviterCode;
|
||||
private String qdCode;
|
||||
private Integer sysPhone;
|
||||
}
|
||||
|
|
@ -7,6 +7,8 @@ import com.sqx.common.utils.PageUtils;
|
|||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.dto.AuthCertNoDTO;
|
||||
import com.sqx.modules.app.dto.AuthDTO;
|
||||
import com.sqx.modules.app.dto.LoginDTO;
|
||||
import com.sqx.modules.app.dto.RegisterDTO;
|
||||
import com.sqx.modules.app.entity.UserEntity;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
|
@ -158,8 +160,6 @@ public interface UserService extends IService<UserEntity> {
|
|||
*
|
||||
* @param phone 手机号
|
||||
* @param msg 验证按
|
||||
* @param pwd 密码
|
||||
* @param platform 来源 app h5
|
||||
* @return
|
||||
*/
|
||||
Result registerCode(String phone, String msg, String platform, Integer sysPhone,String password,
|
||||
|
|
@ -174,11 +174,8 @@ public interface UserService extends IService<UserEntity> {
|
|||
/**
|
||||
* app或h5登录
|
||||
*
|
||||
* @param phone 手机号
|
||||
* @param pwd 密码
|
||||
* @return
|
||||
*/
|
||||
Result login(String phone, String pwd);
|
||||
Result login(LoginDTO loginDTO);
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -235,4 +232,6 @@ public interface UserService extends IService<UserEntity> {
|
|||
void addBlackUser(Long userId,String behavior);
|
||||
|
||||
UserEntity queryByInvitationCodeOrUserId(Long inviterUserId, String invitationCode);
|
||||
|
||||
Result register(RegisterDTO registerDTO);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,9 +42,7 @@ import com.sqx.common.utils.Result;
|
|||
import com.sqx.modules.app.dao.MsgDao;
|
||||
import com.sqx.modules.app.dao.UserDao;
|
||||
import com.sqx.modules.app.dao.UserVipDao;
|
||||
import com.sqx.modules.app.dto.AuthCertNoDTO;
|
||||
import com.sqx.modules.app.dto.AuthDTO;
|
||||
import com.sqx.modules.app.dto.AuthRespDTO;
|
||||
import com.sqx.modules.app.dto.*;
|
||||
import com.sqx.modules.app.entity.*;
|
||||
import com.sqx.modules.app.mapper.TbUserBlacklistMapper;
|
||||
import com.sqx.modules.app.response.CourseOrderResponse;
|
||||
|
|
@ -885,6 +883,98 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|||
return getResult(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result login(LoginDTO loginDTO) {
|
||||
//校验手机号是否存在
|
||||
UserEntity userInfo = queryByPhone(loginDTO.getPhone());
|
||||
if (userInfo == null) {
|
||||
return Result.error("未注册, 请先注册");
|
||||
}
|
||||
|
||||
//密码登录
|
||||
if (StringUtils.isEmpty(userInfo.getPassword())) {
|
||||
return Result.error("当前账号未绑定密码,请前往忘记密码中进行重置!");
|
||||
}
|
||||
|
||||
if (!userInfo.getPassword().equals(DigestUtils.sha256Hex(loginDTO.getPassword()))) {
|
||||
return Result.error("账号或密码不正确!");
|
||||
}
|
||||
|
||||
if (userInfo.getStatus().equals(2)) {
|
||||
return Result.error("账号已被禁用,请联系客服处理!");
|
||||
}
|
||||
|
||||
// 实名认证信息
|
||||
UserInfo idCardAuth = userInfoService.getByUserId(userInfo.getUserId());
|
||||
if (idCardAuth != null && StrUtil.isNotBlank(idCardAuth.getCertNo())) {
|
||||
TbUserBlacklist blacklist = tbUserBlacklistMapper.selectOne(Wrappers.<TbUserBlacklist>lambdaQuery().eq(TbUserBlacklist::getIdCardNo, idCardAuth.getCertNo()));
|
||||
// 如果被拉黑了,不要提示的那么直白,需要换个说法
|
||||
if (blacklist != null) {
|
||||
return Result.error("系统正在维护中,请稍后再试!");
|
||||
}
|
||||
}
|
||||
userInfo.setUpdateTime(DateUtil.date().toString());
|
||||
baseMapper.updateById(userInfo);
|
||||
return getResult(userInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result register(RegisterDTO registerDTO) {
|
||||
//校验手机号是否存在
|
||||
UserEntity userInfo = queryByPhone(registerDTO.getPhone());
|
||||
if (userInfo != null) {
|
||||
return Result.error("此号码已注册");
|
||||
}
|
||||
|
||||
Msg msg1 = msgDao.findByPhoneAndCode(registerDTO.getPhone(), registerDTO.getMsg());
|
||||
if (msg1 == null) {
|
||||
return Result.error("验证码不正确!");
|
||||
}
|
||||
|
||||
userInfo = new UserEntity();
|
||||
UserEntity userEntity;
|
||||
if (StringUtils.isNotEmpty(registerDTO.getInviterCode())) {
|
||||
userEntity = queryByInvitationCode(registerDTO.getInviterCode());
|
||||
if (userEntity == null) {
|
||||
return Result.error("邀请码不正确!");
|
||||
}
|
||||
} else {
|
||||
userInfo.setInviterCode(commonInfoService.findOne(88).getValue());
|
||||
userEntity = queryByInvitationCodeOrUserId(userInfo.getInviterUserId(), userInfo.getInviterCode());
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(registerDTO.getQdCode())) {
|
||||
registerDTO.setQdCode(userEntity.getQdCode());
|
||||
} else {
|
||||
SysUserEntity sysUserEntity = sysUserService.selectSysUserByQdCode(registerDTO.getQdCode());
|
||||
if (sysUserEntity == null) {
|
||||
return Result.error("请使用正确的渠道码!");
|
||||
}
|
||||
}
|
||||
userInfo.setQdCode(registerDTO.getQdCode());
|
||||
userInfo.setPhone(registerDTO.getPhone());
|
||||
userInfo.setUserName(registerDTO.getPhone().replaceAll("(\\d{3})\\d*([0-9a-zA-Z]{4})", "$1****$2"));
|
||||
userInfo.setPlatform(registerDTO.getPlatform());
|
||||
userInfo.setCreateTime(DateUtil.date().toString());
|
||||
userInfo.setSysPhone(registerDTO.getSysPhone());
|
||||
userInfo.setPassword(DigestUtils.sha256Hex(registerDTO.getPassword()));
|
||||
userInfo.setStatus(1);
|
||||
userInfo.setUpdateTime(DateUtil.date().toString());
|
||||
userInfo.setRate(new BigDecimal(commonInfoService.findOne(420).getValue()));
|
||||
userInfo.setTwoRate(new BigDecimal(commonInfoService.findOne(421).getValue()));
|
||||
Long snowFlakeId = InvitationCodeUtil.getSnowFlakeId();
|
||||
userInfo.setUserId(snowFlakeId);
|
||||
baseMapper.insert(userInfo);
|
||||
userInfo.setInvitationCode(InvitationCodeUtil.toSerialCode(userInfo.getUserId()));
|
||||
baseMapper.updateById(userInfo);
|
||||
|
||||
msgDao.deleteById(msg1.getId());
|
||||
if (userEntity != null) {
|
||||
inviteService.saveBody(userInfo.getUserId(), userEntity);
|
||||
}
|
||||
return getResult(userInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result registerCode(String phone, String msg, String platform, Integer sysPhone, String password,
|
||||
String inviterCode, String wxId, String qdCode) {
|
||||
|
|
@ -1045,25 +1135,6 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Result login(String phone, String pwd) {
|
||||
UserEntity userEntity = queryByPhone(phone);
|
||||
if (userEntity == null) {
|
||||
return Result.error("手机号未注册!");
|
||||
}
|
||||
if (!userEntity.getPassword().equals(DigestUtils.sha256Hex(pwd))) {
|
||||
return Result.error("密码不正确!");
|
||||
}
|
||||
if (userEntity.getStatus().equals(2)) {
|
||||
return Result.error("账号已被禁用,请联系客服处理!");
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
userEntity.setUpdateTime(sdf.format(new Date()));
|
||||
baseMapper.updateById(userEntity);
|
||||
return getResult(userEntity);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Result getResult(UserEntity user) {
|
||||
//生成token
|
||||
|
|
@ -1662,8 +1733,8 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|||
|
||||
|
||||
@Override
|
||||
public void addBlackUser(Long userId,String behavior) {
|
||||
log.info("异常用户id, 异常操作: {},{}", userId,behavior);
|
||||
public void addBlackUser(Long userId, String behavior) {
|
||||
log.info("异常用户id, 异常操作: {},{}", userId, behavior);
|
||||
UserInfo userInfo = userInfoService.getOne(new LambdaQueryWrapper<UserInfo>().eq(UserInfo::getUserId, userId));
|
||||
if (userInfo != null && StrUtil.isNotBlank(userInfo.getCertNo())) {
|
||||
TbUserBlacklist userBlacklist = new TbUserBlacklist();
|
||||
|
|
@ -1675,7 +1746,7 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|||
update(null, new LambdaUpdateWrapper<UserEntity>().eq(UserEntity::getUserId, userId)
|
||||
.set(UserEntity::getStatus, 0)
|
||||
.set(UserEntity::getPlatform, behavior)
|
||||
.set(UserEntity::getUpdateTime,DateUtil.now()));
|
||||
.set(UserEntity::getUpdateTime, DateUtil.now()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue