Squashed commit of the following:
commit 4862fd8467d529c54d0aa3e6abff15a574459a8b
Author: Shun Sakai <sorairolake@protonmail.ch>
Date: Wed Oct 23 20:44:30 2024 +0900
chore(backend): Update `argon2` package
commit a52eff5deaee39c0a70c83da49ca58d0eab8d513
Author: NoriDev <m1nthing2322@gmail.com>
Date: Mon Oct 7 18:11:34 2024 +0900
Revert "tweak 0dc322b6 (1673beta/cherrypick#88)"
This reverts commit ab6a5d0c3dbe7146de19d72d08658b1c011fe30a.
commit be51daec8a916a2668ea5794e067bde06499e1a4
Author: Mar0xy <marie@kaifa.ch>
Date: Wed Sep 27 21:46:56 2023 +0200
upd: rehash misskey passwords with argon2 on login
commit 67b124b7e6e8f1b1d1738ea9a123ab0500876d58
Author: Mar0xy <marie@kaifa.ch>
Date: Fri Sep 22 00:21:57 2023 +0200
upd: swap bcrypt to argon2
78 lines
2 KiB
TypeScript
78 lines
2 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
import type { UserSecurityKeysRepository } from '@/models/_.js';
|
|
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
|
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
|
import { DI } from '@/di-symbols.js';
|
|
import { ApiError } from '../../../error.js';
|
|
|
|
export const meta = {
|
|
requireCredential: true,
|
|
|
|
secure: true,
|
|
|
|
errors: {
|
|
noSuchKey: {
|
|
message: 'No such key.',
|
|
code: 'NO_SUCH_KEY',
|
|
id: 'f9c5467f-d492-4d3c-9a8g-a70dacc86512',
|
|
},
|
|
|
|
accessDenied: {
|
|
message: 'You do not have edit privilege of this key.',
|
|
code: 'ACCESS_DENIED',
|
|
id: '1fb7cb09-d46a-4fff-b8df-057708cce513',
|
|
},
|
|
},
|
|
} as const;
|
|
|
|
export const paramDef = {
|
|
type: 'object',
|
|
properties: {
|
|
name: { type: 'string', minLength: 1, maxLength: 30 },
|
|
credentialId: { type: 'string' },
|
|
},
|
|
required: ['name', 'credentialId'],
|
|
} as const;
|
|
|
|
@Injectable()
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
|
constructor(
|
|
@Inject(DI.userSecurityKeysRepository)
|
|
private userSecurityKeysRepository: UserSecurityKeysRepository,
|
|
|
|
private userEntityService: UserEntityService,
|
|
private globalEventService: GlobalEventService,
|
|
) {
|
|
super(meta, paramDef, async (ps, me) => {
|
|
const key = await this.userSecurityKeysRepository.findOneBy({
|
|
id: ps.credentialId,
|
|
});
|
|
|
|
if (key == null) {
|
|
throw new ApiError(meta.errors.noSuchKey);
|
|
}
|
|
|
|
if (key.userId !== me.id) {
|
|
throw new ApiError(meta.errors.accessDenied);
|
|
}
|
|
|
|
await this.userSecurityKeysRepository.update(key.id, {
|
|
name: ps.name,
|
|
});
|
|
|
|
// Publish meUpdated event
|
|
this.globalEventService.publishMainStream(me.id, 'meUpdated', await this.userEntityService.pack(me.id, me, {
|
|
schema: 'MeDetailed',
|
|
includeSecrets: true,
|
|
}));
|
|
|
|
return {};
|
|
});
|
|
}
|
|
}
|