Browse Source

增加重置用户密码功能

main
蒋吉兆 3 years ago
parent
commit
6f0a8b95d4
  1. 18
      server/api/v1/system/sys_user.go
  2. 2
      server/model/system/sys_initdb.go
  3. 1
      server/router/system/sys_user.go
  4. 1
      server/service/system/sys_initdb_mysql.go
  5. 11
      server/service/system/sys_user.go
  6. 1
      server/source/api.go
  7. 1
      server/source/casbin.go
  8. 1
      server/source/system/api.go
  9. 7
      web/src/api/user.js
  10. 0
      web/src/assets/dashboard.png
  11. 37
      web/src/view/person/person.vue
  12. 74
      web/src/view/superAdmin/user/user.vue

18
server/api/v1/system/sys_user.go

@ -301,3 +301,21 @@ func (b *BaseApi) GetUserInfo(c *gin.Context) {
response.OkWithDetailed(gin.H{"userInfo": ReqUser}, "获取成功", c) response.OkWithDetailed(gin.H{"userInfo": ReqUser}, "获取成功", c)
} }
} }
// @Tags SysUser
// @Summary 用户修改密码
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body system.SysUser true "ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Router /user/resetPassword [post]
func (b *BaseApi) ResetPassword(c *gin.Context) {
var user system.SysUser
_ = c.ShouldBindJSON(&user)
if err := userService.ResetPassword(user.ID); err != nil {
global.GVA_LOG.Error("重置失败!", zap.Error(err))
response.FailWithMessage("重置失败"+err.Error(), c)
} else {
response.OkWithMessage("重置成功", c)
}
}

2
server/model/system/sys_initdb.go

@ -41,7 +41,7 @@ func MysqlDataInitialize(inits ...InitData) error {
if err := inits[i].Initialize(); err != nil { if err := inits[i].Initialize(); err != nil {
color.Info.Printf(InitDataFailed, Mysql, err) color.Info.Printf(InitDataFailed, Mysql, err)
continue
return err
} else { } else {
color.Info.Printf(InitDataSuccess, Mysql, inits[i].TableName()) color.Info.Printf(InitDataSuccess, Mysql, inits[i].TableName())
} }

1
server/router/system/sys_user.go

@ -20,6 +20,7 @@ func (s *UserRouter) InitUserRouter(Router *gin.RouterGroup) {
userRouter.DELETE("deleteUser", baseApi.DeleteUser) // 删除用户 userRouter.DELETE("deleteUser", baseApi.DeleteUser) // 删除用户
userRouter.PUT("setUserInfo", baseApi.SetUserInfo) // 设置用户信息 userRouter.PUT("setUserInfo", baseApi.SetUserInfo) // 设置用户信息
userRouter.POST("setUserAuthorities", baseApi.SetUserAuthorities) // 设置用户权限组 userRouter.POST("setUserAuthorities", baseApi.SetUserAuthorities) // 设置用户权限组
userRouter.POST("resetPassword", baseApi.ResetPassword) // 设置用户权限组
} }
{ {
userRouterWithoutRecord.POST("getUserList", baseApi.GetUserList) // 分页获取用户列表 userRouterWithoutRecord.POST("getUserList", baseApi.GetUserList) // 分页获取用户列表

1
server/service/system/sys_initdb_mysql.go

@ -110,7 +110,6 @@ func (initDBService *InitDBService) initMysqlData() error {
system.AuthoritiesMenus, system.AuthoritiesMenus,
system.DictionaryDetail, system.DictionaryDetail,
system.ViewAuthorityMenuMysql, system.ViewAuthorityMenuMysql,
example.File, example.File,
) )
} }

11
server/service/system/sys_user.go

@ -187,3 +187,14 @@ func (userService *UserService) FindUserByUuid(uuid string) (err error, user *sy
} }
return nil, &u return nil, &u
} }
//@author: [piexlmax](https://github.com/piexlmax)
//@function: resetPassword
//@description: 修改用户密码
//@param: ID uint
//@return: err error
func (userService *UserService) ResetPassword(ID uint) (err error) {
err = global.GVA_DB.Model(&system.SysUser{}).Where("id = ?", ID).Update("password", utils.MD5V([]byte("123456"))).Error
return err
}

1
server/source/api.go

@ -93,6 +93,7 @@ var apis = []system.SysApi{
{global.GVA_MODEL{ID: 89, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/delSysHistory", "删除回滚记录", "autoCode", "POST"}, {global.GVA_MODEL{ID: 89, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/delSysHistory", "删除回滚记录", "autoCode", "POST"},
{global.GVA_MODEL{ID: 90, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserAuthorities", "设置权限组", "user", "POST"}, {global.GVA_MODEL{ID: 90, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserAuthorities", "设置权限组", "user", "POST"},
{global.GVA_MODEL{ID: 91, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/getUserInfo", "获取自身信息(必选)", "user", "GET"}, {global.GVA_MODEL{ID: 91, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/getUserInfo", "获取自身信息(必选)", "user", "GET"},
{global.GVA_MODEL{ID: 92, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/resetPassword", "重置指定用户密码", "user", "POST"},
} }
//@author: [SliverHorn](https://github.com/SliverHorn) //@author: [SliverHorn](https://github.com/SliverHorn)

1
server/source/casbin.go

@ -92,6 +92,7 @@ var carbines = []gormadapter.CasbinRule{
{PType: "p", V0: "888", V1: "/autoCode/delSysHistory", V2: "POST"}, {PType: "p", V0: "888", V1: "/autoCode/delSysHistory", V2: "POST"},
{PType: "p", V0: "888", V1: "/user/setUserAuthorities", V2: "POST"}, {PType: "p", V0: "888", V1: "/user/setUserAuthorities", V2: "POST"},
{PType: "p", V0: "888", V1: "/user/getUserInfo", V2: "GET"}, {PType: "p", V0: "888", V1: "/user/getUserInfo", V2: "GET"},
{PType: "p", V0: "888", V1: "/user/resetPassword", V2: "POST"},
{PType: "p", V0: "8881", V1: "/base/login", V2: "POST"}, {PType: "p", V0: "8881", V1: "/base/login", V2: "POST"},
{PType: "p", V0: "8881", V1: "/user/register", V2: "POST"}, {PType: "p", V0: "8881", V1: "/user/register", V2: "POST"},
{PType: "p", V0: "8881", V1: "/api/createApi", V2: "POST"}, {PType: "p", V0: "8881", V1: "/api/createApi", V2: "POST"},

1
server/source/system/api.go

@ -28,6 +28,7 @@ func (a *api) Initialize() error {
{ApiGroup: "系统用户", Method: "POST", Path: "/user/setUserAuthorities", Description: "设置权限组"}, {ApiGroup: "系统用户", Method: "POST", Path: "/user/setUserAuthorities", Description: "设置权限组"},
{ApiGroup: "系统用户", Method: "POST", Path: "/user/changePassword", Description: "修改密码(建(选择)"}, {ApiGroup: "系统用户", Method: "POST", Path: "/user/changePassword", Description: "修改密码(建(选择)"},
{ApiGroup: "系统用户", Method: "POST", Path: "/user/setUserAuthority", Description: "修改用户角色(必选)"}, {ApiGroup: "系统用户", Method: "POST", Path: "/user/setUserAuthority", Description: "修改用户角色(必选)"},
{ApiGroup: "系统用户", Method: "POST", Path: "/api/resetPassword", Description: "重置用户密码"},
{ApiGroup: "api", Method: "POST", Path: "/api/createApi", Description: "创建api"}, {ApiGroup: "api", Method: "POST", Path: "/api/createApi", Description: "创建api"},
{ApiGroup: "api", Method: "POST", Path: "/api/deleteApi", Description: "删除Api"}, {ApiGroup: "api", Method: "POST", Path: "/api/deleteApi", Description: "删除Api"},

7
web/src/api/user.js

@ -141,3 +141,10 @@ export const getUserInfo = () => {
method: 'get' method: 'get'
}) })
} }
export const resetPassword = () => {
return service({
url: '/user/resetPassword',
method: 'post'
})
}

0
web/src/assets/dashbord.png → web/src/assets/dashboard.png

Before

Width: 700  |  Height: 700  |  Size: 70 KiB

After

Width: 700  |  Height: 700  |  Size: 70 KiB

37
web/src/view/person/person.vue

@ -10,7 +10,12 @@
重新上传</span> 重新上传</span>
</div> </div>
<div class="user-personality"> <div class="user-personality">
<p class="nickname">{{ userInfo.nickName }}</p>
<p v-if="!editFlag" class="nickName">{{ userInfo.nickName }} <i class="el-icon-edit pointer" style="color:#66b1ff" @click="openEidt" /></p>
<p v-if="editFlag" class="nickName">
<el-input v-model="nickName" />
<i class="el-icon-check pointer" style="color:#67c23a" @click="enterEdit" />
<i class="el-icon-close pointer" style="color:#f23c3c" @click="closeEdit" />
</p>
<p class="person-info">这个家伙很懒什么都没有留下</p> <p class="person-info">这个家伙很懒什么都没有留下</p>
</div> </div>
<div class="user-information"> <div class="user-information">
@ -118,6 +123,8 @@ export default {
activeName: 'second', activeName: 'second',
showPassword: false, showPassword: false,
pwdModify: {}, pwdModify: {},
nickName: '',
editFlag: false,
rules: { rules: {
password: [ password: [
{ required: true, message: '请输入密码', trigger: 'blur' }, { required: true, message: '请输入密码', trigger: 'blur' },
@ -188,6 +195,26 @@ export default {
}) })
} }
}, },
openEidt() {
this.nickName = this.userInfo.nickName
this.editFlag = true
},
closeEdit() {
this.nickName = ''
this.editFlag = false
},
async enterEdit() {
const res = await setUserInfo({ nickName: this.nickName, ID: this.userInfo.ID })
if (res.code === 0) {
this.ResetUserInfo({ nickName: this.nickName })
this.$message({
type: 'success',
message: '设置成功'
})
}
this.nickName = ''
this.editFlag = false
},
handleClick(tab, event) { handleClick(tab, event) {
console.log(tab, event) console.log(tab, event)
} }
@ -236,7 +263,10 @@ export default {
p { p {
font-size: 16px; font-size: 16px;
} }
.nickname {
.nickName {
display: flex;
justify-content: center;
align-items: center;
font-size: 26px; font-size: 26px;
} }
.person-info{ .person-info{
@ -314,4 +344,7 @@ export default {
color:transparent; color:transparent;
} }
} }
.pointer{
cursor: pointer;
}
</style> </style>

74
web/src/view/superAdmin/user/user.vue

@ -13,7 +13,16 @@
</el-table-column> </el-table-column>
<el-table-column align="left" label="UUID" min-width="250" prop="uuid" /> <el-table-column align="left" label="UUID" min-width="250" prop="uuid" />
<el-table-column align="left" label="用户名" min-width="150" prop="userName" /> <el-table-column align="left" label="用户名" min-width="150" prop="userName" />
<el-table-column align="left" label="昵称" min-width="150" prop="nickName" />
<el-table-column align="left" label="昵称" min-width="100" prop="nickName">
<template #default="scope">
<p v-if="!scope.row.editFlag" class="nickName">{{ scope.row.nickName }} <i class="el-icon-edit pointer" style="color:#66b1ff" @click="openEidt(scope.row)" /></p>
<p v-if="scope.row.editFlag" class="nickName">
<el-input v-model="scope.row.nickName" />
<i class="el-icon-check pointer" style="color:#67c23a" @click="enterEdit(scope.row)" />
<i class="el-icon-close pointer" style="color:#f23c3c" @click="closeEdit(scope.row)" />
</p>
</template>
</el-table-column>
<el-table-column align="left" label="用户角色" min-width="150"> <el-table-column align="left" label="用户角色" min-width="150">
<template #default="scope"> <template #default="scope">
<el-cascader <el-cascader
@ -40,6 +49,7 @@
<el-button type="text" icon="el-icon-delete" size="mini">删除</el-button> <el-button type="text" icon="el-icon-delete" size="mini">删除</el-button>
</template> </template>
</el-popover> </el-popover>
<el-button type="text" icon="el-icon-magic-stick" size="mini" @click="resetPassword(scope.row)">重置密码</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -110,6 +120,7 @@ import { mapGetters } from 'vuex'
import CustomPic from '@/components/customPic/index.vue' import CustomPic from '@/components/customPic/index.vue'
import ChooseImg from '@/components/chooseImg/index.vue' import ChooseImg from '@/components/chooseImg/index.vue'
import warningBar from '@/components/warningBar/warningBar.vue' import warningBar from '@/components/warningBar/warningBar.vue'
import { setUserInfo, resetPassword } from '@/api/user.js'
export default { export default {
name: 'Api', name: 'Api',
components: { CustomPic, ChooseImg, warningBar }, components: { CustomPic, ChooseImg, warningBar },
@ -120,6 +131,7 @@ export default {
path: path, path: path,
authOptions: [], authOptions: [],
addUserDialog: false, addUserDialog: false,
backNickName: '',
userInfo: { userInfo: {
username: '', username: '',
password: '', password: '',
@ -160,6 +172,32 @@ export default {
this.setOptions(res.data.list) this.setOptions(res.data.list)
}, },
methods: { methods: {
resetPassword(row) {
this.$confirm(
'是否将此用户密码重置为123456?',
'警告',
{
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}
).then(async() => {
const res = await resetPassword({
ID: row.ID,
})
if (res.code === 0) {
this.$message({
type: 'success',
message: res.msg,
})
} else {
this.$message({
type: 'error',
message: res.msg,
})
}
})
},
setAuthorityIds() { setAuthorityIds() {
this.tableData && this.tableData.forEach((user) => { this.tableData && this.tableData.forEach((user) => {
const authorityIds = user.authorities && user.authorities.map(i => { const authorityIds = user.authorities && user.authorities.map(i => {
@ -175,6 +213,30 @@ export default {
this.authOptions = [] this.authOptions = []
this.setAuthorityOptions(authData, this.authOptions) this.setAuthorityOptions(authData, this.authOptions)
}, },
openEidt(row) {
if (this.tableData.some(item => item.editFlag)) {
this.$message('当前存在正在编辑的用户')
return
}
this.backNickName = row.nickName
row.editFlag = true
},
async enterEdit(row) {
const res = await setUserInfo({ nickName: row.nickName, ID: row.ID })
if (res.code === 0) {
this.$message({
type: 'success',
message: '设置成功'
})
}
this.backNickName = ''
row.editFlag = false
},
closeEdit(row) {
row.nickName = this.backNickName
this.backNickName = ''
row.editFlag = false
},
setAuthorityOptions(AuthorityData, optionsData) { setAuthorityOptions(AuthorityData, optionsData) {
AuthorityData && AuthorityData &&
AuthorityData.forEach(item => { AuthorityData.forEach(item => {
@ -273,4 +335,14 @@ export default {
display: block; display: block;
} }
} }
.nickName{
display: flex;
justify-content: flex-start;
align-items: center;
}
.pointer{
cursor: pointer;
font-size: 16px;
margin-left: 2px;
}
</style> </style>
Loading…
Cancel
Save