1.remove deviceId login

main
Gary 10 months ago
parent 4ec0092e2a
commit 93872f11cc

@ -88,15 +88,13 @@ public class UserController {
}
@ApiOperation(value = "2.登录/注册后返回token")
@PostMapping("/appLogin/{deviceId}/{deviceBrand}/{mobile}/{mobileCheckCode}")
@PostMapping("/appLogin/{mobile}/{mobileCheckCode}")
@GlobalInterceptor
public Result appLogin( @PathVariable @VerifyParam(required=true,max=32) String deviceId,
@PathVariable @VerifyParam(required=false,max=30) String deviceBrand,
@PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.MOBILE)String mobile,
public Result appLogin( @PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.MOBILE)String mobile,
@PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.MOBILE_CHECK_CODE) String mobileCheckCode
) {
// 得到缓存中的验证码
String redisKey=Constants.REDIS_KEY_MOBILE_CHECK_CODE+deviceId;
String redisKey=Constants.REDIS_KEY_MOBILE_CHECK_CODE+mobile;
try {
UserRespDTO userRespDTO=new UserRespDTO();
String checkcodeRedis = (String) redisTemplate.opsForValue().get(redisKey);
@ -106,7 +104,7 @@ public class UserController {
if (!checkcodeRedis.equals(mobileCheckCode)) {
return Result.failed(StatusCode.USER_VERIFICATION_CODE_MISMATCH);
}
User user = userService.loginOrRegister(deviceId,deviceBrand,mobile);
User user = userService.loginOrRegister(mobile);
BeanUtils.copyProperties(user, userRespDTO);
String token = jwtUtil.createJWT(user.getId(),user.getMobile(),"user");
userRespDTO.setToken(token);
@ -114,6 +112,7 @@ public class UserController {
}finally {
redisTemplate.delete(redisKey);
}
}
@ApiOperation(value = "3.游客登录返回token", notes = "token中的subject和roles均为tourist")
@ -131,11 +130,10 @@ public class UserController {
*
*/
@ApiOperation(value = "1.发送短信验证码有效期15分钟")
@PostMapping("/sendsms/{deviceId}/{mobile}")
@PostMapping("/sendsms/{mobile}")
@GlobalInterceptor
public Result<Void> sendSms(@PathVariable @VerifyParam(required=true,max=32) String deviceId,
@PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.MOBILE)String mobile) {
userService.sendSms(deviceId,mobile);
public Result<Void> sendSms(@PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.MOBILE)String mobile) {
userService.sendSms(mobile);
return Result.success();
}
@ -158,17 +156,17 @@ public class UserController {
*
*/
@ApiOperation(value = "4.三次短信验证码失败后获取图行验证码有效期10分钟")
@GetMapping("/imageCheckCode/{deviceId}")
@GetMapping("/imageCheckCode/{mobile}")
@GlobalInterceptor
public void imageCheckCode(HttpServletResponse response,
@PathVariable @VerifyParam(required=true,max=32) String deviceId) throws IOException {
@PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.MOBILE) String mobile) throws IOException {
CreateImageCode vCode = new CreateImageCode(130,38,5,10);
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
String code=vCode.getCode();
String redisKey=Constants.REDIS_KEY_IMAGE_CHECK_CODE+deviceId;
String redisKey=Constants.REDIS_KEY_IMAGE_CHECK_CODE+mobile;
redisTemplate.opsForValue().set(redisKey,code,10,TimeUnit.MINUTES);
vCode.write(response.getOutputStream());
}

@ -45,7 +45,7 @@ public class UserService {
@Autowired
private UserDao userDao;
@Autowired
private IdWorker idWorker;
@ -55,7 +55,6 @@ public class UserService {
@Autowired
private RabbitTemplate rabbitTemplate;
@Autowired
private BCryptPasswordEncoder encoder;
@ -65,7 +64,6 @@ public class UserService {
@Autowired
private JwtUtil jwtUtil;
/**
* token
*/
@ -73,22 +71,22 @@ public class UserService {
String userid = (String) request.getAttribute("userid");
String mobile = (String) request.getAttribute("mobile");
System.out.println("用户ID"+userid);
System.out.println("手机号"+mobile);
System.out.println("用户ID" + userid);
System.out.println("手机号" + mobile);
}
/**
*
*
* @return
*/
public List<User> findAll() {
return userDao.findAll();
}
/**
* +
*
* @param whereMap
* @param page
* @param size
@ -96,13 +94,13 @@ public class UserService {
*/
public Page<User> findSearch(Map whereMap, int page, int size) {
Specification<User> specification = createSpecification(whereMap);
PageRequest pageRequest = PageRequest.of(page-1, size);
PageRequest pageRequest = PageRequest.of(page - 1, size);
return userDao.findAll(specification, pageRequest);
}
/**
*
*
* @param whereMap
* @return
*/
@ -113,6 +111,7 @@ public class UserService {
/**
* ID
*
* @param id
* @return
*/
@ -122,13 +121,14 @@ public class UserService {
/**
*
*
* @param user
*/
public void add(User user) {
user.setId( idWorker.nextId()+"" );
user.setFanscount(0); //粉丝数
user.setFollowcount(0); //关注数
user.setOnline(0L); //在线时长
user.setId(idWorker.nextId() + "");
user.setFanscount(0); // 粉丝数
user.setFollowcount(0); // 关注数
user.setOnline(0L); // 在线时长
user.setRegdate(new Date());
user.setUpdatedate(new Date());
user.setLastdate(new Date());
@ -139,6 +139,7 @@ public class UserService {
/**
*
*
* @param user
*/
public void update(User user) {
@ -147,12 +148,13 @@ public class UserService {
/**
*
*
* @param id
*/
public void deleteById(String id) {
String token = (String) request.getAttribute("claims_admin");
if (token==null || "".equals(token)) {
if (token == null || "".equals(token)) {
throw new RuntimeException("权限不足");
}
userDao.deleteById(id);
@ -160,6 +162,7 @@ public class UserService {
/**
*
*
* @param searchMap
* @return
*/
@ -170,106 +173,111 @@ public class UserService {
@Override
public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicateList = new ArrayList<Predicate>();
// ID
if (searchMap.get("id")!=null && !"".equals(searchMap.get("id"))) {
predicateList.add(cb.like(root.get("id").as(String.class), "%"+(String)searchMap.get("id")+"%"));
}
// 手机号码
if (searchMap.get("mobile")!=null && !"".equals(searchMap.get("mobile"))) {
predicateList.add(cb.like(root.get("mobile").as(String.class), "%"+(String)searchMap.get("mobile")+"%"));
}
// 用户名
if (searchMap.get("loginname")!=null && !"".equals(searchMap.get("loginname"))) {
predicateList.add(cb.like(root.get("loginname").as(String.class), "%"+(String)searchMap.get("loginname")+"%"));
}
// 密码
if (searchMap.get("password")!=null && !"".equals(searchMap.get("password"))) {
predicateList.add(cb.like(root.get("password").as(String.class), "%"+(String)searchMap.get("password")+"%"));
}
// 昵称
if (searchMap.get("nickname")!=null && !"".equals(searchMap.get("nickname"))) {
predicateList.add(cb.like(root.get("nickname").as(String.class), "%"+(String)searchMap.get("nickname")+"%"));
}
// 性别
if (searchMap.get("sex")!=null && !"".equals(searchMap.get("sex"))) {
predicateList.add(cb.like(root.get("sex").as(String.class), "%"+(String)searchMap.get("sex")+"%"));
}
// 头像
if (searchMap.get("avatar")!=null && !"".equals(searchMap.get("avatar"))) {
predicateList.add(cb.like(root.get("avatar").as(String.class), "%"+(String)searchMap.get("avatar")+"%"));
}
// E-Mail
if (searchMap.get("email")!=null && !"".equals(searchMap.get("email"))) {
predicateList.add(cb.like(root.get("email").as(String.class), "%"+(String)searchMap.get("email")+"%"));
}
// 兴趣
if (searchMap.get("interest")!=null && !"".equals(searchMap.get("interest"))) {
predicateList.add(cb.like(root.get("interest").as(String.class), "%"+(String)searchMap.get("interest")+"%"));
}
// 个性
if (searchMap.get("personality")!=null && !"".equals(searchMap.get("personality"))) {
predicateList.add(cb.like(root.get("personality").as(String.class), "%"+(String)searchMap.get("personality")+"%"));
}
return cb.and( predicateList.toArray(new Predicate[predicateList.size()]));
// ID
if (searchMap.get("id") != null && !"".equals(searchMap.get("id"))) {
predicateList
.add(cb.like(root.get("id").as(String.class), "%" + (String) searchMap.get("id") + "%"));
}
// 手机号码
if (searchMap.get("mobile") != null && !"".equals(searchMap.get("mobile"))) {
predicateList.add(
cb.like(root.get("mobile").as(String.class), "%" + (String) searchMap.get("mobile") + "%"));
}
// 用户名
if (searchMap.get("loginname") != null && !"".equals(searchMap.get("loginname"))) {
predicateList.add(cb.like(root.get("loginname").as(String.class),
"%" + (String) searchMap.get("loginname") + "%"));
}
// 密码
if (searchMap.get("password") != null && !"".equals(searchMap.get("password"))) {
predicateList.add(cb.like(root.get("password").as(String.class),
"%" + (String) searchMap.get("password") + "%"));
}
// 昵称
if (searchMap.get("nickname") != null && !"".equals(searchMap.get("nickname"))) {
predicateList.add(cb.like(root.get("nickname").as(String.class),
"%" + (String) searchMap.get("nickname") + "%"));
}
// 性别
if (searchMap.get("sex") != null && !"".equals(searchMap.get("sex"))) {
predicateList
.add(cb.like(root.get("sex").as(String.class), "%" + (String) searchMap.get("sex") + "%"));
}
// 头像
if (searchMap.get("avatar") != null && !"".equals(searchMap.get("avatar"))) {
predicateList.add(
cb.like(root.get("avatar").as(String.class), "%" + (String) searchMap.get("avatar") + "%"));
}
// E-Mail
if (searchMap.get("email") != null && !"".equals(searchMap.get("email"))) {
predicateList.add(
cb.like(root.get("email").as(String.class), "%" + (String) searchMap.get("email") + "%"));
}
// 兴趣
if (searchMap.get("interest") != null && !"".equals(searchMap.get("interest"))) {
predicateList.add(cb.like(root.get("interest").as(String.class),
"%" + (String) searchMap.get("interest") + "%"));
}
// 个性
if (searchMap.get("personality") != null && !"".equals(searchMap.get("personality"))) {
predicateList.add(cb.like(root.get("personality").as(String.class),
"%" + (String) searchMap.get("personality") + "%"));
}
return cb.and(predicateList.toArray(new Predicate[predicateList.size()]));
}
};
}
public void sendSms(String deviceId,String mobile) {
public void sendSms(String mobile) {
// 生成6位数字随机数
String checkcode = RandomStringUtils.randomNumeric(6);
// 向缓存中放一份
String redisKey=Constants.REDIS_KEY_MOBILE_CHECK_CODE+deviceId;
redisTemplate.opsForValue().set(redisKey,checkcode,15, TimeUnit.MINUTES);
String redisKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + mobile;
redisTemplate.opsForValue().set(redisKey, checkcode, 15, TimeUnit.MINUTES);
// 向用户发一份
Map<String,String> map = new HashMap<>();
map.put("mobile",mobile);
map.put("checkcode",checkcode);
Map<String, String> map = new HashMap<>();
map.put("mobile", mobile);
map.put("checkcode", checkcode);
// rabbitTemplate.convertAndSend("sms",map);
// 在控制台放一份(方便测试)
System.out.println("验证码是:"+checkcode);
}
System.out.println("验证码是:" + checkcode);
}
public User login(String mobile, String password) {
// User user = userDao.findByLoginname(loginname);
User user = userDao.findByMobile(mobile);
if (user!=null && encoder.matches(password,user.getPassword())) {
if (user != null && encoder.matches(password, user.getPassword())) {
return user;
}
return null;
}
public void updatefanscountandfollowcount(int x, String userid, String friendid) {
userDao.updatefanscount(x,friendid);
userDao.updatefollowcount(x,userid);
}
public User loginOrRegister(String deviceId, String deviceBrand,String mobile) {
User user = userDao.findByMobile(mobile);
if(null==user) {
user=new User();
user.setId(String.valueOf(idWorker.nextId()));
user.setMobile(mobile);
user.setNickname("雀乐"+NickNameUtil.getRandomNickName());
//user.setDeviceId(deviceId);
//user.setDeviceBrand(deviceBrand);
userDao.save(user);
}
// else {
// User updateUser = new User();
// updateUser.setLastdate(new Date());
// updateUser.setDeviceId(deviceId);
// updateUser.setDeviceBrand(deviceBrand);
// userDao.updateById(updateUser,user.getId());
// }
return user;
}
public void updatefanscountandfollowcount(int x, String userid, String friendid) {
userDao.updatefanscount(x, friendid);
userDao.updatefollowcount(x, userid);
}
public User loginOrRegister(String mobile) {
User user = userDao.findByMobile(mobile);
if (null == user) {
user = new User();
user.setId(String.valueOf(idWorker.nextId()));
user.setMobile(mobile);
user.setNickname("雀乐" + NickNameUtil.getRandomNickName());
userDao.save(user);
} else {
user.setLastdate(new Date());
userDao.save(user);
}
return user;
}
public User findByMobile(String mobile) {
User user = userDao.findByMobile(mobile);
return user;

Loading…
Cancel
Save