review: 修改 api 结构.
This commit is contained in:
@@ -7,7 +7,6 @@ import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
|
|||||||
import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
||||||
import com.orion.ops.module.infra.define.operator.AuthenticationOperatorType;
|
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.UserLoginRequest;
|
||||||
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.entity.vo.UserLoginVO;
|
||||||
import com.orion.ops.module.infra.service.AuthenticationService;
|
import com.orion.ops.module.infra.service.AuthenticationService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
@@ -58,12 +57,4 @@ public class AuthenticationController {
|
|||||||
return HttpWrapper.ok();
|
return HttpWrapper.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@OperatorLog(AuthenticationOperatorType.UPDATE_PASSWORD)
|
|
||||||
@Operation(summary = "修改密码")
|
|
||||||
@PutMapping("/update-password")
|
|
||||||
public HttpWrapper<?> updatePassword(@Validated @RequestBody UserUpdatePasswordRequest request) {
|
|
||||||
authenticationService.updatePassword(request);
|
|
||||||
return HttpWrapper.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
### 查询当前用户信息
|
||||||
|
GET {{baseUrl}}/infra/mine/get-user
|
||||||
|
Authorization: {{token}}
|
||||||
|
|
||||||
|
|
||||||
|
### 更新当前用户信息
|
||||||
|
PUT {{baseUrl}}/infra/mine/update-user
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: {{token}}
|
||||||
|
|
||||||
|
{
|
||||||
|
"nickname": "名称",
|
||||||
|
"mobile": "15555555555",
|
||||||
|
"email": "123@123.com"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
### 修改当前用户密码
|
||||||
|
PUT {{baseUrl}}/infra/mine/update-password
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: {{token}}
|
||||||
|
|
||||||
|
{
|
||||||
|
"beforePassword": "21232f297a57a5a743894a0e4a801fc3",
|
||||||
|
"password": "21232f297a57a5a743894a0e4a801fc3"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
### 查询当前用户登录日志
|
||||||
|
GET {{baseUrl}}/infra/mine/login-history
|
||||||
|
Authorization: {{token}}
|
||||||
|
|
||||||
|
###
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package com.orion.ops.module.infra.controller;
|
||||||
|
|
||||||
|
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.web.core.annotation.RestWrapper;
|
||||||
|
import com.orion.ops.module.infra.define.operator.AuthenticationOperatorType;
|
||||||
|
import com.orion.ops.module.infra.entity.request.user.SystemUserUpdateRequest;
|
||||||
|
import com.orion.ops.module.infra.entity.request.user.UserUpdatePasswordRequest;
|
||||||
|
import com.orion.ops.module.infra.entity.vo.LoginHistoryVO;
|
||||||
|
import com.orion.ops.module.infra.entity.vo.SystemUserVO;
|
||||||
|
import com.orion.ops.module.infra.service.MineService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 个人服务
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023/11/1 0:19
|
||||||
|
*/
|
||||||
|
@Tag(name = "infra - 个人服务")
|
||||||
|
@Slf4j
|
||||||
|
@Validated
|
||||||
|
@RestWrapper
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/infra/mine")
|
||||||
|
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
|
||||||
|
public class MineController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MineService mineService;
|
||||||
|
|
||||||
|
@IgnoreLog(IgnoreLogMode.RET)
|
||||||
|
@GetMapping("/get-user")
|
||||||
|
@Operation(summary = "查询当前用户信息")
|
||||||
|
public SystemUserVO getCurrentUserInfo() {
|
||||||
|
return mineService.getCurrentUserInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update-user")
|
||||||
|
@Operation(summary = "更新当前用户信息")
|
||||||
|
public Integer updateCurrentUser(@Validated @RequestBody SystemUserUpdateRequest request) {
|
||||||
|
return mineService.updateCurrentUser(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OperatorLog(AuthenticationOperatorType.UPDATE_PASSWORD)
|
||||||
|
@Operation(summary = "修改当前用户密码")
|
||||||
|
@PutMapping("/update-password")
|
||||||
|
public HttpWrapper<?> updateCurrentUserPassword(@Validated @RequestBody UserUpdatePasswordRequest request) {
|
||||||
|
mineService.updateCurrentUserPassword(request);
|
||||||
|
return HttpWrapper.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
@IgnoreLog(IgnoreLogMode.RET)
|
||||||
|
@GetMapping("/login-history")
|
||||||
|
@Operation(summary = "查询当前用户登录日志")
|
||||||
|
public List<LoginHistoryVO> getCurrentLoginHistory() {
|
||||||
|
return mineService.getCurrentLoginHistory();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -48,7 +48,6 @@ public class OperatorLogController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fixme 权限配置
|
// fixme 权限配置
|
||||||
|
|
||||||
@IgnoreLog(IgnoreLogMode.RET)
|
@IgnoreLog(IgnoreLogMode.RET)
|
||||||
@GetMapping("/login-history")
|
@GetMapping("/login-history")
|
||||||
@Operation(summary = "查询用户登录日志")
|
@Operation(summary = "查询用户登录日志")
|
||||||
@@ -56,13 +55,5 @@ public class OperatorLogController {
|
|||||||
return operatorLogService.getLoginHistory(username);
|
return operatorLogService.getLoginHistory(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@IgnoreLog(IgnoreLogMode.RET)
|
|
||||||
@GetMapping("/current-login-history")
|
|
||||||
@Operation(summary = "查询当前用户登录日志")
|
|
||||||
public List<LoginHistoryVO> getCurrentLoginHistory() {
|
|
||||||
String username = SecurityUtils.getLoginUsername();
|
|
||||||
return operatorLogService.getLoginHistory(username);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
|
|||||||
import com.orion.ops.framework.common.validator.group.Page;
|
import com.orion.ops.framework.common.validator.group.Page;
|
||||||
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
|
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
|
||||||
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
|
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.framework.web.core.annotation.RestWrapper;
|
||||||
import com.orion.ops.module.infra.define.operator.SystemUserOperatorType;
|
import com.orion.ops.module.infra.define.operator.SystemUserOperatorType;
|
||||||
import com.orion.ops.module.infra.entity.request.user.*;
|
import com.orion.ops.module.infra.entity.request.user.*;
|
||||||
@@ -96,20 +95,6 @@ public class SystemUserController {
|
|||||||
return HttpWrapper.ok();
|
return HttpWrapper.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@IgnoreLog(IgnoreLogMode.RET)
|
|
||||||
@GetMapping("/get-current")
|
|
||||||
@Operation(summary = "查询当前用户信息")
|
|
||||||
public SystemUserVO getCurrentUserInfo() {
|
|
||||||
return systemUserService.getSystemUserById(SecurityUtils.getLoginUserId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/update-current")
|
|
||||||
@Operation(summary = "更新当前用户信息")
|
|
||||||
public Integer updateCurrentUser(@Validated @RequestBody SystemUserUpdateRequest request) {
|
|
||||||
request.setId(SecurityUtils.getLoginUserId());
|
|
||||||
return systemUserService.updateSystemUserById(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
@IgnoreLog(IgnoreLogMode.RET)
|
@IgnoreLog(IgnoreLogMode.RET)
|
||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
@Operation(summary = "通过 id 查询用户")
|
@Operation(summary = "通过 id 查询用户")
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.orion.ops.module.infra.service;
|
|||||||
import com.orion.ops.framework.common.security.LoginUser;
|
import com.orion.ops.framework.common.security.LoginUser;
|
||||||
import com.orion.ops.module.infra.entity.dto.LoginTokenDTO;
|
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.UserLoginRequest;
|
||||||
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.entity.vo.UserLoginVO;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -43,13 +42,6 @@ public interface AuthenticationService {
|
|||||||
*/
|
*/
|
||||||
void logout(HttpServletRequest servletRequest);
|
void logout(HttpServletRequest servletRequest);
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改密码
|
|
||||||
*
|
|
||||||
* @param request request
|
|
||||||
*/
|
|
||||||
void updatePassword(UserUpdatePasswordRequest request);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取登录用户信息
|
* 获取登录用户信息
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.orion.ops.module.infra.service;
|
||||||
|
|
||||||
|
import com.orion.ops.module.infra.entity.request.user.SystemUserUpdateRequest;
|
||||||
|
import com.orion.ops.module.infra.entity.request.user.UserUpdatePasswordRequest;
|
||||||
|
import com.orion.ops.module.infra.entity.vo.LoginHistoryVO;
|
||||||
|
import com.orion.ops.module.infra.entity.vo.SystemUserVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 个人服务
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023/11/1 0:25
|
||||||
|
*/
|
||||||
|
public interface MineService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前登录用户信息
|
||||||
|
*
|
||||||
|
* @return user
|
||||||
|
*/
|
||||||
|
SystemUserVO getCurrentUserInfo();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新当前登录用户信息
|
||||||
|
*
|
||||||
|
* @param request request
|
||||||
|
* @return effect
|
||||||
|
*/
|
||||||
|
Integer updateCurrentUser(SystemUserUpdateRequest request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改当前用户密码
|
||||||
|
*
|
||||||
|
* @param request request
|
||||||
|
*/
|
||||||
|
void updateCurrentUserPassword(UserUpdatePasswordRequest request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前用户登录日志
|
||||||
|
*
|
||||||
|
* @return 登录日志
|
||||||
|
*/
|
||||||
|
List<LoginHistoryVO> getCurrentLoginHistory();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -24,8 +24,6 @@ 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.domain.SystemUserDO;
|
||||||
import com.orion.ops.module.infra.entity.dto.LoginTokenDTO;
|
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.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.entity.vo.UserLoginVO;
|
||||||
import com.orion.ops.module.infra.enums.LoginTokenStatusEnum;
|
import com.orion.ops.module.infra.enums.LoginTokenStatusEnum;
|
||||||
import com.orion.ops.module.infra.enums.UserStatusEnum;
|
import com.orion.ops.module.infra.enums.UserStatusEnum;
|
||||||
@@ -60,9 +58,6 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
|||||||
@Resource
|
@Resource
|
||||||
private SystemUserRoleDAO systemUserRoleDAO;
|
private SystemUserRoleDAO systemUserRoleDAO;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private SystemUserService systemUserService;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private PermissionService permissionService;
|
private PermissionService permissionService;
|
||||||
|
|
||||||
@@ -127,22 +122,6 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
|||||||
redisTemplate.delete(Lists.of(loginKey, refreshKey));
|
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
|
@Override
|
||||||
public LoginUser getLoginUser(Long id) {
|
public LoginUser getLoginUser(Long id) {
|
||||||
String userInfoKey = UserCacheKeyDefine.USER_INFO.format(id);
|
String userInfoKey = UserCacheKeyDefine.USER_INFO.format(id);
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.orion.ops.module.infra.service.impl;
|
||||||
|
|
||||||
|
import com.orion.lang.utils.crypto.Signatures;
|
||||||
|
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||||
|
import com.orion.ops.framework.common.utils.Valid;
|
||||||
|
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||||
|
import com.orion.ops.module.infra.dao.SystemUserDAO;
|
||||||
|
import com.orion.ops.module.infra.entity.domain.SystemUserDO;
|
||||||
|
import com.orion.ops.module.infra.entity.request.user.SystemUserUpdateRequest;
|
||||||
|
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.LoginHistoryVO;
|
||||||
|
import com.orion.ops.module.infra.entity.vo.SystemUserVO;
|
||||||
|
import com.orion.ops.module.infra.service.MineService;
|
||||||
|
import com.orion.ops.module.infra.service.OperatorLogService;
|
||||||
|
import com.orion.ops.module.infra.service.SystemUserService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 个人服务实现
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023/11/1 0:25
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class MineServiceImpl implements MineService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SystemUserService systemUserService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private OperatorLogService operatorLogService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SystemUserDAO systemUserDAO;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SystemUserVO getCurrentUserInfo() {
|
||||||
|
return systemUserService.getSystemUserById(SecurityUtils.getLoginUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer updateCurrentUser(SystemUserUpdateRequest request) {
|
||||||
|
request.setId(SecurityUtils.getLoginUserId());
|
||||||
|
return systemUserService.updateSystemUserById(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateCurrentUserPassword(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 List<LoginHistoryVO> getCurrentLoginHistory() {
|
||||||
|
String username = SecurityUtils.getLoginUsername();
|
||||||
|
return operatorLogService.getLoginHistory(username);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -53,19 +53,19 @@ axios.interceptors.response.use(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
// 业务判断
|
// 业务判断
|
||||||
if (
|
if ([401, 700, 701, 702].includes(code)) {
|
||||||
[401, 700, 701, 702].includes(code) &&
|
|
||||||
response.config.url !== '/infra/auth/login'
|
|
||||||
) {
|
|
||||||
Notification.error({
|
Notification.error({
|
||||||
closable: true,
|
closable: true,
|
||||||
content: res.msg,
|
content: res.msg,
|
||||||
});
|
});
|
||||||
setTimeout(async () => {
|
// 非登录页面跳转登录页面
|
||||||
// 登出
|
if (response.config.url !== '/infra/auth/login') {
|
||||||
await useUserStore().logout();
|
setTimeout(async () => {
|
||||||
window.location.reload();
|
// 登出
|
||||||
});
|
await useUserStore().logout();
|
||||||
|
window.location.reload();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Promise.reject(new Error(res.msg || 'Error'));
|
return Promise.reject(new Error(res.msg || 'Error'));
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -15,14 +15,6 @@ export interface LoginResponse {
|
|||||||
token: string;
|
token: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改密码请求
|
|
||||||
*/
|
|
||||||
export interface UserUpdatePasswordRequest {
|
|
||||||
beforePassword?: string;
|
|
||||||
password?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录
|
* 登录
|
||||||
*/
|
*/
|
||||||
@@ -37,13 +29,6 @@ export function logout() {
|
|||||||
return axios.get('/infra/auth/logout');
|
return axios.get('/infra/auth/logout');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改密码
|
|
||||||
*/
|
|
||||||
export function updatePassword(request: UserUpdatePasswordRequest) {
|
|
||||||
return axios.put('/infra/auth/update-password', request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户信息
|
* 获取用户信息
|
||||||
*/
|
*/
|
||||||
|
|||||||
40
orion-ops-ui/src/api/user/mine.ts
Normal file
40
orion-ops-ui/src/api/user/mine.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import type { LoginHistoryQueryResponse } from './operator-log';
|
||||||
|
import type { UserQueryResponse, UserUpdateRequest } from './user';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改密码请求
|
||||||
|
*/
|
||||||
|
export interface UserUpdatePasswordRequest {
|
||||||
|
beforePassword?: string;
|
||||||
|
password?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改当前用户密码
|
||||||
|
*/
|
||||||
|
export function updateCurrentUserPassword(request: UserUpdatePasswordRequest) {
|
||||||
|
return axios.put('/infra/mine/update-password', request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询当前用户
|
||||||
|
*/
|
||||||
|
export function getCurrentUser() {
|
||||||
|
return axios.get<UserQueryResponse>('/infra/mine/get-user');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新当前用户
|
||||||
|
*/
|
||||||
|
export function updateCurrentUser(request: UserUpdateRequest) {
|
||||||
|
return axios.put('/infra/mine/update-user', request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询当前用户登录日志
|
||||||
|
*/
|
||||||
|
export function getCurrentLoginHistory() {
|
||||||
|
return axios.get<LoginHistoryQueryResponse[]>('/infra/mine/login-history');
|
||||||
|
}
|
||||||
|
|
||||||
@@ -66,10 +66,3 @@ export function getOperatorLogPage(request: OperatorLogQueryRequest) {
|
|||||||
export function getLoginHistory(username: string) {
|
export function getLoginHistory(username: string) {
|
||||||
return axios.get<LoginHistoryQueryResponse[]>('/infra/operator-log/login-history', { params: { username } });
|
return axios.get<LoginHistoryQueryResponse[]>('/infra/operator-log/login-history', { params: { username } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询当前用户登录日志
|
|
||||||
*/
|
|
||||||
export function getCurrentLoginHistory() {
|
|
||||||
return axios.get<LoginHistoryQueryResponse[]>('/infra/operator-log/current-login-history');
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -91,20 +91,6 @@ export function resetUserPassword(request: UserUpdateRequest) {
|
|||||||
return axios.put('/infra/system-user/reset-password', request);
|
return axios.put('/infra/system-user/reset-password', request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询当前用户
|
|
||||||
*/
|
|
||||||
export function getCurrentUser() {
|
|
||||||
return axios.get<UserQueryResponse>('/infra/system-user/get-current');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新当前用户
|
|
||||||
*/
|
|
||||||
export function updateCurrentUser(request: UserUpdateRequest) {
|
|
||||||
return axios.put('/infra/system-user/update-current', request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过 id 查询用户
|
* 通过 id 查询用户
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -40,13 +40,13 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { UserUpdatePasswordRequest } from '@/api/user/auth';
|
import type { UserUpdatePasswordRequest } from '@/api/user/mine';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import useLoading from '@/hooks/loading';
|
import useLoading from '@/hooks/loading';
|
||||||
import useVisible from '@/hooks/visible';
|
import useVisible from '@/hooks/visible';
|
||||||
import { Message } from '@arco-design/web-vue';
|
import { Message } from '@arco-design/web-vue';
|
||||||
import { md5 } from '@/utils';
|
import { md5 } from '@/utils';
|
||||||
import { updatePassword } from '@/api/user/auth';
|
import { updateCurrentUserPassword } from '@/api/user/mine';
|
||||||
|
|
||||||
const emits = defineEmits(['updated']);
|
const emits = defineEmits(['updated']);
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// 修改
|
// 修改
|
||||||
await updatePassword({
|
await updateCurrentUserPassword({
|
||||||
beforePassword: md5(formModel.value.beforePassword as string),
|
beforePassword: md5(formModel.value.beforePassword as string),
|
||||||
password: md5(formModel.value.password as string)
|
password: md5(formModel.value.password as string)
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
import { ref, onMounted } from 'vue';
|
import { ref, onMounted } from 'vue';
|
||||||
import { useUserStore } from '@/store';
|
import { useUserStore } from '@/store';
|
||||||
import { ResultStatus } from '../types/const';
|
import { ResultStatus } from '../types/const';
|
||||||
import { getCurrentLoginHistory } from '@/api/user/operator-log';
|
import { getCurrentLoginHistory } from '@/api/user/mine';
|
||||||
import { dateFormat } from '@/utils';
|
import { dateFormat } from '@/utils';
|
||||||
|
|
||||||
const list = ref<LoginHistoryQueryResponse[]>([]);
|
const list = ref<LoginHistoryQueryResponse[]>([]);
|
||||||
|
|||||||
@@ -53,8 +53,9 @@
|
|||||||
import { computed, ref, onMounted } from 'vue';
|
import { computed, ref, onMounted } from 'vue';
|
||||||
import formRules from '../../user/types/form.rules';
|
import formRules from '../../user/types/form.rules';
|
||||||
import { useUserStore } from '@/store';
|
import { useUserStore } from '@/store';
|
||||||
import { getCurrentUser, updateCurrentUser } from '@/api/user/user';
|
import { getCurrentUser, updateCurrentUser } from '@/api/user/mine';
|
||||||
import { pick } from 'lodash';
|
import { pick } from 'lodash';
|
||||||
|
import { Message } from '@arco-design/web-vue';
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const { loading, setLoading } = useLoading();
|
const { loading, setLoading } = useLoading();
|
||||||
@@ -71,6 +72,7 @@
|
|||||||
try {
|
try {
|
||||||
await updateCurrentUser(formModel.value);
|
await updateCurrentUser(formModel.value);
|
||||||
userStore.nickname = formModel.value.nickname;
|
userStore.nickname = formModel.value.nickname;
|
||||||
|
Message.success('保存成功');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -82,7 +84,7 @@
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const { data } = await getCurrentUser();
|
const { data } = await getCurrentUser();
|
||||||
formModel.value = pick(data, 'id', 'username', 'nickname', 'mobile', 'email');
|
formModel.value = pick(data, 'username', 'nickname', 'mobile', 'email');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user