Skip to content

Commit

Permalink
Add more academic mail,fix checkAcademic
Browse files Browse the repository at this point in the history
  • Loading branch information
tanish35 committed Oct 9, 2024
1 parent d997439 commit 85b19e4
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 51 deletions.
10 changes: 10 additions & 0 deletions backend/dist/controllers/postController.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ const fetchPosts = (0, express_async_handler_1.default)((req, res) => __awaiter(
name: true,
},
},
User: {
select: {
username: true,
},
},
},
take: postsPerPage,
skip: offset,
Expand Down Expand Up @@ -193,6 +198,11 @@ const fetchSinglePost = (0, express_async_handler_1.default)((req, res) => __awa
name: true,
},
},
User: {
select: {
username: true,
},
},
Comments: {
select: {
comment_id: true,
Expand Down
19 changes: 12 additions & 7 deletions backend/dist/controllers/userControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ const loginUser = (0, express_async_handler_1.default)((req, res) => __awaiter(v
res.status(401).json({ message: "Logged in with Google Or Github" });
return;
}
if (!user.emailVerified) {
res.status(401).json({ message: "Email not verified" });
return;
}
const match = yield bcrypt_1.default.compare(password, user.password);
if (!match) {
res.status(401).json({ message: "Invalid credentials" });
Expand Down Expand Up @@ -426,9 +430,7 @@ const addUsername = (0, express_async_handler_1.default)((req, res) => __awaiter
}
const response = yield prisma_1.default.user.findFirst({
where: {
OR: [
{ username: username },
]
OR: [{ username: username }],
},
});
if (response) {
Expand All @@ -453,9 +455,7 @@ const addDetailsToUser = (0, express_async_handler_1.default)((req, res) => __aw
}
const user = yield prisma_1.default.user.findFirst({
where: {
OR: [
{ username: username },
]
OR: [{ username: username }],
},
});
if (user) {
Expand Down Expand Up @@ -513,7 +513,12 @@ const addDetailsToUser = (0, express_async_handler_1.default)((req, res) => __aw
}));
exports.addDetailsToUser = addDetailsToUser;
const getAllUser = (0, express_async_handler_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () {
const users = yield prisma_1.default.user.findMany({});
const users = yield prisma_1.default.user.findMany({
select: {
user_id: true,
username: true,
},
});
res.status(200).json(users);
}));
exports.getAllUser = getAllUser;
8 changes: 4 additions & 4 deletions backend/dist/mail/checkAcademic.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
// Import the CommonJS module for __dirname and rename it
const currentDir = require("./dirNameHelper");
// Function to check if an email has a valid college domain
// Function to check if an email has a valid college domain blah blah
function checkCollegeEmail(email) {
const filePath = path_1.default.join(currentDir, "emails.json");
// Use process.cwd() to get the current directory
const filePath = path_1.default.join(process.cwd(), "/src/mail/emails.json");
// Read the domains from the JSON file
const domains = JSON.parse(fs_1.default.readFileSync(filePath, "utf8"));
// Extract the domain from the email
const emailDomain = email.split("@")[1];
Expand Down
2 changes: 0 additions & 2 deletions backend/dist/mail/dirNameHelper.js

This file was deleted.

8 changes: 0 additions & 8 deletions backend/dist/mail/emails.json

This file was deleted.

43 changes: 43 additions & 0 deletions backend/dist/mail/sort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.sortEmailDomains = sortEmailDomains;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
// Path to the emails.json file
const filePath = path_1.default.join(__dirname, "emails.json");
// Function to read, sort, and write the emails.json file
function sortEmailDomains() {
// Read the file
fs_1.default.readFile(filePath, "utf8", (err, data) => {
if (err) {
console.error("Error reading file:", err);
return;
}
// Parse the JSON data
let domains;
try {
domains = JSON.parse(data);
}
catch (err) {
console.error("Error parsing JSON:", err);
return;
}
// Sort the array in place
domains.sort();
// Convert the array back to JSON
const sortedData = JSON.stringify(domains, null, 2);
// Write the sorted array back to the file
fs_1.default.writeFile(filePath, sortedData, "utf8", (err) => {
if (err) {
console.error("Error writing file:", err);
return;
}
console.log("File sorted successfully.");
});
});
}
// Call the function to sort the email domains
sortEmailDomains();
57 changes: 43 additions & 14 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@
"nodemailer": "^6.9.14",
"nodemon": "^3.1.4",
"prettier": "^3.3.3",
"ts-node": "^10.9.2",
"tsc": "^2.0.4",
"ws": "^8.18.0"
},
"devDependencies": {
"@types/express": "^4.17.21",
"prisma": "^5.20.0",
"typescript": "^5.5.4"
"ts-node": "^10.9.2",
"typescript": "^5.6.3"
}
}
10 changes: 5 additions & 5 deletions backend/src/mail/checkAcademic.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import fs from "fs";
import path from "path";

// Import the CommonJS module for __dirname and rename it
const currentDir = require("./dirNameHelper");

// Function to check if an email has a valid college domain
// Function to check if an email has a valid college domain blah blah
function checkCollegeEmail(email: string): boolean {
const filePath = path.join(currentDir, "emails.json");
// Use process.cwd() to get the current directory
const filePath = path.join(process.cwd(), "/src/mail/emails.json");

// Read the domains from the JSON file
const domains: string[] = JSON.parse(fs.readFileSync(filePath, "utf8"));

// Extract the domain from the email
Expand Down
2 changes: 0 additions & 2 deletions backend/src/mail/dirNameHelper.js

This file was deleted.

Loading

0 comments on commit 85b19e4

Please sign in to comment.