mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
feat(core): delete user and update user password api (#248)
This commit is contained in:
parent
9c3f017704
commit
9e30b41028
1 changed files with 55 additions and 5 deletions
|
@ -10,6 +10,7 @@ import koaPagination from '@/middleware/koa-pagination';
|
|||
import { findRolesByRoleNames } from '@/queries/roles';
|
||||
import {
|
||||
clearUserCustomDataById,
|
||||
deleteUserById,
|
||||
findAllUsers,
|
||||
findTotalNumberOfUsers,
|
||||
findUserById,
|
||||
|
@ -39,7 +40,7 @@ export default function adminUserRoutes<T extends AuthedRouter>(router: T) {
|
|||
router.get(
|
||||
'/users/:userId',
|
||||
koaGuard({
|
||||
params: object({ userId: string().min(1) }),
|
||||
params: object({ userId: string() }),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
const {
|
||||
|
@ -97,7 +98,7 @@ export default function adminUserRoutes<T extends AuthedRouter>(router: T) {
|
|||
router.patch(
|
||||
'/users/:userId',
|
||||
koaGuard({
|
||||
params: object({ userId: string().min(1) }),
|
||||
params: object({ userId: string() }),
|
||||
body: object({
|
||||
name: string().min(3).optional(),
|
||||
avatar: string().url().optional(),
|
||||
|
@ -122,10 +123,59 @@ export default function adminUserRoutes<T extends AuthedRouter>(router: T) {
|
|||
}
|
||||
);
|
||||
|
||||
router.patch(
|
||||
'/users/:userId/password',
|
||||
koaGuard({
|
||||
params: object({ userId: string() }),
|
||||
body: object({ password: string().min(6) }),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
const {
|
||||
params: { userId },
|
||||
body: { password },
|
||||
} = ctx.guard;
|
||||
|
||||
await findUserById(userId);
|
||||
|
||||
const { passwordEncryptionSalt, passwordEncrypted, passwordEncryptionMethod } =
|
||||
encryptUserPassword(userId, password);
|
||||
|
||||
const user = await updateUserById(userId, {
|
||||
passwordEncrypted,
|
||||
passwordEncryptionMethod,
|
||||
passwordEncryptionSalt,
|
||||
});
|
||||
|
||||
ctx.body = pick(user, ...userInfoSelectFields);
|
||||
|
||||
return next();
|
||||
}
|
||||
);
|
||||
|
||||
router.delete(
|
||||
'/users/:userId',
|
||||
koaGuard({
|
||||
params: object({ userId: string() }),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
const {
|
||||
params: { userId },
|
||||
} = ctx.guard;
|
||||
|
||||
await findUserById(userId);
|
||||
|
||||
await deleteUserById(userId);
|
||||
|
||||
ctx.status = 204;
|
||||
|
||||
return next();
|
||||
}
|
||||
);
|
||||
|
||||
router.patch(
|
||||
'/users/:userId/roleNames',
|
||||
koaGuard({
|
||||
params: object({ userId: string().min(1) }),
|
||||
params: object({ userId: string() }),
|
||||
body: object({ roleNames: string().array() }),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
|
@ -159,7 +209,7 @@ export default function adminUserRoutes<T extends AuthedRouter>(router: T) {
|
|||
router.patch(
|
||||
'/users/:userId/custom-data',
|
||||
koaGuard({
|
||||
params: object({ userId: string().min(1) }),
|
||||
params: object({ userId: string() }),
|
||||
body: object({ customData: customDataGuard }),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
|
@ -183,7 +233,7 @@ export default function adminUserRoutes<T extends AuthedRouter>(router: T) {
|
|||
router.delete(
|
||||
'/users/:userId/custom-data',
|
||||
koaGuard({
|
||||
params: object({ userId: string().min(1) }),
|
||||
params: object({ userId: string() }),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
const {
|
||||
|
|
Loading…
Reference in a new issue