禁止他人登录

pull/1/head
huan.xu 5 years ago
parent 0a84e930b2
commit dd64ea523f
  1. 2
      blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/common/enums/UserEnums.java
  2. 14
      blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/controller/LoginController.java
  3. 6
      blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/entity/YyyfUser.java
  4. 6
      blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/YyyfUserService.java
  5. 6
      blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/service/impl/YyyfUserServiceImpl.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", "用戶名密碼錯誤"),

@ -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();
}
}

@ -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;
}

@ -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);
}

@ -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);
}

Loading…
Cancel
Save