Commit 66bd31121db8cf072925f38834ac9f99b06ce1c6

Authored by weiliwhereareyou@163.com
1 parent 7cd7c324

卖家登录功能开发

mobsite-getway-domain/src/main/java/com/diligrp/mobsite/getway/domain/common/Constant.java
... ... @@ -121,6 +121,8 @@ public class Constant {
121 121 /**
122 122 * 用户
123 123 */
  124 + public static final long USER_ROLE_BUYER = 10L;//买家
  125 + public static final long USER_ROLE_SELLER = 20L;//卖家
124 126 public static final int USER_TYPE_PERSONAL = 1;
125 127 public static final int USER_TYPE_COMPANY = 2;
126 128 public static final int USER_AUTH_RESULT_NOTAUTH = 100;//未认证
... ...
mobsite-getway-domain/src/main/java/com/diligrp/mobsite/getway/domain/common/RedisKey.java
... ... @@ -15,20 +15,20 @@ public final class RedisKey {
15 15  
16 16 public static final int USER_SEND_VERICODE_EXPIRE_TIME = 10*60;//发送验证码失效时间,10分钟
17 17  
18   - public static final String PNR_GETWAY = "PNR_GETWAY";
  18 + public static final String ZDAPP_GETWAY = "ZDAPP_GETWAY";
19 19  
20 20 //登录信息
21   - public static final String USER_LOGININFO = PNR_GETWAY+":USER:LOGININFO";
22   - public static final String USER_DEVICEID = PNR_GETWAY+":USER:DEVICEID";
23   - public static final String USER_REGISTERNO = PNR_GETWAY+":USER:REGISTERNO";
  21 + public static final String USER_LOGININFO = ZDAPP_GETWAY+":USER:LOGININFO";
  22 + public static final String USER_DEVICEID = ZDAPP_GETWAY+":USER:DEVICEID";
  23 + public static final String USER_REGISTERNO = ZDAPP_GETWAY+":USER:REGISTERNO";
24 24  
25 25 //门卫登录信息
26   - public static final String GUARD_LOGININFO = PNR_GETWAY+":GUARD:LOGININFO";
  26 + public static final String GUARD_LOGININFO = ZDAPP_GETWAY+":GUARD:LOGININFO";
27 27  
28 28 //门卫登录session
29   - public static final String GUARD_SESSSION = PNR_GETWAY+":GUARD:SESSSION";
  29 + public static final String GUARD_SESSSION = ZDAPP_GETWAY+":GUARD:SESSSION";
30 30  
31   - public static final String USER = PNR_GETWAY+":USER";
  31 + public static final String USER = ZDAPP_GETWAY+":USER";
32 32 public static final String USER_AUTH_CODE_REGISTER = USER+":AUTH_CODE_REGISTER";//注册验证码
33 33 public static final String USER_AUTH_CODE_MODIFY_PWD_AND_PHONE = USER+":USER_AUTH_CODE_MODIFY_PWD_AND_PHONE";//修改密码
34 34  
... ... @@ -39,21 +39,21 @@ public final class RedisKey {
39 39 public static final String USER_AUTH_CODE = USER+":AUTH_CODE";
40 40  
41 41 //延迟退出 暂时未调用
42   - public static final String LOGOUT = PNR_GETWAY+":LOGOUT";
  42 + public static final String LOGOUT = ZDAPP_GETWAY+":LOGOUT";
43 43 //订单cookieValue
44   - public static final String COOKIE_VALUE = PNR_GETWAY+":COOKIE_VALUE";
  44 + public static final String COOKIE_VALUE = ZDAPP_GETWAY+":COOKIE_VALUE";
45 45  
46 46 //根据城市ID获取提货点
47 47 public static final int GETPICKUPLISTBYCITYID_TIME = 10*60;
48 48  
49 49 //专题标题
50 50 public static final int TOPIC_EXPIRE_TIME = 10;
51   - public static final String TOPIC_BAR = PNR_GETWAY+":TOPIC:BAR";
52   - public static final String TOPIC_CATEGORY = PNR_GETWAY+":TOPIC:CATEGORY";//专题标题
  51 + public static final String TOPIC_BAR = ZDAPP_GETWAY+":TOPIC:BAR";
  52 + public static final String TOPIC_CATEGORY = ZDAPP_GETWAY+":TOPIC:CATEGORY";//专题标题
53 53  
54 54 //商品缓存
55 55 public static final int PRODUCT_EXPIRE_TIME = 3*60;
56   - public static final String PRODUCT = PNR_GETWAY+":PRODUCT";
  56 + public static final String PRODUCT = ZDAPP_GETWAY+":PRODUCT";
57 57 public static final String PRODUCT_PRODUCTDETAIL = PRODUCT+":PRODUCT_DETAIL";
58 58 public static final String PRODUCT_CATEGORY = PRODUCT+":PRODUCT_CATEGORY";
59 59  
... ... @@ -61,7 +61,7 @@ public final class RedisKey {
61 61 * 订单缓存
62 62 */
63 63 public static final int ORDER_EXPIRE_TIME = 10;
64   - public static final String ORDER = PNR_GETWAY + ":ORDER";
  64 + public static final String ORDER = ZDAPP_GETWAY + ":ORDER";
65 65 public static final String ORDER_SUM_INFO = ORDER + ":SUM_INFO";
66 66 public static final String ORDER_AGREEMENT = ORDER + ":AGREEMENT";
67 67  
... ... @@ -69,7 +69,7 @@ public final class RedisKey {
69 69 * 配置缓存,config
70 70 */
71 71 public static final int CONFIG_EXPIRE_TIME = 3*60*60;
72   - public static final String CONFIG = PNR_GETWAY+":CONFIG";
  72 + public static final String CONFIG = ZDAPP_GETWAY+":CONFIG";
73 73 public static final String CONFIG_PROVINCE_CITY_ADDRESS = CONFIG+":PROVINCE_CITY_ADDRESS";
74 74 public static final String CONFIG_SYSTEM_CONFIG = CONFIG + ":SYSTEM_CONFIG";
75 75 public static final String CONFIG_SMS_CONTENT = CONFIG + ":SMS_CONTENT";
... ... @@ -94,7 +94,7 @@ public final class RedisKey {
94 94 * 店铺信息
95 95 */
96 96 public static final int SHOP_EXPIRE_TIME = 3*60;
97   - public static final String SHOP = PNR_GETWAY+":SHOP";
  97 + public static final String SHOP = ZDAPP_GETWAY+":SHOP";
98 98 public static final String SHOP_INFO = SHOP+"INFO";
99 99 public static final String SHOP_SEND_ADDRESS = SHOP+"SEND_ADDRESS";
100 100  
... ...
mobsite-getway-domain/src/main/java/com/diligrp/mobsite/getway/domain/protocol/Token.java
1 1 package com.diligrp.mobsite.getway.domain.protocol;
2 2  
3 3 import com.diligrp.mobsite.getway.domain.common.enums.DeviceTypeEnum;
  4 +import io.swagger.annotations.ApiModelProperty;
4 5  
5 6  
6 7 /**
... ... @@ -17,6 +18,7 @@ public class Token {
17 18 /**
18 19 * 用户ID
19 20 */
  21 + @ApiModelProperty("用户ID")
20 22 private Long userId;
21 23 /**
22 24 * 当前终端所在市场ID
... ... @@ -25,18 +27,22 @@ public class Token {
25 27 /**
26 28 * 终端与服务端协定的密文
27 29 */
  30 + @ApiModelProperty("终端与服务端协定的密文")
28 31 private String secretkey;
29 32 /**
30 33 * 设备ID
31 34 */
  35 + @ApiModelProperty("设备ID")
32 36 private String deviceId;
33 37 /**
34 38 * app版本编号
35 39 */
  40 +
36 41 private String version;
37 42 /**
38 43 * 设备类型
39 44 */
  45 + @ApiModelProperty("设备ID:1-安卓,2-ios")
40 46 private Integer deviceType = DeviceTypeEnum.ANDROID_MOBILE.getType();
41 47 /**
42 48 * 手机系统版本
... ... @@ -46,12 +52,28 @@ public class Token {
46 52 /**
47 53 * 经度
48 54 */
  55 + @ApiModelProperty("经度")
49 56 private Double longitude;
50 57 /**
51 58 * 纬度
52 59 */
  60 + @ApiModelProperty("纬度")
53 61 private Double latitude;
54 62  
  63 + /**
  64 + * 用户角色
  65 + */
  66 + @ApiModelProperty("用户角色:10-买家,20-卖家")
  67 + private Integer userRole;
  68 +
  69 +
  70 + public Integer getUserRole() {
  71 + return userRole;
  72 + }
  73 +
  74 + public void setUserRole(Integer userRole) {
  75 + this.userRole = userRole;
  76 + }
55 77  
56 78 public Long getUserId() {
57 79 return userId;
... ...
mobsite-getway-domain/src/main/java/com/diligrp/mobsite/getway/domain/protocol/login/LoginResp.java
... ... @@ -69,42 +69,27 @@ public class LoginResp extends BaseResp {
69 69 */
70 70 @ApiModelProperty(value = "手机号码")
71 71 private String mobile;
72   - ///**
73   - // * 邮箱地址
74   - // */
75   - //@ApiModelProperty(value = "邮箱")
76   - //private String email;
77   - ///**
78   - // * 1:个人用户, 2:企业用户
79   - // */
80   - //@ApiModelProperty(value = "用户类型:个人用户,2:企业用户")
81   - //private Integer userType;
82   - ///**
83   - // * 1 登入 -1 登出 (出场验货专用)
84   - // */
85   - //private Integer accountState;
86   - ///**
87   - // * 真实姓名
88   - // */
89   - //@ApiModelProperty(value = "真实姓名")
90   - //private String realName;
91   - /**
92   - * 登录之后,passport返回
93   - * 用于支付鉴权
94   - */
95   - @ApiModelProperty(value = "token")
96   - private String token;
  72 +
  73 +
97 74 /**
98 75 * 头像图片
99 76 */
100 77 @ApiModelProperty(value = "头像")
101 78 private String headImg;
102 79  
103   - /**
104   - * 用户信息是否完善:1-完善 0-不完善
105   - */
106   - @ApiModelProperty(value = "用户信息是否完善:1-完善 0-不完善")
107   - private Integer infoCompleteFlag;
  80 +
  81 + ///**
  82 + // * 登录之后,passport返回
  83 + // * 用于支付鉴权
  84 + // */
  85 + //@ApiModelProperty(value = "token")
  86 + //private String token;
  87 +
  88 + ///**
  89 + // * 用户信息是否完善:1-完善 0-不完善
  90 + // */
  91 + //@ApiModelProperty(value = "用户信息是否完善:1-完善 0-不完善")
  92 + //private Integer infoCompleteFlag;
108 93 /**
109 94 * get value of LoginResp.accountId
110 95 * @return the accountId
... ... @@ -167,30 +152,15 @@ public class LoginResp extends BaseResp {
167 152  
168 153  
169 154  
170   - public String getToken() {
171   - return token;
172   - }
173   -
174   -
175   - public void setToken(String token) {
176   - this.token = token;
177   - }
178   -
179   -
180 155 public String getHeadImg() {
181 156 return headImg;
182 157 }
183 158  
184   -
  159 +
185 160 public void setHeadImg(String headImg) {
186 161 this.headImg = headImg;
187 162 }
188 163  
189   - public Integer getInfoCompleteFlag() {
190   - return infoCompleteFlag;
191   - }
192 164  
193   - public void setInfoCompleteFlag(Integer infoCompleteFlag) {
194   - this.infoCompleteFlag = infoCompleteFlag;
195   - }
196   -}
  165 +
  166 + }
... ...
mobsite-getway-domain/src/main/java/com/diligrp/mobsite/getway/domain/protocol/register/SellerRegisterReq.java
... ... @@ -15,13 +15,7 @@ import io.swagger.annotations.ApiModelProperty;
15 15 @ApiModel(value = "请求参数")
16 16 public class SellerRegisterReq extends BaseReq {
17 17  
18   - public static final int USER_TYPE_BUSINESS = 1;//市场商户,企业单位,个体经营,个人
19   -
20   - public static final int USER_TYPE_COMPANY = 2;
21 18  
22   - public static final int USER_TYPE_PERSONMANAGE = 3;
23   -
24   - public static final int USER_TYPE_PERSON = 4;
25 19  
26 20 public static final int APPTYPE_SHEQU = 1;
27 21  
... ... @@ -48,7 +42,7 @@ public class SellerRegisterReq extends BaseReq {
48 42 /**
49 43 * 手机验证码
50 44 */
51   - @ApiModelProperty(value = "app类型(1:社区店版,2:连锁店 ,默认1)")
  45 + @ApiModelProperty(value = "app类型(1:社区店版,2:连锁店 ,默认1)")
52 46 private Integer appType = APPTYPE_SHEQU;
53 47  
54 48  
... ...
mobsite-getway-domain/src/main/java/com/diligrp/mobsite/getway/domain/protocol/shop/GetShopInfoResp.java
... ... @@ -10,6 +10,8 @@ import java.util.List;
10 10 * Created by xxxzzz on 2016/12/27.
11 11 */
12 12 public class GetShopInfoResp extends BaseResp {
  13 + @ApiModelProperty(value = "店铺id")
  14 + private Long shopId;
13 15  
14 16 @ApiModelProperty(value = "城市code")
15 17 private Long cityCode;
... ... @@ -51,6 +53,13 @@ public class GetShopInfoResp extends BaseResp {
51 53 private List<String> deliveryTime;
52 54  
53 55  
  56 + public Long getShopId() {
  57 + return shopId;
  58 + }
  59 +
  60 + public void setShopId(Long shopId) {
  61 + this.shopId = shopId;
  62 + }
54 63  
55 64 public Long getCityCode() {
56 65 return cityCode;
... ...
mobsite-getway-rpc/src/main/java/com/diligrp/mobsite/getway/rpc/PassportRPC.java
1 1 package com.diligrp.mobsite.getway.rpc;
2 2  
3 3 import com.diligrp.mobsite.getway.domain.protocol.login.LoginReq;
  4 +import com.diligrp.mobsite.getway.domain.protocol.register.SellerRegisterReq;
  5 +import com.diligrp.mobsite.getway.domain.protocol.register.SellerRegisterResp;
4 6 import com.diligrp.mobsite.getway.domain.protocol.register.UserRegisterReq;
5 7 import com.diligrp.mobsite.getway.domain.protocol.register.UserRegisterResp;
6 8 import com.diligrp.mobsite.getway.domain.protocol.saler.user.SellerLoginResp;
... ... @@ -24,5 +26,6 @@ public interface PassportRPC extends BaseService {
24 26 UserRegisterResp register(UserRegisterReq req);
25 27  
26 28 String modifyPwd(Map<String, String> params);
27   -
  29 +
  30 + SellerRegisterResp sellerRegister(SellerRegisterReq req);
28 31 }
... ...
mobsite-getway-rpc/src/main/java/com/diligrp/mobsite/getway/rpc/impl/PassportRPCImpl.java
1 1 package com.diligrp.mobsite.getway.rpc.impl;
2 2  
3 3 import com.alibaba.fastjson.JSONObject;
  4 +import com.diligrp.mobsite.getway.domain.common.Constant;
4 5 import com.diligrp.mobsite.getway.domain.common.RedisKey;
5 6 import com.diligrp.mobsite.getway.domain.common.ResultCode;
6 7 import com.diligrp.mobsite.getway.domain.except.ServiceException;
7 8 import com.diligrp.mobsite.getway.domain.protocol.login.LoginReq;
8   -import com.diligrp.mobsite.getway.domain.protocol.login.LoginResp;
  9 +import com.diligrp.mobsite.getway.domain.protocol.register.SellerRegisterReq;
  10 +import com.diligrp.mobsite.getway.domain.protocol.register.SellerRegisterResp;
9 11 import com.diligrp.mobsite.getway.domain.protocol.register.UserRegisterReq;
10 12 import com.diligrp.mobsite.getway.domain.protocol.register.UserRegisterResp;
11 13 import com.diligrp.mobsite.getway.domain.protocol.saler.user.SellerLoginResp;
... ... @@ -60,7 +62,7 @@ public class PassportRPCImpl extends BaseServiceImpl implements PassportRPC {
60 62 Map<String,String> params = new HashMap<String, String>();
61 63 params.put("userName", req.getAccountName());
62 64 params.put("password", req.getPassword());
63   - params.put("src", "1n4j");
  65 + params.put("src", "zadeapp");
64 66 BaseOutput<String> output = null;
65 67 try {
66 68 output = super.httpPost("/api/login/login.html", params, null,passportSign);
... ... @@ -88,40 +90,25 @@ public class PassportRPCImpl extends BaseServiceImpl implements PassportRPC {
88 90 throw new ServiceException(ResultCode.BUSINESS_FAILED,msg);
89 91 }
90 92  
91   - resp.setToken(jsonBody.getString("token"));
  93 + //resp.setToken(jsonBody.getString("token"));
92 94 JSONObject jsonUser = jsonBody.getJSONObject("accountInfo");
93 95 resp.setAccountId(jsonUser.getLong("accountId"));
94 96 resp.setMobile(jsonUser.getString("mobile"));
95 97 resp.setAccountName(jsonUser.getString("accountName"));
96 98 resp.setMsg(msg);
97 99 resp.setHeadImg(jsonUser.getString("face"));
98   - if (Validator.isNull(jsonUser.getString("city"))){
99   - resp.setInfoCompleteFlag(LoginResp.USER_INFOCOMPLETEFLAG_NO);
100   - }else {
101   - resp.setInfoCompleteFlag(LoginResp.USER_INFOCOMPLETEFLAG_YES);
102   - }
  100 + resp.setShopId(jsonUser.getLong("shopId"));
103 101  
104   - //if (Constant.USER_STATE_LOCKED == jsonUser.getInteger("accountState")) {
105   - //resp.setMsg(ErrorMessage.USER_STATE_LOCKED);
106   - //resp.setCode(PASSPORT_LOGIN_CODE_LOCKED);
107   - //}
108   -
109   - //if (Validator.isNull(resp.getAccountState())
110   - // || resp.getAccountState()!= LoginResp.ACCOUNT_STATE_NORMAL) {
111   - // throw new ServiceException(ResultCode.BUSINESS_FAILED,resp.getMsg());
112   - //}
113   -
114   - //登录redisKey=userId-deviceId
115 102  
116   - //String cookieRedisKey = redisUtil.makeKey(RedisKey.USER_LOGININFO, resp.getAccountId()+Constant.COMMON_DASH+req.getDeviceId());
117   - String cookieRedisKey = redisUtil.makeKey(RedisKey.USER_LOGININFO, String.valueOf(resp.getAccountId()));
  103 + //缓存userId
  104 + String cookieRedisKey = redisUtil.makeKey(RedisKey.USER_LOGININFO, Constant.USER_ROLE_SELLER+String.valueOf(resp.getAccountId()));
118 105 redisUtil.setStringByExpire(cookieRedisKey, String.valueOf(resp.getAccountId()), loginExpireTime);
119 106  
120   - // 去掉登录设备排斥验证
121   - //if (!Validator.isNull(req.getDeviceId())) {
122   - // String onlyOneLoginRedisKey = redisUtil.makeKey(RedisKey.USER_DEVICEID, String.valueOf(resp.getAccountId()));
123   - // redisUtil.setStringByExpire(onlyOneLoginRedisKey, req.getDeviceId(), loginExpireTime);
124   - //}
  107 + //缓存设备id,userId作为key
  108 + if (!Validator.isNull(req.getDeviceId())) {
  109 + String onlyOneLoginRedisKey = redisUtil.makeKey(RedisKey.USER_DEVICEID, Constant.USER_ROLE_SELLER+String.valueOf(resp.getAccountId()));
  110 + redisUtil.setStringByExpire(onlyOneLoginRedisKey, req.getDeviceId(), loginExpireTime);
  111 + }
125 112 return resp;
126 113 }
127 114  
... ... @@ -175,4 +162,34 @@ public class PassportRPCImpl extends BaseServiceImpl implements PassportRPC {
175 162 return output.getData();
176 163 }
177 164  
  165 + @Override
  166 + public SellerRegisterResp sellerRegister(SellerRegisterReq req) {
  167 + Map<String,String> params = new HashMap<String, String>();
  168 + params.put("mobile", req.getMobile());
  169 + params.put("password", req.getPassword());
  170 + //BaseOutput<String> output = null;
  171 + //try {
  172 + // output = super.httpPost("/api/register/buyerRegister.html", params,null, passportSign);
  173 + //
  174 + //} catch (Exception e) {
  175 + // log.error("调用passport注册接口失败",e);
  176 + // throw new ServiceException();
  177 + //}
  178 + //
  179 + SellerRegisterResp resp = new SellerRegisterResp();
  180 + //JSONObject jsonBody = JSONObject.parseObject(output.getData());
  181 + //int code = jsonBody.getIntValue("code");
  182 + ////成功
  183 + //if(code == ResultCode.SUCCESS){
  184 + // resp.setResultFlag(UserRegisterResp.RESULT_FLAG_SUCCESS);
  185 + //}else{
  186 + // resp.setResultFlag(UserRegisterResp.RESULT_FLAG_FAILED);
  187 + //}
  188 + //resp.setMsg(jsonBody.getString("msg"));
  189 + //
  190 + //log.info("注册用户信息:msg={}"+jsonBody.getString("msg"));
  191 +
  192 + return resp;
  193 + }
  194 +
178 195 }
... ...
mobsite-getway-service/src/main/java/com/diligrp/mobsite/getway/service/seller/impl/SellerUserServiceImpl.java
... ... @@ -67,7 +67,11 @@ public class SellerUserServiceImpl implements SellerUserService {
67 67  
68 68 @Override
69 69 public SellerLoginResp login(SellerLoginReq req) throws RuntimeException {
70   - return null;
  70 + SellerLoginResp resp = passportRPC.login(req);
  71 +
  72 + //判断卖家是否创建店铺
  73 +
  74 + return resp;
71 75 }
72 76  
73 77 @Override
... ... @@ -188,9 +192,73 @@ public class SellerUserServiceImpl implements SellerUserService {
188 192  
189 193 @Override
190 194 public SellerRegisterResp sellerRegister(SellerRegisterReq req) {
191   - return null;
  195 + SellerRegisterResp resp = new SellerRegisterResp();
  196 +
  197 + //手机号码和账号验证、验证码
  198 + if (!checkRegisterInfo( req)) {
  199 + return resp;
  200 + }
  201 +
  202 + resp = passportRPC.sellerRegister(req);
  203 +
  204 + return resp;
192 205 }
193 206  
  207 + /**
  208 + * 检测注册信息是否正确
  209 + * 1.电话号码
  210 + * 2.账号,会员名
  211 + * 3.验证码
  212 + * @createTime 2014年10月31日 下午2:37:16
  213 + * @author weili
  214 + */
  215 + private boolean checkRegisterInfo( SellerRegisterReq req){
  216 + if(!sellerRPC.checkMobile(req.getMobile())){
  217 + throw new ServiceException(ResultCode.BUSINESS_FAILED,ErrorMessage.USER_MOBILE_EXIST);
  218 + }
  219 + //验证万能验证码
  220 + String passkey = configRPC.getSystemConfig(Constant.USER_REGISTER_PASS_KEY);
  221 + if (req.getVeriCode().equals(passkey)) {
  222 + return true;
  223 + }
  224 +
  225 + checkVeriCode(req.getVeriCode(), req.getMobile(),SendVeriCodeReq.MSG_TYPE_REGISTER);
  226 +
  227 + return true;
  228 + }
  229 +
  230 + /**
  231 + * 根据验证码和电话号码,验证收到的验证码
  232 + *
  233 + * @param code
  234 + * @param mobile
  235 + * @return
  236 + * @createTime 2014年8月28日 下午5:44:48
  237 + * @author weili
  238 + */
  239 + private void checkVeriCode(String code, String mobile,Integer msgType) {
  240 +
  241 + String redisKey = redisUtil.makeKey(RedisKey.USER_AUTH_CODE + String.valueOf(msgType), mobile);
  242 +
  243 + String redisCode = redisUtil.getString(redisKey);
  244 +
  245 + if(Validator.isEmpty(code)){
  246 + throw new ServiceException(ResultCode.BUSINESS_FAILED,ErrorMessage.USER_AUTH_CODE_EMPTY);
  247 + }
  248 +
  249 + //验证码为空
  250 + if (Validator.isEmpty(redisCode)) {
  251 + throw new ServiceException(ResultCode.BUSINESS_FAILED,ErrorMessage.USER_AUTH_CODE_OVERTIME);
  252 + }
  253 +
  254 + //验证码不为空,并且和redis中的验证码相同
  255 + if (!code.equals(redisCode)) {
  256 + throw new ServiceException(ResultCode.BUSINESS_FAILED,ErrorMessage.USER_AUTH_CODE_WRONG);
  257 + }
  258 +
  259 + }
  260 +
  261 +
194 262 @Override
195 263 public LogoutResp logout(LogoutReq req) {
196 264 return null;
... ...
mobsite-getway-web/src/main/java/com/diligrp/mobsite/getway/web/filter/LoginTimeoutInterceptor.java
... ... @@ -85,28 +85,28 @@ public class LoginTimeoutInterceptor extends HandlerInterceptorAdapter {
85 85  
86 86 //登录redisKey=userId-deviceId
87 87 // String loginKey = redisUtil.makeKey(RedisKey.USER_LOGININFO, userId + Constant.COMMON_DASH + baseReq.getDeviceId());
88   -
89   - String loginKey = redisUtil.makeKey(RedisKey.USER_LOGININFO, String.valueOf(userId));
  88 + //登录排斥验证
  89 + String loginKey = redisUtil.makeKey(RedisKey.USER_LOGININFO, token.getUserRole()+String.valueOf(userId));
90 90 String loginValue = redisUtil.getString(loginKey);
91   - //String loginDevicedKey = redisUtil.makeKey(RedisKey.USER_DEVICEID, String.valueOf(userId));
92   - //String loginDevicedValue = redisUtil.getString(loginDevicedKey);
93   -
94 91 if(Validator.isEmpty(loginValue) || !loginValue.equals(String.valueOf(userId))) {
95 92 log.error("用户没有登录请重新登录[userId={}]",userId);
96 93 WebContent.sendErrorInfo(ResultCode.LOGIN_FAILED, ErrorMessage.USER_NOT_LOGIN);
97 94 return false;
98 95 }
99   - //TODO 去掉了登录排斥验证
100   - //if (!Validator.isNull(baseReq.getDeviceId())) {
101   - // if(Validator.isEmpty(loginDevicedValue) || !loginDevicedValue.equals(baseReq.getDeviceId())) {
102   - // log.error("用户使用其他设备重新登录[userId={}]",userId);
103   - // WebContent.sendErrorInfo(ResultCode.LOGIN_MULTI, ErrorMessage.USER_LOGIN_MULTI);
104   - // return false;
105   - // }
106   - //}
  96 +
  97 + //登录设备排斥验证
  98 + String loginDevicedKey = redisUtil.makeKey(RedisKey.USER_DEVICEID, token.getUserRole()+String.valueOf(userId));
  99 + String loginDevicedValue = redisUtil.getString(loginDevicedKey);
  100 + if (!Validator.isNull(baseReq.getDeviceId())) {
  101 + if(Validator.isEmpty(loginDevicedValue) || !loginDevicedValue.equals(baseReq.getDeviceId())) {
  102 + log.error("用户使用其他设备重新登录[userId={}]",userId);
  103 + WebContent.sendErrorInfo(ResultCode.LOGIN_MULTI, ErrorMessage.USER_LOGIN_MULTI);
  104 + return false;
  105 + }
  106 + }
107 107  
108 108 //登录延时
109   - logoutDelay(userId,baseReq.getDeviceId());
  109 + logoutDelay(userId,baseReq.getDeviceId(),token.getUserRole());
110 110  
111 111 return true;
112 112 }
... ... @@ -115,12 +115,10 @@ public class LoginTimeoutInterceptor extends HandlerInterceptorAdapter {
115 115 * 延迟登录超时时间
116 116 * @param userId 用户ID
117 117 */
118   - private void logoutDelay(long userId,String deviceId) {
  118 + private void logoutDelay(long userId,String deviceId,Integer userRole) {
119 119 try {
120 120 //cookievalue的rediskey
121   -// String loginKey = redisUtil.makeKey(RedisKey.USER_LOGININFO, userId + Constant.COMMON_DASH + deviceId);
122   - //TODO 2.5之后版本需要加上
123   - String loginKey = redisUtil.makeKey(RedisKey.USER_LOGININFO, String.valueOf(userId));
  121 + String loginKey = redisUtil.makeKey(RedisKey.USER_LOGININFO, userRole+String.valueOf(userId));
124 122 //缓存cookievalue
125 123 redisUtil.setStringByExpire(loginKey, String.valueOf(userId), loginExpireTime);
126 124  
... ...