Merge branch 'main' into feature/zoom-integration
This commit is contained in:
commit
7ecb7f22e3
8 files changed
+325
-99
No files matched your search
+59
-43
@@ -2,55 +2,71 @@ import prisma from '../../../lib/prisma';
|
||||
import { hashPassword } from "../../../lib/auth";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
if (req.method !== 'POST') {
|
||||
return;
|
||||
}
|
||||
if (req.method !== 'POST') {
|
||||
return;
|
||||
}
|
||||
|
||||
const data = req.body;
|
||||
const { username, email, password } = data;
|
||||
const data = req.body;
|
||||
const { username, email, password } = data;
|
||||
|
||||
if (!username) {
|
||||
res.status(422).json({message: 'Invalid username'});
|
||||
return;
|
||||
}
|
||||
if (!username) {
|
||||
res.status(422).json({message: 'Invalid username'});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!email || !email.includes('@')) {
|
||||
res.status(422).json({message: 'Invalid email'});
|
||||
return;
|
||||
}
|
||||
if (!email || !email.includes('@')) {
|
||||
res.status(422).json({message: 'Invalid email'});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!password || password.trim().length < 7) {
|
||||
res.status(422).json({message: 'Invalid input - password should be at least 7 characters long.'});
|
||||
return;
|
||||
}
|
||||
if (!password || password.trim().length < 7) {
|
||||
res.status(422).json({message: 'Invalid input - password should be at least 7 characters long.'});
|
||||
return;
|
||||
}
|
||||
|
||||
const existingUser = await prisma.user.findFirst({
|
||||
where: {
|
||||
OR: [
|
||||
{
|
||||
username: username
|
||||
},
|
||||
{
|
||||
email: email
|
||||
}
|
||||
]
|
||||
const existingUser = await prisma.user.findFirst({
|
||||
where: {
|
||||
OR: [
|
||||
{
|
||||
username: username
|
||||
},
|
||||
{
|
||||
email: email
|
||||
}
|
||||
});
|
||||
|
||||
if (existingUser) {
|
||||
res.status(422).json({message: 'A user exists with that username or email address'});
|
||||
return;
|
||||
}
|
||||
|
||||
const hashedPassword = await hashPassword(password);
|
||||
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
username,
|
||||
email,
|
||||
password: hashedPassword
|
||||
],
|
||||
AND: [
|
||||
{
|
||||
emailVerified: {
|
||||
not: null,
|
||||
},
|
||||
}
|
||||
});
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
res.status(201).json({message: 'Created user'});
|
||||
if (existingUser) {
|
||||
let message: string = (
|
||||
existingUser.email !== email
|
||||
) ? 'Username already taken' : 'Email address is already registered';
|
||||
|
||||
return res.status(409).json({message});
|
||||
}
|
||||
|
||||
const hashedPassword = await hashPassword(password);
|
||||
|
||||
const user = await prisma.user.upsert({
|
||||
where: { email, },
|
||||
update: {
|
||||
username,
|
||||
password: hashedPassword,
|
||||
emailVerified: new Date(Date.now()),
|
||||
},
|
||||
create: {
|
||||
username,
|
||||
email,
|
||||
password: hashedPassword,
|
||||
}
|
||||
});
|
||||
|
||||
res.status(201).json({message: 'Created user'});
|
||||
}
|
||||
@@ -56,7 +56,18 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
title: req.body.eventName + ' with ' + req.body.name,
|
||||
};
|
||||
|
||||
const hashUID = translator.fromUUID(uuidv5(JSON.stringify(evt), uuidv5.URL));
|
||||
const hashUID: string = translator.fromUUID(uuidv5(JSON.stringify(evt), uuidv5.URL));
|
||||
const cancelLink: string = process.env.BASE_URL + '/cancel/' + hashUID;
|
||||
const rescheduleLink:string = process.env.BASE_URL + '/reschedule/' + hashUID;
|
||||
const appendLinksToEvents = (event: CalendarEvent) => {
|
||||
const eventCopy = {...event};
|
||||
eventCopy.description += "\n\n"
|
||||
+ "Need to change this event?\n"
|
||||
+ "Cancel: " + cancelLink + "\n"
|
||||
+ "Reschedule:" + rescheduleLink;
|
||||
|
||||
return eventCopy;
|
||||
}
|
||||
|
||||
const eventType = await prisma.eventType.findFirst({
|
||||
where: {
|
||||
@@ -92,7 +103,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
// Use all integrations
|
||||
results = await async.mapLimit(calendarCredentials, 5, async (credential) => {
|
||||
const bookingRefUid = booking.references.filter((ref) => ref.type === credential.type)[0].uid;
|
||||
return await updateEvent(credential, bookingRefUid, evt)
|
||||
return await updateEvent(credential, bookingRefUid, appendLinksToEvents(evt))
|
||||
});
|
||||
|
||||
//TODO: Reschedule with videoCredentials as well
|
||||
@@ -125,7 +136,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
} else {
|
||||
// Schedule event
|
||||
results.concat(await async.mapLimit(calendarCredentials, 5, async (credential) => {
|
||||
const response = await createEvent(credential, evt);
|
||||
const response = await createEvent(credential, appendLinksToEvents(evt));
|
||||
return {
|
||||
type: credential.type,
|
||||
response
|
||||
@@ -171,7 +182,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
// If one of the integrations allows email confirmations or no integrations are added, send it.
|
||||
if (currentUser.credentials.length === 0 || !results.every((result) => result.disableConfirmationEmail)) {
|
||||
await createConfirmBookedEmail(
|
||||
evt, hashUID
|
||||
evt, cancelLink, rescheduleLink
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import prisma from '../../../../lib/prisma';
|
||||
import createInvitationEmail from "../../../../lib/emails/invitation";
|
||||
import {getSession} from "next-auth/client";
|
||||
import {randomBytes} from "crypto";
|
||||
import {create} from "domain";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
@@ -34,8 +36,48 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
});
|
||||
|
||||
if (!invitee) {
|
||||
return res.status(400).json({
|
||||
message: `Invite failed because there is no corresponding user for ${req.body.usernameOrEmail}`});
|
||||
// liberal email match
|
||||
const isEmail = (str: string) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(str);
|
||||
|
||||
if (!isEmail(req.body.usernameOrEmail)) {
|
||||
return res.status(400).json({
|
||||
message: `Invite failed because there is no corresponding user for ${req.body.usernameOrEmail}`
|
||||
});
|
||||
}
|
||||
// valid email given, create User
|
||||
const createUser = await prisma.user.create(
|
||||
{
|
||||
data: {
|
||||
email: req.body.usernameOrEmail,
|
||||
}
|
||||
})
|
||||
.then( (invitee) => prisma.membership.create(
|
||||
{
|
||||
data: {
|
||||
teamId: parseInt(req.query.team),
|
||||
userId: invitee.id,
|
||||
role: req.body.role,
|
||||
},
|
||||
}));
|
||||
|
||||
const token: string = randomBytes(32).toString("hex");
|
||||
|
||||
const createVerificationRequest = await prisma.verificationRequest.create({
|
||||
data: {
|
||||
identifier: req.body.usernameOrEmail,
|
||||
token,
|
||||
expires: new Date((new Date()).setHours(168)) // +1 week
|
||||
}
|
||||
});
|
||||
|
||||
createInvitationEmail({
|
||||
toEmail: req.body.usernameOrEmail,
|
||||
from: session.user.name,
|
||||
teamName: team.name,
|
||||
token,
|
||||
});
|
||||
|
||||
return res.status(201).json({});
|
||||
}
|
||||
|
||||
// create provisional membership
|
||||
|
||||
Reference in new issue
Block a user