From 9c477fb4637462bcfa41929326180699b6aff8fa Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Fri, 19 Feb 2021 17:05:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fit2cloud/commons/auth/api/UserApi.java | 6 +- .../commons/auth/config/F2cRealm.java | 10 +- .../commons/auth/dao/ExtUserMapper.java | 5 +- fit2cloud-view/.env.development | 2 +- fit2cloud-view/mock/user-token.js | 4 +- fit2cloud-view/src/api/user-token.js | 21 ---- fit2cloud-view/src/api/user.js | 16 ++- fit2cloud-view/src/business/login/index.vue | 8 +- fit2cloud-view/src/permission.js | 5 +- fit2cloud-view/src/store/getters.js | 1 + .../src/store/modules/user-token.js | 97 ------------------- fit2cloud-view/src/store/modules/user.js | 54 ++++++----- fit2cloud-view/vue.config.js | 3 +- 13 files changed, 64 insertions(+), 168 deletions(-) delete mode 100644 fit2cloud-view/src/api/user-token.js delete mode 100644 fit2cloud-view/src/store/modules/user-token.js diff --git a/fit2cloud-commons/fit2cloud-common-auth/src/main/java/com/fit2cloud/commons/auth/api/UserApi.java b/fit2cloud-commons/fit2cloud-common-auth/src/main/java/com/fit2cloud/commons/auth/api/UserApi.java index c94440fc82..ce80688de6 100644 --- a/fit2cloud-commons/fit2cloud-common-auth/src/main/java/com/fit2cloud/commons/auth/api/UserApi.java +++ b/fit2cloud-commons/fit2cloud-common-auth/src/main/java/com/fit2cloud/commons/auth/api/UserApi.java @@ -35,12 +35,12 @@ public class UserApi { throw new RuntimeException("没有该用户!"); } String pwd = RsaUtil.decryptByPrivateKey(RsaProperties.privateKey, password); - String realpwd = RsaUtil.decryptByPrivateKey(RsaProperties.privateKey, realPwd); - if (!StrUtil.equals(pwd, realpwd)){ + String realPass = RsaUtil.decryptByPrivateKey(RsaProperties.privateKey, realPwd); + if (!StrUtil.equals(pwd, realPass)){ throw new RuntimeException("密码错误!"); } Map result = new HashMap<>(); - result.put("token", JWTUtil.sign(username, realpwd)); + result.put("token", JWTUtil.sign(username, realPass)); return result; } diff --git a/fit2cloud-commons/fit2cloud-common-auth/src/main/java/com/fit2cloud/commons/auth/config/F2cRealm.java b/fit2cloud-commons/fit2cloud-common-auth/src/main/java/com/fit2cloud/commons/auth/config/F2cRealm.java index d8b1c6ef01..892fd00ada 100644 --- a/fit2cloud-commons/fit2cloud-common-auth/src/main/java/com/fit2cloud/commons/auth/config/F2cRealm.java +++ b/fit2cloud-commons/fit2cloud-common-auth/src/main/java/com/fit2cloud/commons/auth/config/F2cRealm.java @@ -3,6 +3,7 @@ package com.fit2cloud.commons.auth.config; import com.fit2cloud.commons.auth.bean.UserBean; import com.fit2cloud.commons.auth.service.UserService; import com.fit2cloud.commons.auth.util.JWTUtil; +import com.fit2cloud.commons.auth.util.RsaUtil; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.shiro.authc.AuthenticationException; @@ -67,8 +68,13 @@ public class F2cRealm extends AuthorizingRealm { if (userBean == null) { throw new AuthenticationException("User didn't existed!"); } - - if (! JWTUtil.verify(token, username, userBean.getPassword())) { + String pwd = null; + try { + pwd = RsaUtil.decryptByPrivateKey(RsaProperties.privateKey, userBean.getPassword()); + } catch (Exception e) { + e.printStackTrace(); + } + if (! JWTUtil.verify(token, username, pwd)) { throw new AuthenticationException("Username or password error"); } diff --git a/fit2cloud-commons/fit2cloud-common-auth/src/main/java/com/fit2cloud/commons/auth/dao/ExtUserMapper.java b/fit2cloud-commons/fit2cloud-common-auth/src/main/java/com/fit2cloud/commons/auth/dao/ExtUserMapper.java index f65d39a9ba..28566486cd 100644 --- a/fit2cloud-commons/fit2cloud-common-auth/src/main/java/com/fit2cloud/commons/auth/dao/ExtUserMapper.java +++ b/fit2cloud-commons/fit2cloud-common-auth/src/main/java/com/fit2cloud/commons/auth/dao/ExtUserMapper.java @@ -15,7 +15,7 @@ public interface ExtUserMapper { @Select("select password from sys_user where username = #{userName,jdbcType=VARCHAR} ") String getPassword(String userName); - @Select("select role_id from sys_users_roles where username = #{userName,jdbcType=VARCHAR} ") + @Select("select role_id from sys_users_roles sur left join sys_user su on su.user_id = sur.user_id where su.username = #{userName,jdbcType=VARCHAR} ") List getRole(String userName); @Select({ @@ -23,7 +23,8 @@ public interface ExtUserMapper { "from sys_users_roles sur ", "LEFT JOIN sys_roles_menus srm on srm.role_id = sur.role_id ", "LEFT JOIN sys_menu sm on sm.menu_id = srm.menu_id ", - "where sur.username = #{userName,jdbcType=VARCHAR} " + "LEFT JOIN sys_user su on su.user_id = sur.user_id ", + "where su.username = #{userName,jdbcType=VARCHAR} " }) List getPermission(String userName); diff --git a/fit2cloud-view/.env.development b/fit2cloud-view/.env.development index e625e73e3d..5ebedc1c41 100644 --- a/fit2cloud-view/.env.development +++ b/fit2cloud-view/.env.development @@ -2,4 +2,4 @@ ENV = 'development' # base api, e.g., '/dev' -VUE_APP_BASE_API = '' +VUE_APP_BASE_API = 'http://localhost:8081/' diff --git a/fit2cloud-view/mock/user-token.js b/fit2cloud-view/mock/user-token.js index 5fb072ea5a..45a2d4bf42 100644 --- a/fit2cloud-view/mock/user-token.js +++ b/fit2cloud-view/mock/user-token.js @@ -41,7 +41,7 @@ const users = { module.exports = [ // user login { - url: '/samples/user-token/login', + url: '/samples/user/login', type: 'post', response: config => { const {username} = config.body @@ -57,7 +57,7 @@ module.exports = [ // get user info { - url: '/samples/user-token/info', + url: '/samples/user/info', type: 'get', response: (config) => { let token = config.headers[TOKEN_KEY] diff --git a/fit2cloud-view/src/api/user-token.js b/fit2cloud-view/src/api/user-token.js deleted file mode 100644 index 5dc6435d97..0000000000 --- a/fit2cloud-view/src/api/user-token.js +++ /dev/null @@ -1,21 +0,0 @@ -/* 前后端分离的登录方式 */ -import {get, post, put} from "@/plugins/request" - -export function login(data) { - return post("/login", data) -} - -export function logout() { - return post("/logout") -} - -export function getCurrentUser() { - return get("/info") -} - -export function updateInfo(data) { - return put("/update", data) -} - - - diff --git a/fit2cloud-view/src/api/user.js b/fit2cloud-view/src/api/user.js index bdb9daa82e..5dc6435d97 100644 --- a/fit2cloud-view/src/api/user.js +++ b/fit2cloud-view/src/api/user.js @@ -1,24 +1,20 @@ -/* 前后端不分离的登录方式 */ +/* 前后端分离的登录方式 */ import {get, post, put} from "@/plugins/request" export function login(data) { - return post("/samples/user/login", data) + return post("/login", data) } export function logout() { - return post("/samples/user/logout") -} - -export function isLogin() { - return get("/samples/user/is-login") + return post("/logout") } export function getCurrentUser() { - return get("/samples/user/current") + return get("/info") } -export function updateInfo(id, data) { - return put("/samples/user/info/update/" + id, data) +export function updateInfo(data) { + return put("/update", data) } diff --git a/fit2cloud-view/src/business/login/index.vue b/fit2cloud-view/src/business/login/index.vue index c05263e7a4..761680a68d 100644 --- a/fit2cloud-view/src/business/login/index.vue +++ b/fit2cloud-view/src/business/login/index.vue @@ -43,6 +43,7 @@