Browse Source

用户管理代码更新

master
李永德 2 years ago
parent
commit
87e6a51fa8
  1. 3
      lms/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java
  2. 8
      lms/nladmin-system/src/main/java/org/nl/modules/system/rest/UserController.java
  3. 58
      lms/nladmin-system/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java
  4. 8
      lms/nladmin-ui/src/views/login.vue
  5. 55
      lms/nladmin-ui/src/views/system/user/index.vue
  6. 34
      lms/nladmin-ui/src/views/wms/sch/point/index.vue

3
lms/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java

@ -92,6 +92,9 @@ public class AuthorizationController {
throw new BadRequestException("账号或密码错误"); throw new BadRequestException("账号或密码错误");
} }
// 判断是否被锁
if (!userDto.getEnabled()) throw new BadRequestException("账号未激活");
// 获取权限列表 - 登录查找权限 // 获取权限列表 - 登录查找权限
List<String> permissionList = roleService.getPermissionList(userDto); List<String> permissionList = roleService.getPermissionList(userDto);

8
lms/nladmin-system/src/main/java/org/nl/modules/system/rest/UserController.java

@ -19,6 +19,7 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.secure.SaSecureUtil; import cn.dev33.satoken.secure.SaSecureUtil;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -38,7 +39,9 @@ import org.nl.modules.system.service.UserService;
import org.nl.modules.system.service.dto.RoleSmallDto; import org.nl.modules.system.service.dto.RoleSmallDto;
import org.nl.modules.system.service.dto.UserDto; import org.nl.modules.system.service.dto.UserDto;
import org.nl.modules.system.service.dto.UserQueryCriteria; import org.nl.modules.system.service.dto.UserQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -109,7 +112,10 @@ public class UserController {
public ResponseEntity<Object> create(@Validated @RequestBody User resources){ public ResponseEntity<Object> create(@Validated @RequestBody User resources){
checkLevel(resources); checkLevel(resources);
// 默认密码 123456 // 默认密码 123456
resources.setPassword(SaSecureUtil.md5BySalt("123456", "salt")); if (ObjectUtil.isEmpty(resources.getPassword()))
resources.setPassword(SaSecureUtil.md5BySalt("123456", "salt"));
else
resources.setPassword(SaSecureUtil.md5BySalt(resources.getPassword(), "salt"));
userService.create(resources); userService.create(resources);
return new ResponseEntity<>(HttpStatus.CREATED); return new ResponseEntity<>(HttpStatus.CREATED);
} }

58
lms/nladmin-system/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java

@ -15,6 +15,8 @@
*/ */
package org.nl.modules.system.service.impl; package org.nl.modules.system.service.impl;
import cn.dev33.satoken.secure.SaSecureUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.nl.modules.common.config.FileProperties; import org.nl.modules.common.config.FileProperties;
@ -89,9 +91,6 @@ public class UserServiceImpl implements UserService {
if (userRepository.findByUsername(resources.getUsername()) != null) { if (userRepository.findByUsername(resources.getUsername()) != null) {
throw new EntityExistException(User.class, "username", resources.getUsername()); throw new EntityExistException(User.class, "username", resources.getUsername());
} }
if (userRepository.findByEmail(resources.getEmail()) != null) {
throw new EntityExistException(User.class, "email", resources.getEmail());
}
resources.setCreateBy(SecurityUtils.getCurrentUsername()); resources.setCreateBy(SecurityUtils.getCurrentUsername());
userRepository.save(resources); userRepository.save(resources);
} }
@ -102,45 +101,36 @@ public class UserServiceImpl implements UserService {
User user = userRepository.findById(resources.getId()).orElseGet(User::new); User user = userRepository.findById(resources.getId()).orElseGet(User::new);
ValidationUtil.isNull(user.getId(), "User", "id", resources.getId()); ValidationUtil.isNull(user.getId(), "User", "id", resources.getId());
User user1 = userRepository.findByUsername(resources.getUsername()); User user1 = userRepository.findByUsername(resources.getUsername());
User user2 = userRepository.findByEmail(resources.getEmail());
if (user1 != null && !user.getId().equals(user1.getId())) { if (user1 != null && !user.getId().equals(user1.getId())) {
throw new EntityExistException(User.class, "username", resources.getUsername()); throw new EntityExistException(User.class, "username", resources.getUsername());
} }
if (user2 != null && !user.getId().equals(user2.getId())) {
throw new EntityExistException(User.class, "email", resources.getEmail());
}
// 如果用户的角色改变 // 如果用户的角色改变
if (!resources.getRoles().equals(user.getRoles())) { if (!resources.getRoles().equals(user.getRoles())) {
redisUtils.del(CacheKey.DATA_USER + resources.getId()); redisUtils.del(CacheKey.DATA_USER + resources.getId());
redisUtils.del(CacheKey.MENU_USER + resources.getId()); redisUtils.del(CacheKey.MENU_USER + resources.getId());
redisUtils.del(CacheKey.ROLE_AUTH + resources.getId()); redisUtils.del(CacheKey.ROLE_AUTH + resources.getId());
} }
// 如果用户名称修改 redisUtils.del("user::username:" + user.getUsername());
if(!resources.getUsername().equals(user.getUsername())){
redisUtils.del("user::username:" + user.getUsername());
}
// 如果用户被禁用,则清除用户登录信息 // 如果用户被禁用,则清除用户登录信息
if(!resources.getEnabled()){ if(!resources.getEnabled()){
onlineUserService.kickOutForUsername(resources.getUsername()); onlineUserService.kickOutForUsername(resources.getUsername());
} }
User clone = new User(); // jpa 多表问题,需要用新的类来进行修改 user.setId(resources.getId());
clone.setId(resources.getId()); user.setUsername(resources.getUsername());
clone.setUsername(resources.getUsername()); user.setEmail(resources.getEmail());
clone.setEmail(resources.getEmail()); user.setEnabled(resources.getEnabled());
clone.setEnabled(resources.getEnabled()); user.setRoles(resources.getRoles());
clone.setRoles(resources.getRoles()); user.setDept(resources.getDept());
clone.setDept(resources.getDept()); user.setPhone(resources.getPhone());
clone.setPhone(resources.getPhone()); user.setNickName(resources.getNickName());
clone.setNickName(resources.getNickName()); user.setGender(resources.getGender());
clone.setGender(resources.getGender()); if (ObjectUtil.isNotEmpty(resources.getPassword()))
user.setPassword(SaSecureUtil.md5BySalt(resources.getPassword(), "salt"));
userRepository.save(clone);
userRepository.save(user);
// 清除缓存 // 清除缓存
delCaches(user.getId(), user.getUsername()); delCaches(user.getId(), user.getUsername());
// 修改session
// flushSession(user);
} }
@Override @Override
@ -153,8 +143,6 @@ public class UserServiceImpl implements UserService {
userRepository.save(user); userRepository.save(user);
// 清理缓存 // 清理缓存
delCaches(user.getId(), user.getUsername()); delCaches(user.getId(), user.getUsername());
// 修改session
// flushSession(user);
} }
@Override @Override
@ -184,7 +172,6 @@ public class UserServiceImpl implements UserService {
public void updatePass(String username, String pass) { public void updatePass(String username, String pass) {
userRepository.updatePass(username, pass, new Date()); userRepository.updatePass(username, pass, new Date());
redisUtils.del("user::username:" + username); redisUtils.del("user::username:" + username);
// flushSession(userRepository.findByUsername(username));
} }
@Override @Override
@ -200,7 +187,6 @@ public class UserServiceImpl implements UserService {
FileUtil.del(oldPath); FileUtil.del(oldPath);
} }
@NotBlank String username = user.getUsername(); @NotBlank String username = user.getUsername();
// flushSession(user);
return new HashMap<String, String>(1) {{ return new HashMap<String, String>(1) {{
put("avatar", file.getName()); put("avatar", file.getName());
}}; }};
@ -210,7 +196,6 @@ public class UserServiceImpl implements UserService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateEmail(String username, String email) { public void updateEmail(String username, String email) {
userRepository.updateEmail(username, email); userRepository.updateEmail(username, email);
// flushSession(userRepository.findByUsername(username));
} }
@Override @Override
@ -239,17 +224,6 @@ public class UserServiceImpl implements UserService {
*/ */
public void delCaches(Long id, String username) { public void delCaches(Long id, String username) {
redisUtils.del(CacheKey.USER_ID + id); redisUtils.del(CacheKey.USER_ID + id);
// flushCache(username);
} }
/**
* 清理 登陆时 用户缓存信息
*
* @param user /
*/
// private void flushSession(User user) {
// UserDto userDto = this.findByName(user.getUsername());
// List<String> permissionList = roleService.getPermissionList(userDto.getId().toString());
// flushSessionUtil.flushSessionInfo(userDto, permissionList);
// }
} }

8
lms/nladmin-ui/src/views/login.vue

@ -2,7 +2,7 @@
<div class="login" :style="'background-image:url('+ Background +');'"> <div class="login" :style="'background-image:url('+ Background +');'">
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" label-position="left" label-width="0px" class="login-form"> <el-form ref="loginForm" :model="loginForm" :rules="loginRules" label-position="left" label-width="0px" class="login-form">
<h3 class="title"> <h3 class="title">
{{title}}</h3> {{ title }}</h3>
<el-form-item prop="username"> <el-form-item prop="username">
<el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号"> <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号">
<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" /> <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
@ -120,14 +120,12 @@ export default {
code: this.loginForm.code, code: this.loginForm.code,
uuid: this.loginForm.uuid uuid: this.loginForm.uuid
} }
if (user.password !== this.cookiePass) { user.password = encrypt(user.password)
user.password = encrypt(user.password)
}
if (valid) { if (valid) {
this.loading = true this.loading = true
if (user.rememberMe) { if (user.rememberMe) {
Cookies.set('username', user.username, { expires: Config.passCookieExpires }) Cookies.set('username', user.username, { expires: Config.passCookieExpires })
Cookies.set('password', user.password, { expires: Config.passCookieExpires }) Cookies.set('password', this.loginForm.password, { expires: Config.passCookieExpires })
Cookies.set('rememberMe', user.rememberMe, { expires: Config.passCookieExpires }) Cookies.set('rememberMe', user.rememberMe, { expires: Config.passCookieExpires })
} else { } else {
Cookies.remove('username') Cookies.remove('username')

55
lms/nladmin-ui/src/views/system/user/index.vue

@ -80,7 +80,7 @@
<el-form-item label="邮箱" prop="email"> <el-form-item label="邮箱" prop="email">
<el-input v-model="form.email" style="width: 200px;" /> <el-input v-model="form.email" style="width: 200px;" />
</el-form-item> </el-form-item>
<el-form-item label="部门" prop="dept.id"> <el-form-item label="部门" prop="dept.id" :rules="[{ required: true, message: '请选择部门', trigger: 'change' }]">
<treeselect <treeselect
v-model="form.dept.id" v-model="form.dept.id"
:options="depts" :options="depts"
@ -89,7 +89,10 @@
placeholder="选择部门" placeholder="选择部门"
/> />
</el-form-item> </el-form-item>
<br v-if="!crud.status.add">
<el-form-item v-if="crud.status.add" label="密码" prop="password">
<el-input v-model="form.password" style="width: 200px;" show-password auto-complete="new-password" />
</el-form-item>
<el-form-item label="性别"> <el-form-item label="性别">
<el-radio-group v-model="form.gender" style="width: 178px"> <el-radio-group v-model="form.gender" style="width: 178px">
<el-radio label="男"></el-radio> <el-radio label="男"></el-radio>
@ -168,16 +171,26 @@
<el-table-column <el-table-column
v-permission="['admin','user:edit','user:del']" v-permission="['admin','user:edit','user:del']"
label="操作" label="操作"
width="115" width="200"
align="center" align="center"
fixed="right" fixed="right"
> >
<template slot-scope="scope"> <template slot-scope="scope">
<udOperation <udOperation
style="display:inline;"
:data="scope.row" :data="scope.row"
:permission="permission" :permission="permission"
:disabled-dle="scope.row.id === user.id" :disabled-dle="scope.row.id === user.id"
/> />
<el-button
slot="left"
v-permission="permission.edit"
type="text"
icon="el-icon-refresh-left"
@click="resetPassword(scope.row)"
>
重置密码
</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -212,7 +225,8 @@ const defaultForm = {
enabled: 'true', enabled: 'true',
roles: [], roles: [],
dept: { id: null }, dept: { id: null },
phone: null phone: null,
password: null
} }
export default { export default {
name: 'User', name: 'User',
@ -256,7 +270,7 @@ export default {
]) ])
}, },
created() { created() {
this.crud.msg.add = '新增成功,默认密码:123456' this.crud.msg.add = '新增成功'
}, },
mounted: function() { mounted: function() {
const that = this const that = this
@ -292,6 +306,7 @@ export default {
}, },
// //
[CRUD.HOOK.beforeToAdd]() { [CRUD.HOOK.beforeToAdd]() {
this.form.password = '123456'
this.roleDatas = [] this.roleDatas = []
}, },
// //
@ -435,14 +450,36 @@ export default {
}, },
checkboxT(row, rowIndex) { checkboxT(row, rowIndex) {
return row.id !== this.user.id return row.id !== this.user.id
},
resetPassword(row) {
row.password = null
this.$prompt('', '重置密码', {
confirmButtonText: '确定',
cancelButtonText: '取消',
inputPlaceholder: '请输入新的密码',
inputPattern: /^[A-Z|a-z|0-9|(._~!@#$^&*)]{6,20}$/,
inputErrorMessage: '密码格式不正确,只能是6-20位密码',
closeOnClickModal: false
}).then(({ value }) => {
row.password = value
crudUser.edit(row).then(res => {
this.crud.toQuery()
this.crud.notify('密码重置成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
})
}).catch(() => {
this.$message({
type: 'info',
message: '取消输入'
})
})
} }
} }
} }
</script> </script>
<style rel="stylesheet/scss" lang="scss" scoped> <style rel="stylesheet/scss" lang="scss" scoped>
::v-deep .vue-treeselect__control, ::v-deep .vue-treeselect__placeholder, ::v-deep .vue-treeselect__single-value { ::v-deep .vue-treeselect__control, ::v-deep .vue-treeselect__placeholder, ::v-deep .vue-treeselect__single-value {
height: 30px; height: 30px;
line-height: 30px; line-height: 30px;
} }
</style> </style>

34
lms/nladmin-ui/src/views/wms/sch/point/index.vue

@ -27,7 +27,7 @@
size="mini" size="mini"
placeholder="区域类型" placeholder="区域类型"
class="filter-item" class="filter-item"
@change="getPointStatusAndTypeList" @change="getPointStatusAndTypeList(query.region_id, 1)"
> >
<el-option <el-option
v-for="item in regionList" v-for="item in regionList"
@ -205,7 +205,7 @@
v-model="form.region_id" v-model="form.region_id"
placeholder="请选择" placeholder="请选择"
style="width: 370px;" style="width: 370px;"
@change="getPointStatusAndTypeList" @change="getPointStatusAndTypeList(form.region_id, 2)"
> >
<el-option <el-option
v-for="item in regionList" v-for="item in regionList"
@ -223,7 +223,7 @@
style="width: 370px;" style="width: 370px;"
> >
<el-option <el-option
v-for="item in pointTypesList" v-for="item in pointTypesDialogList"
:label="item.label" :label="item.label"
:value="item.value" :value="item.value"
/> />
@ -239,7 +239,7 @@
clearable clearable
> >
<el-option <el-option
v-for="item in pointStatusList" v-for="item in pointStatusDialogList"
:label="item.label" :label="item.label"
:value="item.value" :value="item.value"
/> />
@ -379,7 +379,9 @@ export default {
syncLoading: false, syncLoading: false,
invtypelist: [], invtypelist: [],
pointStatusList: [], pointStatusList: [],
pointStatusDialogList: [],
pointTypesList: [], pointTypesList: [],
pointTypesDialogList: [],
options: [], options: [],
regionList: [], regionList: [],
permission: {}, permission: {},
@ -443,21 +445,31 @@ export default {
}).catch(() => { }).catch(() => {
}) })
}, },
getPointStatusAndTypeList(id) { getPointStatusAndTypeList(id, flag) {
if (id) { if (id) {
this.getPointStatusList(id) this.getPointStatusList(id, flag)
this.getPointTypeList(id) this.getPointTypeList(id, flag)
}
if (flag === 1) {
this.crud.toQuery() this.crud.toQuery()
} }
}, },
getPointStatusList(id) { getPointStatusList(id, flag) {
crudRegion.getPointStatusSelectById(id).then(res => { crudRegion.getPointStatusSelectById(id).then(res => {
this.pointStatusList = res if (flag === 1) {
this.pointStatusList = res
} else {
this.pointStatusDialogList = res
}
}) })
}, },
getPointTypeList(id) { getPointTypeList(id, flag) {
crudRegion.getPointTypeSelectById(id).then(res => { crudRegion.getPointTypeSelectById(id).then(res => {
this.pointTypesList = res if (flag === 1) {
this.pointTypesList = res
} else {
this.pointTypesDialogList = res
}
}) })
}, },
changeUsed(data, flag) { // changeUsed(data, flag) { //

Loading…
Cancel
Save