From ab9cbdb6cb562068c6a783474640a6346a148a8a Mon Sep 17 00:00:00 2001 From: BuddyLongLegs Date: Thu, 24 Aug 2023 17:19:10 +0530 Subject: [PATCH] updated server url --- API_Endpoints.md | 10 +- controllers/auth.controller.js | 2 +- controllers/project.controller.js | 37 ++--- controllers/user.controller.js | 13 ++ templates/collaborator.handlebars | 219 ++++++++++++------------------ templates/verification.handlebars | 217 ++++++++++++----------------- utils/mailer.js | 10 +- 7 files changed, 209 insertions(+), 299 deletions(-) diff --git a/API_Endpoints.md b/API_Endpoints.md index a084bba..f7cb418 100644 --- a/API_Endpoints.md +++ b/API_Endpoints.md @@ -205,7 +205,7 @@ The following properties of every endpoint will be descibed in this file: "id": "Project Id" "name": "Project Name", "form_count": 5, - "allowed_origins": ["http://localhost", "https://savemyform.tk"], + "allowed_origins": ["http://localhost", "https://savemyform.in.net"], "date_created": "date-of-creation" } ] @@ -244,7 +244,7 @@ The following properties of every endpoint will be descibed in this file: "hasRecaptcha": true, "recaptchaKey": "User's project Recaptcha Key", "recaptchaSecret": "User's project Recaptcha Secret", - "allowedOrigins": ["http://localhost", "https://savemyform.tk"], + "allowedOrigins": ["http://localhost", "https://savemyform.in.net"], "collaborators": ["test1@test.com", "test2@test.com"], "recaptcha_token": "Google Recaptcha Token recieved from Google" } @@ -283,7 +283,7 @@ The following properties of every endpoint will be descibed in this file: "hasRecaptcha": true, "recaptchaKey": "User's project Recaptcha Key", "recaptchaSecret": "User's project Recaptcha Secret", - "allowedOrigins": ["http://localhost", "https://savemyform.tk"], + "allowedOrigins": ["http://localhost", "https://savemyform.in.net"], "form_count": 2, "forms":[ { @@ -309,7 +309,7 @@ The following properties of every endpoint will be descibed in this file: "hasRecaptcha": true, "recaptchaKey": "User's project Recaptcha Key", "recaptchaSecret": "User's project Recaptcha Secret", - "allowedOrigins": ["http://localhost", "https://savemyform.tk"], + "allowedOrigins": ["http://localhost", "https://savemyform.in.net"], "collaborators": ["test1@test.com", "test2@test.com"], "recaptcha_token": "Google Recaptcha Token recieved from Google", "password": "user's password" @@ -335,7 +335,7 @@ The following properties of every endpoint will be descibed in this file: "hasRecaptcha": true, "recaptchaKey": "User's project Recaptcha Key", "recaptchaSecret": "User's project Recaptcha Secret", - "allowedOrigins": ["http://localhost", "https://savemyform.tk"], + "allowedOrigins": ["http://localhost", "https://savemyform.in.net"], } ``` diff --git a/controllers/auth.controller.js b/controllers/auth.controller.js index 307fd79..1f799f6 100644 --- a/controllers/auth.controller.js +++ b/controllers/auth.controller.js @@ -14,7 +14,7 @@ const client = new OAuth2Client( process.env.GOOGLE_OAUTH_CLIENT_ID, process.env.GOOGLE_OAUTH_CLIENT_SECRET, process.env.ENV === 'prod' - ? 'https://savemyform.tk/signin/oauth' + ? 'https://savemyform.in.net/signin/oauth' : 'http://localhost:3000/signin/oauth', ); diff --git a/controllers/project.controller.js b/controllers/project.controller.js index f33de99..0bc09a7 100644 --- a/controllers/project.controller.js +++ b/controllers/project.controller.js @@ -124,30 +124,12 @@ export async function updateProject(req, res) { updatedProject.allowedOrigins = req.body.allowedOrigins; } - if (req.body.collaborators) { - if (req.body.collaborators.length > 5) { - return response_400( - res, - 'Number of collaborators cannot be greater than 5', - ); - } - inviteCollaborators( - req.body.collaborators, - projectId, - req.body.name, - req.user.name, - req.user.email, - ); - } - // updating the project details in DB const finalProject = await Project.findOneAndUpdate( { projectId: projectId }, updatedProject, { returnDocument: 'after', select: '-_id -forms' }, - ) - .populate({ path: 'owner', select: '-_id name email' }) - .populate({ path: 'collaborators', select: '-_id name email' }); + ).populate({ path: 'owner', select: '-_id name email' }); finalProject.is_owner = req.user.id === finalProject.owner; @@ -160,7 +142,10 @@ export async function updateProject(req, res) { export async function projectDashboard(req, res) { let project = await Project.findOne({ projectId: req.params.id }); if (!project) return response_400(res, 'No project with this id'); - let allow = project.collaborators.includes(req.user._id); + let allow = Collaborators.exists({ + email: req.user.email, + projectId: project._id, + }); if (!allow && String(project.owner) !== String(req.user._id)) return response_400(res, 'You cannot access this project'); @@ -168,7 +153,6 @@ export async function projectDashboard(req, res) { project = await Project.findOne({ projectId: req.params.id }) .populate('forms', 'formId name submission createdAt updatedAt -_id') .populate('owner', 'name email') - .populate('collaborators', 'name email -_id') .select('-_id -createdAt -updatedAt -__v'); project = project.toJSON(); project.is_owner = String(project.owner._id) === String(req.user._id); @@ -267,14 +251,13 @@ export async function updateCollaborator(req, res) { export async function updateCollaboratorStatus(req, res) { try { - if(req.body.userAccepted){ - let collaborator=await Collaborators.findById(req.body.collaboratorId); - collaborator.status='Accepted' + if (req.body.userAccepted) { + let collaborator = await Collaborators.findById(req.body.collaboratorId); + collaborator.status = 'Accepted'; collaborator.save(); - } - else{ + } else { await Collaborators.findByIdAndDelete(req.body.collaboratorId); - } + } } catch (error) { console.log(error); return response_500(res, 'Server error', error); diff --git a/controllers/user.controller.js b/controllers/user.controller.js index 7e1c4d2..18181b1 100644 --- a/controllers/user.controller.js +++ b/controllers/user.controller.js @@ -5,6 +5,7 @@ import { verifycaptcha } from '../utils/recaptcha.js'; import validator from 'validator'; import jwt from 'jsonwebtoken'; import User from '../models/user.model.js'; +import InvitedCollaborator from '../models/invitedCollaborators.model.js'; export function getVerificationLink(req, res) { if (req.user.verified) @@ -111,7 +112,19 @@ export async function dashboard(req, res) { options: { sort: { createdAt: -1 } }, select: 'projectId name forms allowedOrigins createdAt', }); + let collaboratedProjects = await InvitedCollaborator.find({ + status: 'Accepted', + email: req.user.email, + }) + .populate({ + path: 'projectId', + select: 'projectId name forms allowedOrigins createdAt', + }) + .toJSON(); user = await user.toJSON(); + collaboratedProjects.forEach((collabProjectObj) => { + user.projects.push(collabProjectObj.projectId); + }); user.project_count = user.projects.length; user.projects.map((project) => { project.date_created = project.createdAt; diff --git a/templates/collaborator.handlebars b/templates/collaborator.handlebars index 260bf90..bd7a281 100644 --- a/templates/collaborator.handlebars +++ b/templates/collaborator.handlebars @@ -1,170 +1,127 @@ - - + - - - + + + Verification of Email -
-
-
- +
+
+
+ + d='M73.5527 62.781H15.5968C6.75038 62.781 4.821 54.9048 4.96211 50.9667C5.96524 43.0259 14.0658 40.8125 17.9907 40.6983C17.5669 33.8839 24.3035 29.1225 27.7248 27.5936C41.4982 20.4456 51.2985 30.294 54.477 36.1117C67.9855 32.8236 71.8041 40.8085 72.0248 45.2119H73.5527C82.8936 45.3647 83.5305 52.9779 82.6814 56.7655C80.2188 61.7307 75.5695 62.8447 73.5527 62.781Z' + stroke='#12AB51' + stroke-width='8' + > - + d='M39.67 0.015625H61.8924C63.5511 0.385304 64.0784 1.54046 64.1346 2.07183V51.6406C64.0948 52.9798 62.9222 53.4655 62.3409 53.5409H25.8184C24.1841 52.8893 23.7755 52.0025 23.7755 51.6406V13.1368L39.67 0.015625Z' + fill='#116148' + > + + d='M39.563 11.1237V0.043457L23.7404 13.1732L37.4471 13.28C39.027 13.0067 39.516 11.7286 39.563 11.1237Z' + fill='#12AB51' + > + cx='45.1948' + cy='29.6' + rx='12.4494' + ry='11.3212' + fill='#FDFEFE' + > + d='M40.258 36.1168C39.7896 36.1168 39.3888 35.9521 39.0556 35.6228C38.7217 35.2929 38.5548 34.8966 38.5548 34.4337V31.9091H40.258V34.4337H50.4773V31.9091H52.1805V34.4337C52.1805 34.8966 52.0138 35.2929 51.6806 35.6228C51.3468 35.9521 50.9457 36.1168 50.4773 36.1168H40.258ZM45.3676 32.7507L41.1096 28.543L42.3019 27.3228L44.516 29.5108V22.6523H46.2192V29.5108L48.4334 27.3228L49.6257 28.543L45.3676 32.7507Z' + fill='#116148' + > - + - - - + in='SourceAlpha' + type='matrix' + values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0' + result='hardAlpha' + > + + + + type='matrix' + values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0' + > + mode='normal' + in2='BackgroundImageFix' + result='effect1_dropShadow_610_201' + > + mode='normal' + in='SourceGraphic' + in2='effect1_dropShadow_610_201' + result='shape' + >
-
Invitation to project {projectName}
-

+

Invitation to project {projectName}
+

You have been invited to the project{projectName} by - {userEmail}. + {userEmail}. Kindly click on the following link !

- - + + -

+

If this does not work, copy and paste the following link in your web browser.

-

- {{url}} +

+ {{url}}

- + \ No newline at end of file diff --git a/templates/verification.handlebars b/templates/verification.handlebars index ea5e51c..d6cbbbf 100644 --- a/templates/verification.handlebars +++ b/templates/verification.handlebars @@ -1,168 +1,129 @@ - - + - - - + + + Verification of Email -
-
-
- +
+
+
+ + d='M73.5527 62.781H15.5968C6.75038 62.781 4.821 54.9048 4.96211 50.9667C5.96524 43.0259 14.0658 40.8125 17.9907 40.6983C17.5669 33.8839 24.3035 29.1225 27.7248 27.5936C41.4982 20.4456 51.2985 30.294 54.477 36.1117C67.9855 32.8236 71.8041 40.8085 72.0248 45.2119H73.5527C82.8936 45.3647 83.5305 52.9779 82.6814 56.7655C80.2188 61.7307 75.5695 62.8447 73.5527 62.781Z' + stroke='#12AB51' + stroke-width='8' + > - + d='M39.67 0.015625H61.8924C63.5511 0.385304 64.0784 1.54046 64.1346 2.07183V51.6406C64.0948 52.9798 62.9222 53.4655 62.3409 53.5409H25.8184C24.1841 52.8893 23.7755 52.0025 23.7755 51.6406V13.1368L39.67 0.015625Z' + fill='#116148' + > + + d='M39.563 11.1237V0.043457L23.7404 13.1732L37.4471 13.28C39.027 13.0067 39.516 11.7286 39.563 11.1237Z' + fill='#12AB51' + > + cx='45.1948' + cy='29.6' + rx='12.4494' + ry='11.3212' + fill='#FDFEFE' + > + d='M40.258 36.1168C39.7896 36.1168 39.3888 35.9521 39.0556 35.6228C38.7217 35.2929 38.5548 34.8966 38.5548 34.4337V31.9091H40.258V34.4337H50.4773V31.9091H52.1805V34.4337C52.1805 34.8966 52.0138 35.2929 51.6806 35.6228C51.3468 35.9521 50.9457 36.1168 50.4773 36.1168H40.258ZM45.3676 32.7507L41.1096 28.543L42.3019 27.3228L44.516 29.5108V22.6523H46.2192V29.5108L48.4334 27.3228L49.6257 28.543L45.3676 32.7507Z' + fill='#116148' + > - + - - - + in='SourceAlpha' + type='matrix' + values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0' + result='hardAlpha' + > + + + + type='matrix' + values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0' + > + mode='normal' + in2='BackgroundImageFix' + result='effect1_dropShadow_610_201' + > + mode='normal' + in='SourceGraphic' + in2='effect1_dropShadow_610_201' + result='shape' + >
-
Verify Your Email Address
-

+

Verify Your Email Address
+

We need to verify your email address. Kindly click on the following link !

- - + + -

+

If this does not work, copy and paste the following link in your web browser.

-

- {{url}} +

+ {{url}}

-

- The verification request was generated on the ip address: {{ip}} +

+ The verification request was generated on the ip address: + {{ip}}

- + \ No newline at end of file diff --git a/utils/mailer.js b/utils/mailer.js index 2c542ae..cb96a21 100644 --- a/utils/mailer.js +++ b/utils/mailer.js @@ -13,7 +13,7 @@ let transporter = nodemailer.createTransport({ const BASE_URL = process.env.ENV === 'prod' - ? 'https://www.savemyform.tk' + ? 'https://www.savemyform.in.net' : 'http://localhost:3000'; export function mailer(subject, email, body, html) { @@ -64,11 +64,7 @@ export function sendVerificationLink(email, secret, ip) { }); } -export function sendCollabInvitationLink( - email, - secret, - projectName -) { +export function sendCollabInvitationLink(email, secret, projectName) { let link = BASE_URL + '/collab/' + secret; const handlebarOptions = { viewEngine: { @@ -86,7 +82,7 @@ export function sendCollabInvitationLink( context: { url: link, projectName, - userEmail:email + userEmail: email, }, }; transporter.sendMail(mailOptions, (err, info) => {