510de87607
* wip * wip * Update abuse-user-reports.ts * Update files.ts * Update list-remote.ts * Update list.ts * Update show-users.ts * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update update.ts * Update search.ts * Update reactions.ts * Update search.ts * wip * wip * wip * wip * Update update.ts * Update relation.ts * Update available.ts * wip * wip * wip * Update packages/backend/src/server/api/define.ts Co-authored-by: Johann150 <johann.galle@protonmail.com> * Update define.ts * Update define.ts * typo * wip * wip * wip * wip * wip * wip * wip * wip * Update update.ts * wip * Update signup.ts * Update call.ts * minimum for limit * type * remove needless annotation * wip * Update signup.ts * wip * wip * fix * Update create.ts Co-authored-by: Johann150 <johann.galle@protonmail.com>
45 lines
1 KiB
TypeScript
45 lines
1 KiB
TypeScript
import * as bcrypt from 'bcryptjs';
|
|
import { publishMainStream } from '@/services/stream';
|
|
import define from '../define';
|
|
import { Users, UserProfiles, PasswordResetRequests } from '@/models/index';
|
|
import { ApiError } from '../error';
|
|
|
|
export const meta = {
|
|
requireCredential: false,
|
|
|
|
errors: {
|
|
|
|
},
|
|
} as const;
|
|
|
|
const paramDef = {
|
|
type: 'object',
|
|
properties: {
|
|
token: { type: 'string' },
|
|
password: { type: 'string' },
|
|
},
|
|
required: ['token', 'password'],
|
|
} as const;
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
export default define(meta, paramDef, async (ps, user) => {
|
|
const req = await PasswordResetRequests.findOneOrFail({
|
|
token: ps.token,
|
|
});
|
|
|
|
// 発行してから30分以上経過していたら無効
|
|
if (Date.now() - req.createdAt.getTime() > 1000 * 60 * 30) {
|
|
throw new Error(); // TODO
|
|
}
|
|
|
|
// Generate hash of password
|
|
const salt = await bcrypt.genSalt(8);
|
|
const hash = await bcrypt.hash(ps.password, salt);
|
|
|
|
await UserProfiles.update(req.userId, {
|
|
password: hash,
|
|
});
|
|
|
|
PasswordResetRequests.delete(req.id);
|
|
});
|