|
|
|
@@ -1,7 +1,9 @@ |
|
|
|
import express from 'express'; |
|
|
|
import express, { response } from 'express'; |
|
|
|
import { DB_NAME, getDatabaseClient } from '../db-utils'; |
|
|
|
import bcrypt from 'bcrypt'; |
|
|
|
import { generateJWT, SALT_ROUNDS } from './auth'; |
|
|
|
import sendGridMail from '@sendgrid/mail'; |
|
|
|
import { MailDataRequired } from '@sendgrid/helpers/classes/mail'; |
|
|
|
|
|
|
|
const authRoutes = express.Router(); |
|
|
|
|
|
|
|
@@ -11,11 +13,11 @@ authRoutes.get('/users/', async (request, response) => { |
|
|
|
}); |
|
|
|
|
|
|
|
authRoutes.post('/register-applicant/', async (request, response) => { |
|
|
|
const name = request.body.name; |
|
|
|
const email = request.body.email; |
|
|
|
const password = request.body.password; |
|
|
|
const userType = 'APPLICANT'; |
|
|
|
const isVerified = false; |
|
|
|
const name: string = request.body.name; |
|
|
|
const email: string = request.body.email; |
|
|
|
const password: string = request.body.password; |
|
|
|
const userType: string = 'APPLICANT'; |
|
|
|
const isVerified: boolean = false; |
|
|
|
|
|
|
|
const userCollection = getDatabaseClient().db(DB_NAME).collection('users'); |
|
|
|
|
|
|
|
@@ -66,10 +68,58 @@ authRoutes.post('/register-applicant/', async (request, response) => { |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
authRoutes.post('/verify-user/', async (request, response) => { |
|
|
|
const email: string = request.body.email; |
|
|
|
|
|
|
|
if (!email) { |
|
|
|
response.status(400); |
|
|
|
response.send("Missing Email ID"); |
|
|
|
} |
|
|
|
|
|
|
|
const userCollection = getDatabaseClient().db(DB_NAME).collection('users'); |
|
|
|
|
|
|
|
let users = await userCollection.find({ |
|
|
|
email, |
|
|
|
}).toArray(); |
|
|
|
|
|
|
|
const matchedUser = users[0]; |
|
|
|
|
|
|
|
if (!matchedUser) { |
|
|
|
response.status(400); |
|
|
|
response.send('No user under this EmailID'); |
|
|
|
return; |
|
|
|
} else if (matchedUser.isVerified) { |
|
|
|
response.status(400); |
|
|
|
response.send('The user is already verified'); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
const otp = 1000 + Math.ceil(Math.random() * 8999); |
|
|
|
|
|
|
|
const otpMail: MailDataRequired = { |
|
|
|
to: email, |
|
|
|
from: 'kj@webtrigon.in', |
|
|
|
subject: 'Webtrigon Job-portal Sign Up Verification', |
|
|
|
text: `Please use the OTP ${otp} to verify your Email ID`, |
|
|
|
}; |
|
|
|
|
|
|
|
sendGridMail.send(otpMail).then(data=> { |
|
|
|
console.log(data); |
|
|
|
response.send('Verification OTP sent'); |
|
|
|
}, (err) => { |
|
|
|
console.log(err); |
|
|
|
response.sendStatus(500); |
|
|
|
response.send("SMTP system failure"); |
|
|
|
}); |
|
|
|
|
|
|
|
return; |
|
|
|
}); |
|
|
|
|
|
|
|
authRoutes.post('/api-auth/', async (request, response) => { |
|
|
|
const email = request.body.email; |
|
|
|
const password = request.body.password; |
|
|
|
const userType = request.body.userType; |
|
|
|
const email: string = request.body.email; |
|
|
|
const password: string = request.body.password; |
|
|
|
const userType: string = request.body.userType; |
|
|
|
|
|
|
|
if (!email || !password || !userType) { |
|
|
|
response.status(400); |
|
|
|
@@ -117,12 +167,6 @@ authRoutes.post('/api-auth/', async (request, response) => { |
|
|
|
} |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
// let passwordComparisonResult: boolean; |
|
|
|
|
|
|
|
// try { |
|
|
|
// passwordComparisonResult = await bcrypt.compare(password, user.password); |
|
|
|
// } |
|
|
|
}); |
|
|
|
|
|
|
|
export default authRoutes; |