修改用户密码.

This commit is contained in:
lijiahang
2023-10-31 12:39:12 +08:00
parent 46fd799021
commit 6c9aabd4fd
11 changed files with 255 additions and 40 deletions

View File

@@ -63,4 +63,6 @@ public interface ErrorMessage {
String PASSWORD_MISSING = "请输入密码";
String BEFORE_PASSWORD_ERROR = "原密码错误";
}

View File

@@ -4,11 +4,10 @@ import com.orion.lang.define.wrapper.HttpWrapper;
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
import com.orion.ops.framework.security.core.utils.SecurityUtils;
import com.orion.ops.framework.web.core.annotation.RestWrapper;
import com.orion.ops.module.infra.define.operator.AuthenticationOperatorType;
import com.orion.ops.module.infra.entity.request.user.UserLoginRequest;
import com.orion.ops.module.infra.entity.request.user.UserResetPasswordRequest;
import com.orion.ops.module.infra.entity.request.user.UserUpdatePasswordRequest;
import com.orion.ops.module.infra.entity.vo.UserLoginVO;
import com.orion.ops.module.infra.service.AuthenticationService;
import com.orion.ops.module.infra.service.SystemUserService;
@@ -66,10 +65,8 @@ public class AuthenticationController {
@OperatorLog(AuthenticationOperatorType.UPDATE_PASSWORD)
@Operation(summary = "修改密码")
@PutMapping("/update-password")
public HttpWrapper<?> updatePassword(@Validated @RequestBody UserResetPasswordRequest request) {
// 当前用户id
request.setId(SecurityUtils.getLoginUserId());
systemUserService.resetPassword(request);
public HttpWrapper<?> updatePassword(@Validated @RequestBody UserUpdatePasswordRequest request) {
authenticationService.updatePassword(request);
return HttpWrapper.ok();
}

View File

@@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* 重置密码请求
@@ -16,6 +17,7 @@ import javax.validation.constraints.NotEmpty;
@Schema(name = "UserResetPasswordRequest", description = "重置密码请求")
public class UserResetPasswordRequest {
@NotNull
@Schema(description = "id")
private Long id;

View File

@@ -0,0 +1,27 @@
package com.orion.ops.module.infra.entity.request.user;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
/**
* 修改密码请求
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023/7/17 12:19
*/
@Data
@Schema(name = "UserUpdatePasswordRequest", description = "修改密码请求")
public class UserUpdatePasswordRequest {
@NotEmpty
@Schema(description = "原密码")
private String beforePassword;
@NotEmpty
@Schema(description = "新密码")
private String password;
}

View File

@@ -3,6 +3,7 @@ package com.orion.ops.module.infra.service;
import com.orion.ops.framework.common.security.LoginUser;
import com.orion.ops.module.infra.entity.dto.LoginTokenDTO;
import com.orion.ops.module.infra.entity.request.user.UserLoginRequest;
import com.orion.ops.module.infra.entity.request.user.UserUpdatePasswordRequest;
import com.orion.ops.module.infra.entity.vo.UserLoginVO;
import javax.servlet.http.HttpServletRequest;
@@ -42,6 +43,13 @@ public interface AuthenticationService {
*/
void logout(HttpServletRequest servletRequest);
/**
* 修改密码
*
* @param request request
*/
void updatePassword(UserUpdatePasswordRequest request);
/**
* 获取登陆用户信息
*

View File

@@ -73,7 +73,7 @@ public interface SystemUserService {
/**
* 删除 id 删除用户拓展信息
*
* @param id
* @param id id
*/
void deleteSystemUserRel(Long id);

View File

@@ -24,11 +24,14 @@ import com.orion.ops.module.infra.entity.domain.SystemRoleDO;
import com.orion.ops.module.infra.entity.domain.SystemUserDO;
import com.orion.ops.module.infra.entity.dto.LoginTokenDTO;
import com.orion.ops.module.infra.entity.request.user.UserLoginRequest;
import com.orion.ops.module.infra.entity.request.user.UserResetPasswordRequest;
import com.orion.ops.module.infra.entity.request.user.UserUpdatePasswordRequest;
import com.orion.ops.module.infra.entity.vo.UserLoginVO;
import com.orion.ops.module.infra.enums.LoginTokenStatusEnum;
import com.orion.ops.module.infra.enums.UserStatusEnum;
import com.orion.ops.module.infra.service.AuthenticationService;
import com.orion.ops.module.infra.service.PermissionService;
import com.orion.ops.module.infra.service.SystemUserService;
import com.orion.web.servlet.web.Servlets;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
@@ -57,6 +60,9 @@ public class AuthenticationServiceImpl implements AuthenticationService {
@Resource
private SystemUserRoleDAO systemUserRoleDAO;
@Resource
private SystemUserService systemUserService;
@Resource
private PermissionService permissionService;
@@ -120,6 +126,22 @@ public class AuthenticationServiceImpl implements AuthenticationService {
redisTemplate.delete(Lists.of(loginKey, refreshKey));
}
@Override
public void updatePassword(UserUpdatePasswordRequest request) {
Long userId = SecurityUtils.getLoginUserId();
// 查询用户信息
SystemUserDO record = systemUserDAO.selectById(userId);
Valid.notNull(record, ErrorMessage.USER_ABSENT);
// 对比原始密码
String beforePassword = Signatures.md5(request.getBeforePassword());
Valid.eq(beforePassword, record.getPassword(), ErrorMessage.BEFORE_PASSWORD_ERROR);
// 重置密码
UserResetPasswordRequest reset = new UserResetPasswordRequest();
reset.setId(userId);
reset.setPassword(request.getPassword());
systemUserService.resetPassword(reset);
}
@Override
public LoginUser getLoginUser(Long id) {
String userInfoKey = UserCacheKeyDefine.USER_INFO.format(id);

View File

@@ -15,6 +15,14 @@ export interface LoginResponse {
token: string;
}
/**
* 修改密码请求
*/
export interface UserUpdatePasswordRequest {
beforePassword?: string;
password?: string;
}
/**
* 登陆
*/
@@ -29,6 +37,13 @@ export function logout() {
return axios.get('/infra/auth/logout');
}
/**
* 修改密码
*/
export function updatePassword(request: UserUpdatePasswordRequest) {
return axios.put('/infra/auth/update-password', request);
}
/**
* 获取用户信息
*/

View File

@@ -38,15 +38,15 @@
<a-tooltip content="语言">
<a-button class="nav-btn"
type="outline"
:shape="'circle'"
@click="setUserInfoVisible">
shape="circle"
@click="setLocalesVisible">
<template #icon>
<icon-language />
</template>
</a-button>
</a-tooltip>
<a-dropdown trigger="click" @select="changeLocale">
<div ref="refUserInfoTrigger" class="trigger-btn" />
<div ref="localeRef" class="trigger-btn" />
<template #content>
<a-doption v-for="item in locales"
:key="item.value"
@@ -66,7 +66,7 @@
: '点击切换为亮色模式'">
<a-button class="nav-btn"
type="outline"
:shape="'circle'"
shape="circle"
@click="handleToggleTheme">
<template #icon>
<icon-moon-fill v-if="theme === 'dark'" />
@@ -82,7 +82,7 @@
<a-badge :count="9" dot>
<a-button class="nav-btn"
type="outline"
:shape="'circle'"
shape="circle"
@click="setMessageBoxVisible">
<icon-notification />
</a-button>
@@ -93,7 +93,7 @@
:arrow-style="{ display: 'none' }"
:content-style="{ padding: 0, minWidth: '400px' }"
content-class="message-popover">
<div ref="refMessageBoxTrigger" class="ref-btn" />
<div ref="messageRef" class="ref-btn" />
<template #content>
<message-box />
</template>
@@ -161,7 +161,7 @@
</a-doption>
<!-- 修改密码 -->
<a-doption>
<a-space @click="$router.push({ name: 'userMine' })">
<a-space @click="() => updatePasswordRef.open()">
<icon-lock />
<span>修改密码</span>
</a-space>
@@ -177,6 +177,8 @@
</a-dropdown>
</li>
</ul>
<!-- 修改密码模态框-->
<update-password-modal ref="updatePasswordRef" @updated="handleLogout" />
</div>
</template>
@@ -192,25 +194,14 @@
import MessageBox from '@/components/system/message-box/index.vue';
import { openAppSettingKey, toggleDrawerMenuKey } from '@/types/symbol';
import { preferenceTipsKey } from './const';
import UpdatePasswordModal from '@/components/user/role/update-password-modal.vue';
const tipsStore = useTipsStore();
const tippedPreference = ref(tipsStore.isNotTipped(preferenceTipsKey));
const appStore = useAppStore();
const userStore = useUserStore();
const { logout } = useUser();
const { changeLocale, currentLocale } = useLocale();
const { isFullscreen, toggle: toggleFullScreen } = useFullscreen();
const locales = [...LOCALE_OPTIONS];
const nickname = computed(() => {
return userStore.nickname?.substring(0, 1);
});
const topMenu = computed(() => appStore.topMenu && appStore.menu);
// 当前主题
const theme = computed(() => {
return appStore.theme;
});
// 主题
const darkTheme = useDark({
selector: 'body',
@@ -225,24 +216,42 @@
},
});
// 用户名
const nickname = computed(() => userStore.nickname?.substring(0, 1));
// 是否展示顶部菜单
const topMenu = computed(() => appStore.topMenu && appStore.menu);
// 当前主题
const theme = computed(() => appStore.theme);
const locales = [...LOCALE_OPTIONS];
// 偏好提示
const tippedPreference = ref(tipsStore.isNotTipped(preferenceTipsKey));
// 修改密码
const updatePasswordRef = ref();
// 消息
const messageRef = ref();
// 语言
const localeRef = ref();
// 打开应用设置
const openAppSetting = inject(openAppSettingKey) as () => void;
// 注入收缩菜单
const toggleDrawerMenu = inject(toggleDrawerMenuKey) as () => void;
// 切换主题
const handleToggleTheme = () => {
useToggle(darkTheme)();
};
// 打开应用设置
const openAppSetting = inject(openAppSettingKey) as () => void;
// 消息触发器 ref
const refMessageBoxTrigger = ref();
// 打开消息
const setMessageBoxVisible = () => {
triggerMouseEvent(refMessageBoxTrigger);
triggerMouseEvent(messageRef);
};
// 个人信息触发器 ref
const refUserInfoTrigger = ref();
const setUserInfoVisible = () => {
triggerMouseEvent(refUserInfoTrigger);
// 打开语言切换
const setLocalesVisible = () => {
triggerMouseEvent(localeRef);
};
// 退出登录
@@ -250,9 +259,6 @@
logout();
};
// 注入收缩菜单
const toggleDrawerMenu = inject(toggleDrawerMenuKey) as () => void;
// 关闭偏好提示
const closePreferenceTip = (ack: boolean) => {
tippedPreference.value = false;

View File

@@ -80,10 +80,11 @@
<script lang="ts" setup>
import type { TableColumnData } from '@arco-design/web-vue/es/table/interface';
import type { HistoryValueQueryRequest, HistoryValueQueryResponse } from '@/api/meta/history-value';
import { reactive, ref } from 'vue';
import useLoading from '@/hooks/loading';
import useVisible from '@/hooks/visible';
import { getHistoryValuePage, HistoryValueQueryRequest, HistoryValueQueryResponse } from '@/api/meta/history-value';
import { getHistoryValuePage } from '@/api/meta/history-value';
import { usePagination } from '@/types/table';
import useCopy from '@/hooks/copy';
import { dateFormat } from '@/utils';

View File

@@ -0,0 +1,135 @@
<template>
<a-modal v-model:visible="visible"
body-class="modal-form"
title-align="start"
title="重置密码"
:top="120"
:align-center="false"
:draggable="true"
:mask-closable="false"
:unmount-on-close="true"
:ok-button-props="{ disabled: loading }"
:cancel-button-props="{ disabled: loading }"
:on-before-ok="handlerOk"
@close="handleClose">
<a-spin :loading="loading">
<a-form :model="formModel"
ref="formRef"
label-align="right"
:rules="rules"
:style="{ width: '460px' }"
:label-col-props="{ span: 6 }"
:wrapper-col-props="{ span: 18 }">
<!-- 密码 -->
<a-form-item field="beforePassword" label="原始密码">
<a-input-password v-model="formModel.beforePassword" placeholder="请输入原始密码" />
</a-form-item>
<!-- 密码 -->
<a-form-item field="password" label="新密码">
<a-input-password v-model="formModel.password" placeholder="请输入新密码" />
</a-form-item>
</a-form>
</a-spin>
</a-modal>
</template>
<script lang="ts">
export default {
name: 'update-password-modal'
};
</script>
<script lang="ts" setup>
import type { UserUpdatePasswordRequest } from '@/api/user/auth';
import { ref } from 'vue';
import useLoading from '@/hooks/loading';
import useVisible from '@/hooks/visible';
import { Message } from '@arco-design/web-vue';
import { md5 } from '@/utils';
import { updatePassword } from '@/api/user/auth';
const emits = defineEmits(['updated']);
const { visible, setVisible } = useVisible();
const { loading, setLoading } = useLoading();
const rules = {
beforePassword: [{
required: true,
message: '请输入原始密码'
}],
password: [{
required: true,
message: '请输入新密码'
}, {
minLength: 8,
maxLength: 32,
message: '新密码长度需要在 8-32 位之间'
}],
};
const formRef = ref();
const formModel = ref<UserUpdatePasswordRequest>({});
// 打开
const open = () => {
formModel.value = {
beforePassword: undefined,
password: undefined
};
setVisible(true);
};
defineExpose({ open });
// 确定
const handlerOk = async () => {
setLoading(true);
try {
// 验证参数
const error = await formRef.value.validate();
if (error) {
return false;
}
// 相同校验
if (formModel.value.beforePassword === formModel.value.password) {
formRef.value.setFields({
password: {
status: 'error',
message: '新密码不能和原始密码相同'
}
});
return false;
}
// 修改
await updatePassword({
beforePassword: md5(formModel.value.beforePassword as string),
password: md5(formModel.value.password as string)
});
Message.success('修改成功');
// 清空
handlerClear();
emits('updated');
} catch (e) {
return false;
} finally {
setLoading(false);
}
};
// 关闭
const handleClose = () => {
handlerClear();
};
// 清空
const handlerClear = () => {
setLoading(false);
setVisible(false);
};
</script>
<style lang="less" scoped>
</style>