登录设置权限 0.1

This commit is contained in:
Captain.B 2020-02-13 15:40:51 +08:00
parent 163912046b
commit ebf322cde3
15 changed files with 206 additions and 66 deletions

View File

@ -17,6 +17,8 @@ public class User implements Serializable {
private Long updateTime;
private String lastSourceId;
private static final long serialVersionUID = 1L;
public String getId() {
@ -74,4 +76,12 @@ public class User implements Serializable {
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
public String getLastSourceId() {
return lastSourceId;
}
public void setLastSourceId(String lastSourceId) {
this.lastSourceId = lastSourceId == null ? null : lastSourceId.trim();
}
}

View File

@ -573,6 +573,76 @@ public class UserExample {
addCriterion("update_time not between", value1, value2, "updateTime");
return (Criteria) this;
}
public Criteria andLastSourceIdIsNull() {
addCriterion("last_source_id is null");
return (Criteria) this;
}
public Criteria andLastSourceIdIsNotNull() {
addCriterion("last_source_id is not null");
return (Criteria) this;
}
public Criteria andLastSourceIdEqualTo(String value) {
addCriterion("last_source_id =", value, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdNotEqualTo(String value) {
addCriterion("last_source_id <>", value, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdGreaterThan(String value) {
addCriterion("last_source_id >", value, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdGreaterThanOrEqualTo(String value) {
addCriterion("last_source_id >=", value, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdLessThan(String value) {
addCriterion("last_source_id <", value, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdLessThanOrEqualTo(String value) {
addCriterion("last_source_id <=", value, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdLike(String value) {
addCriterion("last_source_id like", value, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdNotLike(String value) {
addCriterion("last_source_id not like", value, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdIn(List<String> values) {
addCriterion("last_source_id in", values, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdNotIn(List<String> values) {
addCriterion("last_source_id not in", values, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdBetween(String value1, String value2) {
addCriterion("last_source_id between", value1, value2, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdNotBetween(String value1, String value2) {
addCriterion("last_source_id not between", value1, value2, "lastSourceId");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -9,7 +9,7 @@ public class UserRole implements Serializable {
private String roleId;
private String resourceId;
private String sourceId;
private Long createTime;
@ -41,12 +41,12 @@ public class UserRole implements Serializable {
this.roleId = roleId == null ? null : roleId.trim();
}
public String getResourceId() {
return resourceId;
public String getSourceId() {
return sourceId;
}
public void setResourceId(String resourceId) {
this.resourceId = resourceId == null ? null : resourceId.trim();
public void setSourceId(String sourceId) {
this.sourceId = sourceId == null ? null : sourceId.trim();
}
public Long getCreateTime() {

View File

@ -314,73 +314,73 @@ public class UserRoleExample {
return (Criteria) this;
}
public Criteria andResourceIdIsNull() {
addCriterion("resource_id is null");
public Criteria andSourceIdIsNull() {
addCriterion("source_id is null");
return (Criteria) this;
}
public Criteria andResourceIdIsNotNull() {
addCriterion("resource_id is not null");
public Criteria andSourceIdIsNotNull() {
addCriterion("source_id is not null");
return (Criteria) this;
}
public Criteria andResourceIdEqualTo(String value) {
addCriterion("resource_id =", value, "resourceId");
public Criteria andSourceIdEqualTo(String value) {
addCriterion("source_id =", value, "sourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotEqualTo(String value) {
addCriterion("resource_id <>", value, "resourceId");
public Criteria andSourceIdNotEqualTo(String value) {
addCriterion("source_id <>", value, "sourceId");
return (Criteria) this;
}
public Criteria andResourceIdGreaterThan(String value) {
addCriterion("resource_id >", value, "resourceId");
public Criteria andSourceIdGreaterThan(String value) {
addCriterion("source_id >", value, "sourceId");
return (Criteria) this;
}
public Criteria andResourceIdGreaterThanOrEqualTo(String value) {
addCriterion("resource_id >=", value, "resourceId");
public Criteria andSourceIdGreaterThanOrEqualTo(String value) {
addCriterion("source_id >=", value, "sourceId");
return (Criteria) this;
}
public Criteria andResourceIdLessThan(String value) {
addCriterion("resource_id <", value, "resourceId");
public Criteria andSourceIdLessThan(String value) {
addCriterion("source_id <", value, "sourceId");
return (Criteria) this;
}
public Criteria andResourceIdLessThanOrEqualTo(String value) {
addCriterion("resource_id <=", value, "resourceId");
public Criteria andSourceIdLessThanOrEqualTo(String value) {
addCriterion("source_id <=", value, "sourceId");
return (Criteria) this;
}
public Criteria andResourceIdLike(String value) {
addCriterion("resource_id like", value, "resourceId");
public Criteria andSourceIdLike(String value) {
addCriterion("source_id like", value, "sourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotLike(String value) {
addCriterion("resource_id not like", value, "resourceId");
public Criteria andSourceIdNotLike(String value) {
addCriterion("source_id not like", value, "sourceId");
return (Criteria) this;
}
public Criteria andResourceIdIn(List<String> values) {
addCriterion("resource_id in", values, "resourceId");
public Criteria andSourceIdIn(List<String> values) {
addCriterion("source_id in", values, "sourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotIn(List<String> values) {
addCriterion("resource_id not in", values, "resourceId");
public Criteria andSourceIdNotIn(List<String> values) {
addCriterion("source_id not in", values, "sourceId");
return (Criteria) this;
}
public Criteria andResourceIdBetween(String value1, String value2) {
addCriterion("resource_id between", value1, value2, "resourceId");
public Criteria andSourceIdBetween(String value1, String value2) {
addCriterion("source_id between", value1, value2, "sourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotBetween(String value1, String value2) {
addCriterion("resource_id not between", value1, value2, "resourceId");
public Criteria andSourceIdNotBetween(String value1, String value2) {
addCriterion("source_id not between", value1, value2, "sourceId");
return (Criteria) this;
}

View File

@ -2,9 +2,8 @@ package io.metersphere.base.mapper;
import io.metersphere.base.domain.User;
import io.metersphere.base.domain.UserExample;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface UserMapper {
long countByExample(UserExample example);

View File

@ -9,6 +9,7 @@
<result column="status" jdbcType="VARCHAR" property="status" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" />
<result column="last_source_id" jdbcType="VARCHAR" property="lastSourceId" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -69,7 +70,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, name, email, phone, status, create_time, update_time
id, name, email, phone, status, create_time, update_time, last_source_id
</sql>
<select id="selectByExample" parameterType="io.metersphere.base.domain.UserExample" resultMap="BaseResultMap">
select
@ -104,10 +105,10 @@
<insert id="insert" parameterType="io.metersphere.base.domain.User">
insert into user (id, name, email,
phone, status, create_time,
update_time)
update_time, last_source_id)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR},
#{phone,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
#{updateTime,jdbcType=BIGINT})
#{updateTime,jdbcType=BIGINT}, #{lastSourceId,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.User">
insert into user
@ -133,6 +134,9 @@
<if test="updateTime != null">
update_time,
</if>
<if test="lastSourceId != null">
last_source_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -156,6 +160,9 @@
<if test="updateTime != null">
#{updateTime,jdbcType=BIGINT},
</if>
<if test="lastSourceId != null">
#{lastSourceId,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.UserExample" resultType="java.lang.Long">
@ -188,6 +195,9 @@
<if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=BIGINT},
</if>
<if test="record.lastSourceId != null">
last_source_id = #{record.lastSourceId,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -201,7 +211,8 @@
phone = #{record.phone,jdbcType=VARCHAR},
status = #{record.status,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT}
update_time = #{record.updateTime,jdbcType=BIGINT},
last_source_id = #{record.lastSourceId,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -227,6 +238,9 @@
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=BIGINT},
</if>
<if test="lastSourceId != null">
last_source_id = #{lastSourceId,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
@ -237,7 +251,8 @@
phone = #{phone,jdbcType=VARCHAR},
status = #{status,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT}
update_time = #{updateTime,jdbcType=BIGINT},
last_source_id = #{lastSourceId,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -2,9 +2,8 @@ package io.metersphere.base.mapper;
import io.metersphere.base.domain.UserRole;
import io.metersphere.base.domain.UserRoleExample;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface UserRoleMapper {
long countByExample(UserRoleExample example);

View File

@ -5,7 +5,7 @@
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="user_id" jdbcType="VARCHAR" property="userId" />
<result column="role_id" jdbcType="VARCHAR" property="roleId" />
<result column="resource_id" jdbcType="VARCHAR" property="resourceId" />
<result column="source_id" jdbcType="VARCHAR" property="sourceId" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" />
</resultMap>
@ -68,7 +68,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, user_id, role_id, resource_id, create_time, update_time
id, user_id, role_id, source_id, create_time, update_time
</sql>
<select id="selectByExample" parameterType="io.metersphere.base.domain.UserRoleExample" resultMap="BaseResultMap">
select
@ -102,10 +102,10 @@
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.UserRole">
insert into user_role (id, user_id, role_id,
resource_id, create_time, update_time
source_id, create_time, update_time
)
values (#{id,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR}, #{roleId,jdbcType=VARCHAR},
#{resourceId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}
#{sourceId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}
)
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.UserRole">
@ -120,8 +120,8 @@
<if test="roleId != null">
role_id,
</if>
<if test="resourceId != null">
resource_id,
<if test="sourceId != null">
source_id,
</if>
<if test="createTime != null">
create_time,
@ -140,8 +140,8 @@
<if test="roleId != null">
#{roleId,jdbcType=VARCHAR},
</if>
<if test="resourceId != null">
#{resourceId,jdbcType=VARCHAR},
<if test="sourceId != null">
#{sourceId,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=BIGINT},
@ -169,8 +169,8 @@
<if test="record.roleId != null">
role_id = #{record.roleId,jdbcType=VARCHAR},
</if>
<if test="record.resourceId != null">
resource_id = #{record.resourceId,jdbcType=VARCHAR},
<if test="record.sourceId != null">
source_id = #{record.sourceId,jdbcType=VARCHAR},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=BIGINT},
@ -188,7 +188,7 @@
set id = #{record.id,jdbcType=VARCHAR},
user_id = #{record.userId,jdbcType=VARCHAR},
role_id = #{record.roleId,jdbcType=VARCHAR},
resource_id = #{record.resourceId,jdbcType=VARCHAR},
source_id = #{record.sourceId,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT}
<if test="_parameter != null">
@ -204,8 +204,8 @@
<if test="roleId != null">
role_id = #{roleId,jdbcType=VARCHAR},
</if>
<if test="resourceId != null">
resource_id = #{resourceId,jdbcType=VARCHAR},
<if test="sourceId != null">
source_id = #{sourceId,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=BIGINT},
@ -220,7 +220,7 @@
update user_role
set user_id = #{userId,jdbcType=VARCHAR},
role_id = #{roleId,jdbcType=VARCHAR},
resource_id = #{resourceId,jdbcType=VARCHAR},
source_id = #{sourceId,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT}
where id = #{id,jdbcType=VARCHAR}

View File

@ -0,0 +1 @@
export const TokenKey = 'Admin-Token';

View File

@ -42,8 +42,8 @@
<script>
import Cookies from 'js-cookie';
import {TokenKey} from '../common/constants';
const TokenKey = 'Admin-Token';
export default {
name: "Login",

View File

@ -3,7 +3,7 @@
<router-link to="/content">
<font-awesome-icon :icon="['fas', 'user-plus']" size="lg"/>
</router-link>
<router-link to="/content">
<router-link to="/setting">
<font-awesome-icon :icon="['fas', 'cog']" size="lg"/>
</router-link>
</el-row>

View File

@ -12,14 +12,14 @@
<script>
import Cookies from 'js-cookie';
const TokenKey = 'Admin-Token';
import {TokenKey} from '../../common/constants';
export default {
name: "MsUser",
computed: {
currentUser: () => {
let user = Cookies.get(TokenKey);
window.console.log(user);
return JSON.parse(user);
}
},
@ -31,6 +31,7 @@
break;
case "logout":
this.$get("/signout", function () {
Cookies.remove(TokenKey);
window.location.href = "/login";
});
break;

View File

@ -18,7 +18,7 @@ const router = new VueRouter({
}
},
{
path: "/content", components: {
path: "/setting", components: {
content: Setting
},
children: [
@ -26,17 +26,24 @@ const router = new VueRouter({
path: 'workspace',
component: Workspace,
meta: {
roles: ['admin']
roles: ['org_admin']
}
},
{
path: 'user',
component: User
component: User,
meta: {
roles: ['admin']
}
},
{
path: 'organization',
component: Organization
},{
component: Organization,
meta: {
roles: ['admin']
}
},
{
path: 'workspace/user',
component: WorkspaceUser
}

View File

@ -7,6 +7,7 @@ import ajax from "../common/ajax";
import App from './App.vue';
import router from "./components/router/router";
import store from './store'
import './permission' // permission control
import i18n from "../i18n/i18n";
import timestampFormatDate from "./components/common/filter/TimestampFormatDateFilter";

View File

@ -0,0 +1,37 @@
import router from './components/router/router'
import Cookies from 'js-cookie' // get token from cookie
import {TokenKey} from '../common/constants';
const whiteList = ['/login']; // no redirect whitelist
router.beforeEach(async (to, from, next) => {
// determine whether the user has logged in
const user = JSON.parse(Cookies.get(TokenKey));
if (user && user.roles.length > 0) {
if (to.path === '/login') {
next({path: '/'});
} else {
// const roles = user.roles.filter(r => r.id);
// TODO 设置路由的权限
next()
}
} else {
/* has no token*/
if (whiteList.indexOf(to.path) !== -1) {
// in the free login whitelist, go directly
next()
} else {
// other pages that do not have permission to access are redirected to the login page.
next(`/login`)
}
}
});
router.afterEach(() => {
// finish progress bar
});