mirror of
https://github.com/misskey-dev/misskey.git
synced 2025-02-24 07:45:26 +09:00

* chore: Add the SPDX information to each file Add copyright and licensing information as defined in version 3.0 of the REUSE Specification. * tweak format --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import bcrypt from 'bcryptjs';
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
import type { UsersRepository, UserProfilesRepository } from '@/models/index.js';
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
import { DeleteAccountService } from '@/core/DeleteAccountService.js';
|
|
import { DI } from '@/di-symbols.js';
|
|
|
|
export const meta = {
|
|
requireCredential: true,
|
|
|
|
secure: true,
|
|
} as const;
|
|
|
|
export const paramDef = {
|
|
type: 'object',
|
|
properties: {
|
|
password: { type: 'string' },
|
|
},
|
|
required: ['password'],
|
|
} as const;
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
@Injectable()
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
constructor(
|
|
@Inject(DI.usersRepository)
|
|
private usersRepository: UsersRepository,
|
|
|
|
@Inject(DI.userProfilesRepository)
|
|
private userProfilesRepository: UserProfilesRepository,
|
|
|
|
private deleteAccountService: DeleteAccountService,
|
|
) {
|
|
super(meta, paramDef, async (ps, me) => {
|
|
const profile = await this.userProfilesRepository.findOneByOrFail({ userId: me.id });
|
|
const userDetailed = await this.usersRepository.findOneByOrFail({ id: me.id });
|
|
if (userDetailed.isDeleted) {
|
|
return;
|
|
}
|
|
|
|
// Compare password
|
|
const same = await bcrypt.compare(ps.password, profile.password!);
|
|
|
|
if (!same) {
|
|
throw new Error('incorrect password');
|
|
}
|
|
|
|
await this.deleteAccountService.deleteAccount(me);
|
|
});
|
|
}
|
|
}
|