revert: UserPassword (#13680)

This commit is contained in:
Alex van Andel authored and GitHub committed 2024-02-14 12:36:29 +00:00
1 parent bb9f8e5d38
commit 0a68c6d048
25 files changed
+89 -190

No files matched your search

@@ -43,11 +43,11 @@ export const deleteMeHandler = async ({ ctx, input }: DeleteMeOptions) => {
throw new HttpError({ statusCode: 400, message: ErrorCode.ThirdPartyIdentityProviderEnabled });
}
if (!user.password?.hash) {
if (!user.password) {
throw new HttpError({ statusCode: 400, message: ErrorCode.UserMissingPassword });
}
const isCorrectPassword = await verifyPassword(input.password, user.password.hash);
const isCorrectPassword = await verifyPassword(input.password, user.password);
if (!isCorrectPassword) {
throw new HttpError({ statusCode: 403, message: ErrorCode.IncorrectPassword });
}
@@ -25,11 +25,16 @@ export const changePasswordHandler = async ({ input, ctx }: ChangePasswordOption
throw new TRPCError({ code: "FORBIDDEN", message: "THIRD_PARTY_IDENTITY_PROVIDER_ENABLED" });
}
const currentPasswordQuery = await prisma.userPassword.findFirst({
where: { userId: user.id },
const currentPasswordQuery = await prisma.user.findFirst({
where: {
id: user.id,
},
select: {
password: true,
},
});
const currentPassword = currentPasswordQuery?.hash;
const currentPassword = currentPasswordQuery?.password;
if (!currentPassword) {
throw new TRPCError({ code: "NOT_FOUND", message: "MISSING_PASSWORD" });
@@ -49,12 +54,12 @@ export const changePasswordHandler = async ({ input, ctx }: ChangePasswordOption
}
const hashedPassword = await hashPassword(newPassword);
await prisma.userPassword.update({
await prisma.user.update({
where: {
userId: user.id,
id: user.id,
},
data: {
hash: hashedPassword,
password: hashedPassword,
},
});
};
@@ -14,17 +14,17 @@ type VerifyPasswordOptions = {
};
export const verifyPasswordHandler = async ({ input, ctx }: VerifyPasswordOptions) => {
const userPassword = await prisma.userPassword.findUnique({
const user = await prisma.user.findUnique({
where: {
userId: ctx.user.id,
id: ctx.user.id,
},
});
if (!userPassword?.hash) {
if (!user?.password) {
throw new TRPCError({ code: "INTERNAL_SERVER_ERROR" });
}
const passwordsMatch = await verifyPassword(input.passwordInput, userPassword.hash);
const passwordsMatch = await verifyPassword(input.passwordInput, user.password);
if (!passwordsMatch) {
throw new TRPCError({ code: "UNAUTHORIZED" });
@@ -119,7 +119,7 @@ export const createHandler = async ({ input, ctx }: CreateOptions) => {
username: slugify(adminUsername),
email: adminEmail,
emailVerified: new Date(),
password: { create: { hash: hashedPassword } },
password: hashedPassword,
organizationId: organization.id,
// Default schedule
schedules: {
@@ -30,13 +30,12 @@ export const setPasswordHandler = async ({ ctx, input }: UpdateOptions) => {
});
if (!user) throw new TRPCError({ code: "BAD_REQUEST", message: "User not found" });
if (!user.password?.hash)
throw new TRPCError({ code: "BAD_REQUEST", message: "Password not set by default" });
if (!user.password) throw new TRPCError({ code: "BAD_REQUEST", message: "Password not set by default" });
const generatedPassword = createHash("md5")
.update(`${user?.email ?? ""}${process.env.CALENDSO_ENCRYPTION_KEY}`)
.digest("hex");
const isCorrectPassword = await verifyPassword(generatedPassword, user.password.hash);
const isCorrectPassword = await verifyPassword(generatedPassword, user?.password);
if (!isCorrectPassword)
throw new TRPCError({
@@ -45,12 +44,12 @@ export const setPasswordHandler = async ({ ctx, input }: UpdateOptions) => {
});
const hashedPassword = await hashPassword(newPassword);
await prisma.userPassword.update({
await prisma.user.update({
where: {
userId: ctx.user.id,
id: ctx.user.id,
},
data: {
hash: hashedPassword,
password: hashedPassword,
},
});
@@ -13,7 +13,7 @@ import { UserRepository } from "@calcom/lib/server/repository/user";
import slugify from "@calcom/lib/slugify";
import { prisma } from "@calcom/prisma";
import type { Membership, Team } from "@calcom/prisma/client";
import { Prisma, type User as UserType, type UserPassword } from "@calcom/prisma/client";
import { Prisma, type User as UserType } from "@calcom/prisma/client";
import type { Profile as ProfileType } from "@calcom/prisma/client";
import { MembershipRole } from "@calcom/prisma/enums";
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
@@ -27,13 +27,12 @@ import type { InviteMemberOptions, TeamWithParent } from "./types";
const log = logger.getSubLogger({ prefix: ["inviteMember.utils"] });
export type Invitee = Pick<
UserType,
"id" | "email" | "username" | "identityProvider" | "completedOnboarding"
"id" | "email" | "username" | "password" | "identityProvider" | "completedOnboarding"
>;
export type UserWithMembership = Invitee & {
teams?: Pick<Membership, "userId" | "teamId" | "accepted" | "role">[];
profiles: ProfileType[];
password: UserPassword | null;
};
export async function checkPermissions({
@@ -571,7 +570,7 @@ export const sendExistingUserTeamInviteEmails = async ({
* Here we want to redirect to a different place if onboarding has been completed or not. This prevents the flash of going to teams -> Then to onboarding - also show a different email template.
* This only changes if the user is a CAL user and has not completed onboarding and has no password
*/
if (!user.completedOnboarding && !user.password?.hash && user.identityProvider === "CAL") {
if (!user.completedOnboarding && !user.password && user.identityProvider === "CAL") {
const token = randomBytes(32).toString("hex");
await prisma.verificationToken.create({
data: {
@@ -73,6 +73,7 @@ export const removeMemberHandler = async ({ ctx, input }: RemoveMemberOptions) =
id: true,
movedToProfileId: true,
email: true,
password: true,
username: true,
completedOnboarding: true,
},