| | |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.huaweicloud.sdk.core.exception.SdkErrorMessage; |
| | | import com.stylefeng.guns.core.shiro.ShiroKit; |
| | | import com.stylefeng.guns.core.util.JwtTokenUtil; |
| | | import com.stylefeng.guns.core.util.MD5Util; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"), |
| | | }) |
| | | public ResultUtil isFirst() { |
| | | AppUser appUser = appUserService.getAppUser(); |
| | | if (appUser == null){ |
| | | return ResultUtil.tokenErr("登录失效"); |
| | | } |
| | | Login userId = loginService.selectOne(new EntityWrapper<Login>() |
| | | .eq("userId", appUserService.getAppUser().getId())); |
| | | .eq("userId", appUser.getId())); |
| | | if (userId == null){ |
| | | // 首次登录 |
| | | Login login = new Login(); |
| | |
| | | public ResultUtil<String> updatePassword(String password, String newPassword,String code) { |
| | | try { |
| | | AppUser appUser = appUserService.getAppUser(); |
| | | if (appUser == null){ |
| | | return ResultUtil.tokenErr("登录失效"); |
| | | } |
| | | if (null == appUser) { |
| | | return ResultUtil.error("请先登录!", ""); |
| | | } |
| | |
| | | // 首次注册默认头像 |
| | | appUser1.setHeadImg("https://jkjianshen.obs.cn-north-4.myhuaweicloud.com/admin/8d9bb8b7fb9a4786a50b88863c7706ab.png"); |
| | | // appUser1.setConstellation(zodiacSign); |
| | | appUser1.setName(addAppUserVo.getPhone()); |
| | | appUser1.setAccount(addAppUserVo.getPhone()); |
| | | appUser1.setCode(UUIDUtil.getRandomCode(6).toUpperCase()); |
| | | appUser1.setName("用户-"+appUser1.getCode()); |
| | | appUser1.setHeight(155); |
| | | appUser1.setWeight(130D); |
| | | appUser1.setWaistline(100); |
| | | appUser1.setGender(1); |
| | | // 获取当前时间 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | // 将当前时间向前推30年 |
| | | calendar.add(Calendar.YEAR, -30); |
| | | Date date30YearsAgo = calendar.getTime(); |
| | | appUser1.setBirthday(date30YearsAgo); |
| | | // 根据邀请码 查询到用户 |
| | | if (StringUtils.hasLength(addAppUserVo.getInvitationCode())){ |
| | | AppUser code = appUserService.selectOne(new EntityWrapper<AppUser>() |
| | | .eq("code", addAppUserVo.getInvitationCode())); |
| | | if (code==null){ |
| | | return ResultUtil.errorInvite("邀请码无效",null); |
| | | return ResultUtil.errorInvite("邀请码无效",""); |
| | | } |
| | | appUser1.setInviteUserId(code.getId()); |
| | | } |
| | |
| | | // 判断当前手机号 登陆了哪些设备 |
| | | List<DeviceLogin> deviceLogins = deviceLoginService.selectList(queryWrapper); |
| | | List<String> collect = deviceLogins.stream().map(DeviceLogin::getDevice).collect(Collectors.toList()); |
| | | if (collect.size()>=5 &&!collect.contains(addAppUserVo.getCode2())){ |
| | | // 是一个新的设备登录 返回登陆失败的提示 |
| | | return ResultUtil.errorDevice("登录失败,同一账号一年内最多登录五部手机",null); |
| | | } |
| | | // if (collect.size()>=5 &&!collect.contains(addAppUserVo.getCode2())){ |
| | | // // 是一个新的设备登录 返回登陆失败的提示 |
| | | // return ResultUtil.errorDevice("登录失败,同一账号一年内最多登录五部手机",null); |
| | | // } |
| | | DeviceLogin deviceLogin1 = deviceLoginService.selectOne(new EntityWrapper<DeviceLogin>() |
| | | .eq("device", addAppUserVo.getCode2()) |
| | | .eq("userId", appUser1.getId())); |
| | |
| | | return ResultUtil.errorLogin("登录失败,您的账号已被冻结!",null); |
| | | } |
| | | if (StringUtils.hasLength(invitationCode)){ |
| | | |
| | | if (tAppUser.getCode().equals(invitationCode)){ |
| | | return ResultUtil.error("不能绑定自己",""); |
| | | } |
| | | if (tAppUser.getInviteUserId()!=null){ |
| | | ResultUtil.error("ss"); |
| | | // 登陆失败 |
| | | return ResultUtil.errorLogin("登录失败,已绑定其他用户",null); |
| | | return ResultUtil.error("该手机号已绑定其他邀请码",null); |
| | | }else{ |
| | | // 根据邀请码 去查询用户 |
| | | AppUser code3 = appUserService.selectOne(new EntityWrapper<AppUser>() |
| | | .eq("code", invitationCode)); |
| | | |
| | | if (code3!=null){ |
| | | if (code3.getInviteUserId().equals(tAppUser.getId())){ |
| | | return ResultUtil.error("邀请失败,当前邀请用户为您的邀请人", null); |
| | | } |
| | | } |
| | | // 根据邀请码 去查询用户 |
| | | |
| | | if (code3 == null){ |
| | | return ResultUtil.errorInvite("邀请码无效",null); |
| | | return ResultUtil.errorInvite("邀请码无效",""); |
| | | }else{ |
| | | tAppUser.setInviteUserId(code3.getId()); |
| | | appUserService.updateById(tAppUser); |
| | |
| | | // 判断当前手机号 登陆了哪些设备 |
| | | List<DeviceLogin> deviceLogins = deviceLoginService.selectList(queryWrapper); |
| | | List<String> collect = deviceLogins.stream().map(DeviceLogin::getDevice).collect(Collectors.toList()); |
| | | |
| | | if (collect.size()>=5 &&!collect.contains(code2)){ |
| | | // 是一个新的设备登录 返回登陆失败的提示 |
| | | return ResultUtil.errorDevice("登录失败,同一账号一年内最多登录五部手机",null); |
| | | } |
| | | // |
| | | // if (collect.size()>=5 &&!collect.contains(code2)){ |
| | | // // 是一个新的设备登录 返回登陆失败的提示 |
| | | // return ResultUtil.errorDevice("登录失败,同一账号一年内最多登录五部手机",null); |
| | | // } |
| | | DeviceLogin deviceLogin1 = deviceLoginService.selectOne(new EntityWrapper<DeviceLogin>() |
| | | .eq("device", code2) |
| | | .eq("userId", tAppUser.getId())); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | String s = ShiroKit.md5("123456", "SA;d5#"); |
| | | System.err.println(s); |
| | | } |
| | | @ResponseBody |
| | | @PostMapping("/base/appUser/loginWeChat") |
| | | @ApiOperation(value = "微信登录", tags = {"APP-登录注册"}) |
| | |
| | | tAppUser.setOpenId(loginWeChatVo.getOpenId()); |
| | | tAppUser.setPhone(loginWeChatVo.getPhone()); |
| | | tAppUser.setPassword(Md5Util.MD5Encode("111111", null)); |
| | | tAppUser.setName(loginWeChatVo.getNickname()); |
| | | tAppUser.setName("用户-"+s); |
| | | tAppUser.setHeadImg(loginWeChatVo.getHeadimgurl()); |
| | | tAppUser.setGender(loginWeChatVo.getSex()); |
| | | tAppUser.setState(1); |
| | | tAppUser.setHeadImg("https://jkjianshen.obs.cn-north-4.myhuaweicloud.com/admin/8d9bb8b7fb9a4786a50b88863c7706ab.png"); |
| | | tAppUser.setHeight(155); |
| | | tAppUser.setWeight(130D); |
| | | tAppUser.setWaistline(100); |
| | | tAppUser.setGender(1); |
| | | // 获取当前时间 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | // 将当前时间向前推30年 |
| | | calendar.add(Calendar.YEAR, -30); |
| | | Date date30YearsAgo = calendar.getTime(); |
| | | tAppUser.setBirthday(date30YearsAgo); |
| | | // 获取当前日期 |
| | | LocalDate currentDate = LocalDate.now(); |
| | | int month = currentDate.getMonthValue(); |
| | |
| | | // 判断当前手机号 登陆了哪些设备 |
| | | List<DeviceLogin> deviceLogins = deviceLoginService.selectList(queryWrapper); |
| | | List<String> collect = deviceLogins.stream().map(DeviceLogin::getDevice).collect(Collectors.toList()); |
| | | if (collect.size()>5){ |
| | | if (!collect.contains(loginWeChatVo.getCode2())){ |
| | | // 是一个新的设备登录 返回登陆失败的提示 |
| | | return ResultUtil.errorDevice("登录失败,同一账号一年内最多登录五部手机",null); |
| | | } |
| | | } |
| | | // if (collect.size()>5){ |
| | | // if (!collect.contains(loginWeChatVo.getCode2())){ |
| | | // // 是一个新的设备登录 返回登陆失败的提示 |
| | | // return ResultUtil.errorDevice("登录失败,同一账号一年内最多登录五部手机",null); |
| | | // } |
| | | // } |
| | | DeviceLogin deviceLogin1 = deviceLoginService.selectOne(new EntityWrapper<DeviceLogin>() |
| | | .eq("device", loginWeChatVo.getCode2()) |
| | | .eq("userId", tAppUser.getId())); |
| | |
| | | }) |
| | | public ResultUtil<String> setPhone(String phone, String code, String invitationCode) { |
| | | System.err.println("邀请码"+invitationCode); |
| | | AppUser appUser2 = appUserService.getAppUser(); |
| | | if (appUser2 == null){ |
| | | return ResultUtil.tokenErr("登录失效"); |
| | | } |
| | | if (StringUtils.hasLength(invitationCode)){ |
| | | // 根据邀请码查询用户id |
| | | AppUser appUser1 = appUserService.selectOne(new EntityWrapper<AppUser>() |
| | |
| | | .ne("state", 3)); |
| | | if (appUser1==null){ |
| | | return ResultUtil.errorInvite("邀请码无效",null); |
| | | }else{ |
| | | if (appUser1.getInviteUserId().equals(appUser2.getId())){ |
| | | return ResultUtil.error("邀请失败,当前邀请用户为您的邀请人", null); |
| | | } |
| | | } |
| | | } |
| | | AppUser appUser2 = appUserService.getAppUser(); |
| | | System.err.println("登录用户id"+appUser2.getId()); |
| | | System.err.println("手机号"+phone); |
| | | |
| | | // 先判断当前电话是否已经被绑定了 |
| | | AppUser appUser = appUserService.selectOne(new EntityWrapper<AppUser>() |
| | | .eq("phone", phone) |
| | |
| | | } |
| | | // 判断手机验证码是否相同 |
| | | String value = redisUtil.getValue(phone); |
| | | if (!code.equals("123456")){ |
| | | // if (!code.equals("123456")){ |
| | | if (null == value){ |
| | | return ResultUtil.error("验证码无效",null); |
| | | } |
| | | if (!code.equals(value)){ |
| | | return ResultUtil.error("验证码错误",null); |
| | | } |
| | | } |
| | | // } |
| | | // 如果绑定的手机号 已经注册过了 同时没有绑定微信id和苹果id 那么把openId修改过去 |
| | | AppUser appUser3 = appUserService.selectOne(new EntityWrapper<AppUser>() |
| | | .eq("phone", phone) |
| | |
| | | .isNull("appleId") |
| | | .ne("state", 3)); |
| | | // 微信绑定 |
| | | if (appUser3!=null && StringUtils.hasLength(appUser3.getOpenId())){ |
| | | if (appUser3!=null && StringUtils.hasLength(appUser2.getOpenId())){ |
| | | appUser3.setOpenId(appUser2.getOpenId()); |
| | | appUserService.updateById(appUser3); |
| | | // 同时删除这条数据 |
| | | appUserService.deleteById(appUser2.getId()); |
| | | if (StringUtils.hasLength(invitationCode)){ |
| | | if (appUser3.getInviteUserId()!=null){ |
| | | return ResultUtil.errorLogin("登录失败,已绑定其他用户",null); |
| | | return ResultUtil.error("该手机号已绑定其他邀请码",null); |
| | | } |
| | | if (appUser3.getCode().equals(invitationCode)){ |
| | | return ResultUtil.error("不能绑定自己",""); |
| | | } |
| | | // 根据邀请码查询用户id |
| | | AppUser appUser1 = appUserService.selectOne(new EntityWrapper<AppUser>() |
| | | .eq("code", invitationCode) |
| | | .ne("state", 3)); |
| | | if (appUser1==null){ |
| | | return ResultUtil.errorInvite("邀请码无效",null); |
| | | return ResultUtil.errorInvite("邀请码无效",""); |
| | | }else{ |
| | | if (appUser1.getInviteUserId().equals(appUser2.getId())){ |
| | | return ResultUtil.error("邀请失败,当前邀请用户为您的邀请人", null); |
| | | } |
| | | appUser3.setInviteUserId(appUser1.getId()); |
| | | } |
| | | } |
| | | appUserService.updateById(appUser3); |
| | | // 同时删除这条数据 |
| | | appUserService.deleteById(appUser2.getId()); |
| | | |
| | | //生成token |
| | | String token = JwtTokenUtil.generateToken(appUser3.getPhone()); |
| | | System.err.println("token1111--->" + token); |
| | | //存入缓存中 |
| | | addTokenToRedis(token, appUser3.getId()); |
| | | return ResultUtil.success(token); |
| | | }else if (appUser3!=null && StringUtils.hasLength(appUser3.getAppleId())){ |
| | | }else if (appUser3!=null && StringUtils.hasLength(appUser2.getAppleId())){ |
| | | if (appUser3.getCode().equals(invitationCode)){ |
| | | return ResultUtil.error("不能绑定自己",""); |
| | | } |
| | | // 苹果绑定手机号 |
| | | appUser3.setAppleId(appUser2.getAppleId()); |
| | | if (!StringUtils.hasLength(appUser3.getName())){ |
| | | appUser3.setName(phone); |
| | | if (StringUtils.hasLength(appUser3.getName())){ |
| | | // 如果已经有name了不更新 |
| | | }else{ |
| | | appUser3.setName("用户-"+appUser3.getCode()); |
| | | appUser3.setAccount(phone); |
| | | } |
| | | appUserService.updateById(appUser3); |
| | | // 同时删除这条数据 |
| | | appUserService.deleteById(appUser2.getId()); |
| | | if (StringUtils.hasLength(invitationCode)){ |
| | | if (appUser3.getInviteUserId()!=null){ |
| | | return ResultUtil.errorLogin("登录失败,已绑定其他用户",null); |
| | | return ResultUtil.error("该手机号已绑定其他邀请码",null); |
| | | } |
| | | // 根据邀请码查询用户id |
| | | AppUser appUser1 = appUserService.selectOne(new EntityWrapper<AppUser>() |
| | | .eq("code", invitationCode) |
| | | .ne("state", 3)); |
| | | if (appUser1==null){ |
| | | return ResultUtil.errorInvite("邀请码无效",null); |
| | | return ResultUtil.errorInvite("邀请码无效",""); |
| | | }else{ |
| | | if (appUser1.getInviteUserId().equals(appUser2.getId())){ |
| | | return ResultUtil.error("邀请失败,当前邀请用户为您的邀请人", null); |
| | | } |
| | | appUser3.setInviteUserId(appUser1.getId()); |
| | | } |
| | | } |
| | | appUserService.updateById(appUser3); |
| | | // 同时删除这条数据 |
| | | appUserService.deleteById(appUser2.getId()); |
| | | |
| | | //生成token |
| | | String token = JwtTokenUtil.generateToken(appUser3.getPhone()); |
| | | System.err.println("token1111--->" + token); |
| | | //存入缓存中 |
| | | addTokenToRedis(token, appUser3.getId()); |
| | | return ResultUtil.success(token); |
| | | // 绑定的手机号没有注册过 |
| | | } |
| | | appUser2.setPhone(phone); |
| | | appUser2.setAccount(phone); |
| | | if (appUser2.getCode()!=null){ |
| | | appUser2.setName("用户-"+appUser2.getCode()); |
| | | } |
| | | if (StringUtils.hasLength(invitationCode)){ |
| | | if (appUser2.getCode().equals(invitationCode)){ |
| | | return ResultUtil.error("不能绑定自己",""); |
| | | } |
| | | if (appUser2.getInviteUserId()!=null){ |
| | | return ResultUtil.errorLogin("登录失败,已绑定其他用户",null); |
| | | return ResultUtil.errorLogin("该手机号已绑定其他邀请码",null); |
| | | } |
| | | // 根据邀请码查询用户id |
| | | AppUser appUser1 = appUserService.selectOne(new EntityWrapper<AppUser>() |
| | | .eq("code", invitationCode) |
| | | .ne("state", 3)); |
| | | if (appUser1==null){ |
| | | return ResultUtil.errorInvite("邀请码无效",null); |
| | | return ResultUtil.errorInvite("邀请码无效",""); |
| | | }else{ |
| | | appUser2.setInviteUserId(appUser1.getId()); |
| | | } |
| | |
| | | addTokenToRedis(token, appUser2.getId()); |
| | | return ResultUtil.success(token); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/appUser/loginPassword") |
| | | @ApiOperation(value = "账号密码登录", tags = {"APP-登录注册"}) |
| | |
| | | // 判断当前手机号 登陆了哪些设备 |
| | | List<DeviceLogin> deviceLogins = deviceLoginService.selectList(queryWrapper); |
| | | List<String> collect = deviceLogins.stream().map(DeviceLogin::getDevice).collect(Collectors.toList()); |
| | | if (collect.size()>=5 &&!collect.contains(code2)){ |
| | | // 是一个新的设备登录 返回登陆失败的提示 |
| | | return ResultUtil.errorDevice("登录失败,同一账号一年内最多登录五部手机",null); |
| | | } |
| | | // if (collect.size()>=5 &&!collect.contains(code2)){ |
| | | // // 是一个新的设备登录 返回登陆失败的提示 |
| | | // return ResultUtil.errorDevice("登录失败,同一账号一年内最多登录五部手机",null); |
| | | // } |
| | | DeviceLogin deviceLogin1 = deviceLoginService.selectOne(new EntityWrapper<DeviceLogin>() |
| | | .eq("device", code2) |
| | | .eq("userId", tAppUser.getId())); |
| | |
| | | // 首次登录注册 |
| | | AppUser appUser1 = new AppUser(); |
| | | appUser1.setAppleId(appleId); |
| | | appUser1.setName(name); |
| | | appUser1.setAccount(name); |
| | | |
| | | appUser1.setAccount("用户"+UUIDUtil.getNumberRandom(5)); |
| | | appUser1.setPassword(MD5Util.encrypt("111111")); |
| | | appUser1.setState(1); |
| | | // 根据当前月份 填入星座名称 |
| | |
| | | appUser1.setHeadImg("https://jkjianshen.obs.cn-north-4.myhuaweicloud.com/admin/8d9bb8b7fb9a4786a50b88863c7706ab.png"); |
| | | appUser1.setConstellation(zodiacSign); |
| | | appUser1.setCode(UUIDUtil.getRandomCode(6).toUpperCase()); |
| | | appUser1.setName("用户-"+appUser1.getCode()); |
| | | appUser1.setHeight(155); |
| | | appUser1.setWeight(130D); |
| | | appUser1.setWaistline(100); |
| | | appUser1.setGender(1); |
| | | // 获取当前时间 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | // 将当前时间向前推30年 |
| | | calendar.add(Calendar.YEAR, -30); |
| | | Date date30YearsAgo = calendar.getTime(); |
| | | appUser1.setBirthday(date30YearsAgo); |
| | | // 根据邀请码 查询到用户 |
| | | if (StringUtils.hasLength(code2)){ |
| | | AppUser code3 = appUserService.selectOne(new EntityWrapper<AppUser>() |
| | | .eq("code", code2)); |
| | | if (code==null){ |
| | | if (code3==null){ |
| | | return ResultUtil.errorInvite("邀请码无效",null); |
| | | } |
| | | appUser1.setInviteUserId(code3.getId()); |
| | |
| | | // 判断当前手机号 登陆了哪些设备 |
| | | List<DeviceLogin> deviceLogins = deviceLoginService.selectList(queryWrapper); |
| | | List<String> collect = deviceLogins.stream().map(DeviceLogin::getDevice).collect(Collectors.toList()); |
| | | if (collect.size()>=5 &&!collect.contains(code)){ |
| | | // 是一个新的设备登录 返回登陆失败的提示 |
| | | return ResultUtil.errorDevice("登录失败,同一账号一年内最多登录五部手机",null); |
| | | } |
| | | // if (collect.size()>=5 &&!collect.contains(code)){ |
| | | // // 是一个新的设备登录 返回登陆失败的提示 |
| | | // return ResultUtil.errorDevice("登录失败,同一账号一年内最多登录五部手机",null); |
| | | // } |
| | | DeviceLogin deviceLogin1 = deviceLoginService.selectOne(new EntityWrapper<DeviceLogin>() |
| | | .eq("device", code) |
| | | .eq("userId", appUser1.getId())); |