diff --git a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/common/enums/UserEnums.java b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/common/enums/UserEnums.java index 5c52234..fbd030f 100644 --- a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/common/enums/UserEnums.java +++ b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/common/enums/UserEnums.java @@ -5,6 +5,8 @@ package com.blockchain.server.user.common.enums; * @data 2019/2/21 20:53 */ public enum UserEnums { + USER_NOT_FORBID_OTHER_USER(1098, "禁止登录他人账号", "The user does not allow login other user's accout", "禁止登錄他人賬號"), + USER_NOT_BIND_YYYF(1099, "该用户未绑定以渔有方或者以渔有方登录已失效", "The user does not bind yyyf", "該用戶未綁定以漁有方或者以漁有方登錄已失效"), USER_EXISTS(1100, "该用户已存在", "The user already exists", "該用戶已存在"), USER_NOT_EXISTS(1101, "不存在该用户", "The user does not exist", "不存在該用戶"), LOGIN_PASSWORD_ERROR(1102, "用户名密码错误", "Wrong username and password", "用戶名密碼錯誤"), diff --git a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/controller/LoginController.java b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/controller/LoginController.java index c57e4d4..2539e2e 100644 --- a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/controller/LoginController.java +++ b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/controller/LoginController.java @@ -19,6 +19,7 @@ import com.blockchain.server.user.common.utils.SmsCodeUtils; import com.blockchain.server.user.controller.api.LoginApi; import com.blockchain.server.user.dto.UserBaseDTO; import com.blockchain.server.user.entity.UserMain; +import com.blockchain.server.user.entity.YyyfUser; import com.blockchain.server.user.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -197,6 +198,7 @@ public class LoginController { smsCodeUtils.validateVerifyCode(code, tel, SmsCountEnum.SMS_COUNT_REGISTER); UserMain userMain = userMainService.handleRegister(tel, invitationCode, internationalCode, password, nickName); smsCodeUtils.removeKey(tel, SmsCountEnum.SMS_COUNT_REGISTER); + return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue(), request); } @@ -280,12 +282,17 @@ public class LoginController { YyyfUserDto yyyfUserDto = (YyyfUserDto) redisTemplate.opsForValue().get(yyyfTtoken); yyyfUserId = yyyfUserDto.getId(); String userId =userMain.getId(); - int count = this.yyyfUserService.selectCountByYyyfUserIdAndUserId(yyyfUserId, userId); - if (count == 0) { + YyyfUser yyyfUser = this.yyyfUserService.selectByYyyfUserIdAndTel(yyyfUserId, userMain.getMobilePhone()); + if (yyyfUser == null) { this.yyyfUserService.saveUser(yyyfUserId, userId, yyyfUserDto.getName()); this.redisTemplate.delete(yyyfTtoken); + }else{ + if(!yyyfUser.getUserId().equals(userMain.getId())){ + throw new UserException(UserEnums.USER_NOT_FORBID_OTHER_USER); + } } - + }else{ + throw new UserException(UserEnums.USER_NOT_BIND_YYYF); } long timestamp = System.currentTimeMillis(); @@ -330,4 +337,5 @@ public class LoginController { // smsCountService.handleInsertSmsCode(tel, internationalCode, SmsCountEnum.SMS_COUNT_FORGET_PASSWORD); return ResultDTO.requstSuccess(); } + } diff --git a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/entity/YyyfUser.java b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/entity/YyyfUser.java index b0fb656..8170da3 100644 --- a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/entity/YyyfUser.java +++ b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/entity/YyyfUser.java @@ -40,5 +40,11 @@ public class YyyfUser extends BaseModel { @Column(name = "create_time") private java.util.Date createTime; + /** + * 手机号码 + */ + @Column(name = "mobile_phone") + private String mobilePhone; + } \ No newline at end of file diff --git a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/YyyfUserService.java b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/YyyfUserService.java index 202cbed..3243e58 100644 --- a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/YyyfUserService.java +++ b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/YyyfUserService.java @@ -1,5 +1,7 @@ package com.blockchain.server.user.service; +import com.blockchain.server.user.entity.YyyfUser; + /** * @author huangxl * @create 2019-02-23 18:21 @@ -18,9 +20,9 @@ public interface YyyfUserService { * @description * @author Mr.Xu * @date 2020/5/4 13:42 - * @param [yyyfUserId, userId] + * @param [yyyfUserId, tel] * @return com.blockchain.server.user.entity.YyyfUser **/ - int selectCountByYyyfUserIdAndUserId(Integer yyyfUserId,String userId); + YyyfUser selectByYyyfUserIdAndTel(Integer yyyfUserId, String tel); } diff --git a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/YyyfUserServiceImpl.java b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/YyyfUserServiceImpl.java index 9ef299b..479b7e2 100644 --- a/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/YyyfUserServiceImpl.java +++ b/blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/YyyfUserServiceImpl.java @@ -51,12 +51,12 @@ public class YyyfUserServiceImpl implements YyyfUserService { } @Override - public int selectCountByYyyfUserIdAndUserId(Integer yyyfUserId, String userId) { + public YyyfUser selectByYyyfUserIdAndTel(Integer yyyfUserId, String tel) { Example example=new Example(YyyfUser.class); Example.Criteria criteria=example.createCriteria(); criteria.andCondition("yyyf_user_id = " ,yyyfUserId) - .andCondition("user_id = ",userId); - return this.yyyfUserMapper.selectCountByExample(example); + .andCondition("mobile_phone = ",tel); + return this.yyyfUserMapper.selectOneByExample(example); }