diff --git a/auth/src/main/java/com/bonus/auth/controller/TokenController.java b/auth/src/main/java/com/bonus/auth/controller/TokenController.java index 689e65a..948a435 100644 --- a/auth/src/main/java/com/bonus/auth/controller/TokenController.java +++ b/auth/src/main/java/com/bonus/auth/controller/TokenController.java @@ -3,8 +3,10 @@ package com.bonus.auth.controller; import com.bonus.auth.form.LoginBody; import com.bonus.auth.form.RegisterBody; import com.bonus.auth.service.SysLoginService; +import com.bonus.common.core.constant.Constants; import com.bonus.common.core.constant.SecurityConstants; import com.bonus.common.core.domain.R; +import com.bonus.common.core.exception.CaptchaException; import com.bonus.common.core.utils.JwtUtils; import com.bonus.common.core.utils.StringUtils; import com.bonus.common.redis.service.RedisService; @@ -46,6 +48,22 @@ public class TokenController // 用户登录 LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword(), form.getType(),form.getJwtToken()); + if (StringUtils.isEmpty(form.getCode())) + { + throw new CaptchaException("验证码不能为空"); + } + if (StringUtils.isEmpty(form.getUuid())) + { + throw new CaptchaException("验证码已失效"); + } + String verifyKey = Constants.CAPTCHA_CODE_KEY + form.getUuid(); + String captcha = redisService.getCacheObject(verifyKey); + redisService.deleteObject(verifyKey); + + if (!form.getCode().equalsIgnoreCase(captcha)) + { + throw new CaptchaException("验证码错误"); + } // 获取登录token return R.ok(tokenService.createToken(userInfo)); } diff --git a/auth/src/main/java/com/bonus/auth/form/LoginBody.java b/auth/src/main/java/com/bonus/auth/form/LoginBody.java index e5d4086..8377ddf 100644 --- a/auth/src/main/java/com/bonus/auth/form/LoginBody.java +++ b/auth/src/main/java/com/bonus/auth/form/LoginBody.java @@ -2,7 +2,7 @@ package com.bonus.auth.form; /** * 用户登录对象 - * + * * @author zys */ public class LoginBody @@ -27,6 +27,13 @@ public class LoginBody */ private String jwtToken; + private String code; + + /** + * 类型 有值为app登录,无需密码 + */ + private String uuid; + public String getType() { return type; } @@ -65,4 +72,19 @@ public class LoginBody this.jwtToken = jwtToken; } + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } } diff --git a/gateway/src/main/java/com/bonus/gateway/filter/AuthFilter.java b/gateway/src/main/java/com/bonus/gateway/filter/AuthFilter.java index 55d119c..79f8ac4 100644 --- a/gateway/src/main/java/com/bonus/gateway/filter/AuthFilter.java +++ b/gateway/src/main/java/com/bonus/gateway/filter/AuthFilter.java @@ -64,14 +64,7 @@ public class AuthFilter implements GlobalFilter, Ordered return chain.filter(exchange); } String token = getToken(request); - // 获取token中的用户ID - String userId = JwtUtils.getUserId(token); - // 获取用户当前有效的token - String currentToken = redisService.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + userId); - // 如果当前token和缓存中的token不一致,说明已被挤下线 - if (currentToken == null || !currentToken.equals(token)) { - return unauthorizedResponse(exchange,"您的账号已在其他设备登录"); - } + if (StringUtils.isEmpty(token) ) { @@ -94,7 +87,14 @@ public class AuthFilter implements GlobalFilter, Ordered { return unauthorizedResponse(exchange, "令牌验证失败"); } - + // 获取token中的用户ID + String userId = JwtUtils.getUserId(token); + // 获取用户当前有效的token + String currentToken = redisService.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + userId); + // 如果当前token和缓存中的token不一致,说明已被挤下线 + if (currentToken == null || !currentToken.equals(userkey)) { + return unauthorizedResponse(exchange,"您的账号已在其他设备登录"); + } // 设置用户信息到请求 addHeader(mutate, SecurityConstants.USER_KEY, userkey); addHeader(mutate, SecurityConstants.DETAILS_USER_ID, userid); diff --git a/modules/bmw/src/main/resources/static/css/login.css b/modules/bmw/src/main/resources/static/css/login.css index 4b31118..c936035 100644 --- a/modules/bmw/src/main/resources/static/css/login.css +++ b/modules/bmw/src/main/resources/static/css/login.css @@ -10,13 +10,24 @@ body { background-size: 100% 100%; } -#content{ +#content { width: 19%; - height: 37%; + /*height: 37%;*/ + + display: flex; + flex-direction: column; + align-content: center; margin-top: 15.5%; margin-left: 57%; } -.title{ + +.common-box { + height: 42px; + display: flex; + align-items: center; +} + +.title { color: #000; font-size: 30px; font-family: "微软雅黑"; @@ -24,37 +35,45 @@ body { letter-spacing: 10px; text-align: center; } -.content{ + +.content { height: 35%; margin-top: 13%; } -.phoneDiv{ - height: 35%; - background-color: rgba(255,255,255,0.1); + +.phoneDiv, .codeDiv, .pwdDiv { + height: 40px; + background-color: rgba(255, 255, 255, 0.1); } -.phoneDiv>div{ + +.phoneDiv > div { display: inline-block; } -.phoneDiv>.title{ + +.phoneDiv > .title { display: inline-block; - height: 60%; + height: 25px; width: 25px; background: url(../img/userName.png) no-repeat; background-size: 100% 100%; - margin-top: 2%; - margin-left: 2%; - float: left; + /*margin-top: 2%;*/ + /*margin-left: 2%;*/ + /*float: left;*/ + margin-right: 2%; } -#phoneDiv{ - width: 80%; + +#phoneDiv { + /*width: 80%;*/ height: 100%; margin-left: 3%; - float: left; + /*float: left;*/ + flex: 1; } -#username{ + +#username { height: 95%; width: 97%; - background-color: rgba(229,235,241,1); + background-color: rgba(229, 235, 241, 1); border: 0; outline: 0; float: left; @@ -62,55 +81,116 @@ body { } - - -.pwdDiv{ - height: 35%; +.pwdDiv { + /*height: 35%;*/ + height: 40px; margin-top: 9%; - background-color: rgba(255,255,255,0.1); + background-color: rgba(255, 255, 255, 0.1); } -.pwdDiv>div{ + +.pwdDiv > div { display: inline-block; } -.pwdDiv>.title{ + +.pwdDiv > .title { display: inline-block; - height: 60%; + height: 25px; width: 25px; background: url(../img/pwd.png) no-repeat; background-size: 100% 100%; - margin-top: 2%; - margin-left: 2%; - float: left; + /*margin-top: 2%;*/ + /*margin-left: 2%;*/ + /*float: left;*/ + margin-right: 2%; } -#pwdDiv{ - width: 80%; + +#pwdDiv { + /*width: 80%;*/ height: 100%; margin-left: 3%; - float: left; + /*float: left;*/ + flex: 1; } -#password{ + +.codeDiv { + /*height: 35%;*/ + height: 40px; + margin-top: 9%; + background-color: rgba(255, 255, 255, 0.1); +} + +.codeDiv > div { + display: inline-block; +} + +.codeDiv > .title { + display: inline-block; + height: 25px; + width: 25px; + background: url(../img/pwd.png) no-repeat; + background-size: 100% 100%; + /*margin-top: 2%;*/ + /*margin-left: 2%;*/ + /*float: left;*/ + margin-right: 2%; +} + +#codeDiv { + + /*width: 80%;*/ + height: 100%; + margin-left: 3%; + /*float: left;*/ + flex: 1; + + display: flex; +} + +#code-img { + height: 40px; + width: 120px; + object-fit: cover; + cursor:pointer; +} + +#password { height: 95%; width: 97%; - background-color: rgba(229,235,241,1); + background-color: rgba(229, 235, 241, 1); border: 0; outline: 0; float: left; color: #000; } -.func{ + +#code { + height: 95%; + /*width: 97%;*/ + background-color: rgba(229, 235, 241, 1); + border: 0; + outline: 0; + /*float: left;*/ + color: #000; + flex: 1; +} + +.func { height: 7%; margin-top: 4%; + display: flex; } -.func span:last-child{ + +.func span:last-child { color: #00367A; font-size: 13px; font-family: '微软雅黑'; margin-left: 64%; cursor: pointer; } -#login{ + +#login { height: 12.5%; - margin-top: 15%; + margin-top: 10%; background-color: #0857ba; text-align: center; line-height: 20px; @@ -120,10 +200,11 @@ body { line-height: 41px; cursor: pointer; } -#login:hover{ - background-color: rgba(8,87,186,0.5); + +#login:hover { + background-color: rgba(8, 87, 186, 0.5); } -input::-webkit-input-placeholder{ - color: rgba(152,167,191,0.5); +input::-webkit-input-placeholder { + color: rgba(152, 167, 191, 0.5); } diff --git a/modules/bmw/src/main/resources/static/login.html b/modules/bmw/src/main/resources/static/login.html index 3ae7548..8502c5a 100644 --- a/modules/bmw/src/main/resources/static/login.html +++ b/modules/bmw/src/main/resources/static/login.html @@ -1,41 +1,49 @@
- - - - -