40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
import { publishMainStream } from "../../../../../services/stream.js";
|
|
import define from "../../../define.js";
|
|
import { Users, UserProfiles } from "../../../../../models/index.js";
|
|
import { comparePassword } from "../../../../../misc/password.js";
|
|
export const meta = {
|
|
requireCredential: true,
|
|
secure: true
|
|
};
|
|
export const paramDef = {
|
|
type: "object",
|
|
properties: {
|
|
password: {
|
|
type: "string"
|
|
}
|
|
},
|
|
required: [
|
|
"password"
|
|
]
|
|
};
|
|
export default define(meta, paramDef, async (ps, user)=>{
|
|
const profile = await UserProfiles.findOneByOrFail({
|
|
userId: user.id
|
|
});
|
|
// Compare password
|
|
const same = await comparePassword(ps.password, profile.password);
|
|
if (!same) {
|
|
throw new Error("incorrect password");
|
|
}
|
|
await UserProfiles.update(user.id, {
|
|
twoFactorSecret: null,
|
|
twoFactorEnabled: false,
|
|
usePasswordLessLogin: false
|
|
});
|
|
const iObj = await Users.pack(user.id, user, {
|
|
detail: true,
|
|
includeSecrets: true
|
|
});
|
|
publishMainStream(user.id, "meUpdated", iObj);
|
|
});
|