-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/aammya8/new account approval (#104)
* Add user approval and denial functionality, as well as email user about account approval updates * backup * backup * fixed delete route * change approve/deny/delete to use email * approve/deny controllers do not get entered? but delete does * Fix Notifications UI (immediately remove corresponding card when approve/deny button clicked) * Modify routes for testing purposes * Debug statements --> user does not get found in denyUser * Email successfully sent for deny (accidentally deleted user before trying to send email earlier lol) * Fix frontend (populate account type) * Remove extra comments * added auth protection and cleaned up code * added env for emails * fix user role bug * fixed some bugs and deleted some log statements * ran lint fix --------- Co-authored-by: adhi0331 <[email protected]>
- Loading branch information
Showing
14 changed files
with
399 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
import nodemailer from "nodemailer"; | ||
|
||
// Create a transporter object using SMTP transport | ||
const transporter = nodemailer.createTransport({ | ||
service: "Gmail", | ||
auth: { | ||
user: process.env.EMAIL_ADDRESS_1, | ||
pass: process.env.PASS_1, | ||
}, | ||
}); | ||
|
||
export const sendApprovalEmail = async (email: string) => { | ||
try { | ||
await transporter.sendMail({ | ||
from: process.env.EMAIL_ADDRESS_1, | ||
to: email, | ||
subject: "Welcome to PIA! Your Account Has Been Approved", | ||
// text: `Hello, | ||
// Thank you for your interest in Plant It Again. | ||
// We are emailing to let you know that your account | ||
// creation request has been approved.` | ||
html: `<p>Hello,</p> | ||
<p>Thank you for your interest in Plant It Again.</p> | ||
<p>We are emailing to let you know that your account creation request | ||
has been <strong>approved</strong>.</p>`, | ||
}); | ||
console.log("Approval email sent successfully"); | ||
} catch (error) { | ||
console.error("Error sending approval email:", error); | ||
} | ||
}; | ||
|
||
export const sendDenialEmail = async (email: string) => { | ||
console.log("Sending Denial Email"); | ||
try { | ||
await transporter.sendMail({ | ||
from: process.env.EMAIL_ADDRESS_1, | ||
to: email, | ||
subject: "An Update on Your PIA Account Approval Status", | ||
// text: `Hello, | ||
// Thank you for your interest in Plant It Again. | ||
// We are emailing to let you know that your account | ||
// creation request has been denied. | ||
// If you believe this a mistake, | ||
// please contact us through our website` | ||
html: `<p>Hello,</p> | ||
<p>Thank you for your interest in Plant It Again.</p> | ||
<p>We are emailing to let you know that your account creation request | ||
has been <strong>denied</strong>.</p> | ||
<p>If you believe this is a mistake, please contact us through our website.</p>`, | ||
}); | ||
console.log("Denial email sent successfully"); | ||
} catch (error) { | ||
console.error("Error sending denial email:", error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import UserModel from "../models/user"; | ||
|
||
import { firebaseAdminAuth } from "./firebase"; | ||
|
||
// delete user from Firebase | ||
export const deleteUserFromFirebase = async (userId: string): Promise<void> => { | ||
await firebaseAdminAuth.deleteUser(userId); | ||
}; | ||
|
||
// delete user from MongoDB | ||
export const deleteUserFromMongoDB = async (userId: string): Promise<void> => { | ||
await UserModel.findByIdAndDelete(userId); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.