1- const express = require ( ' express' )
2- const cors = require ( ' cors' )
3- const bodyParser = require ( ' body-parser' )
1+ const express = require ( " express" ) ;
2+ const cors = require ( " cors" ) ;
3+ const bodyParser = require ( " body-parser" ) ;
44const app = express ( ) ;
5+ require ( "dotenv" ) . config ( ) ;
56
67// user verification
7- const verifyToken = require ( ' ./ValidateUser/validateuser' )
8+ const verifyToken = require ( " ./ValidateUser/validateuser" ) ;
89
910// google photos
10- const { getAlbum } = require ( ' ./GooglePhotos/googlePhotos' )
11+ const { getAlbum } = require ( " ./GooglePhotos/googlePhotos" ) ;
1112
1213// mail
13- const transporter = require ( ' ./Mailer/transporter' )
14- const sendEmail = require ( ' ./Mailer/mail' )
14+ const transporter = require ( " ./Mailer/transporter" ) ;
15+ const sendEmail = require ( " ./Mailer/mail" ) ;
1516
1617// constants
17- const { EMAIL , EMAILTO , ALBUMID } = require ( ' ./constants' )
18+ const { EMAIL , EMAILTO , ALBUMID } = require ( " ./constants" ) ;
1819
1920// middlewares
2021app . use ( bodyParser . urlencoded ( { extended : true } ) ) ;
21- app . use ( bodyParser . json ( ) )
22- app . use ( cors ( ) )
22+ app . use ( bodyParser . json ( ) ) ;
23+ app . use ( cors ( ) ) ;
2324
2425app . use ( express . static ( "public" ) ) ;
2526
2627/**
2728 * To change email id (to be used for sending emails)
28- *
29+ *
2930 * 1. Go to account setting of your GMAIL account.
3031 * 2. Then go to 'allow less secure apps..'.
3132 * 3. Generate a new password and use that here to allow nodemailer to logging in your gmail account, skipping 2 step verification step.
32- *
33+ *
3334 * Reference:
3435 * https://stackoverflow.com/questions/26196467/sending-email-via-node-js-using-nodemailer-is-not-working
35- *
36+ *
3637 */
3738
38-
3939/**
4040 * this endpoint is for sending user's credentials when a new account is created from admin panel.
4141 */
4242
43- app . post ( "/sendMail" , verifyToken , async ( req , res , next ) => {
44-
45- let mailOptions = {
46- from : EMAIL ,
47- to : req . body . email || EMAIL ,
48- subject : 'Technocrats Member Profile Credentials' ,
49- html : `
43+ app . post ( "/sendMail" , verifyToken , async ( req , res , next ) => {
44+ let mailOptions = {
45+ from : EMAIL ,
46+ to : req . body . email || EMAIL ,
47+ subject : "Technocrats Member Profile Credentials" ,
48+ html : `
5049 <h1>Welcome to Technocrats Robotics</h1>
5150 <p>Click on the <strong>Member Login</strong> button at the bottom footer of the web app.</p>
5251 <p><span style="color: #0000ff;">Following are your credentials to customize your profile on the web app:<br /> <span style="color: #ff0000;"><strong>Username:</strong> ${ req . body . data . username } </span><br /><span style="color: #ff0000;"><strong>Password:</strong> ${ req . body . data . password } <br /></span>Whosoever holds these credentials, if he be worthy, shall possess the power of a Member.</span></p>
@@ -55,73 +54,70 @@ app.post("/sendMail", verifyToken ,async (req, res, next) => {
5554 <blockquote>
5655 <p><strong>This is only a foretaste of what is to come, and only the shadow of what is going to be. <em>~ Alan Turing</em></strong></p>
5756 </blockquote>
58- `
59- } ;
60-
61- let response = await sendEmail ( transporter , mailOptions , next )
57+ ` ,
58+ } ;
6259
63- if ( response )
64- res . status ( 200 ) . send ( { message : "Sent" } ) ;
65- } )
60+ let response = await sendEmail ( transporter , mailOptions , next ) ;
6661
62+ if ( response ) res . status ( 200 ) . send ( { message : "Sent" } ) ;
63+ } ) ;
6764
6865/**
69- * endpoint to send feedback submitted by user in Contact Us form to TCR's official mail id
66+ * endpoint to send feedback submitted by user in Contact Us form to TCR's official mail id
7067 */
71- app . post ( "/sendFeedback" , verifyToken , async ( req , res , next ) => {
72-
73- let mailOptions = {
74- from : EMAIL ,
75- to : EMAILTO ,
76- subject : 'Got a Feedback !!' ,
77- html : `
68+ app . post ( "/sendFeedback" , verifyToken , async ( req , res , next ) => {
69+ let mailOptions = {
70+ from : EMAIL ,
71+ to : EMAILTO ,
72+ subject : "Got a Feedback !!" ,
73+ html : `
7874 <h1><u>Feedback</u></h1>
7975 <p><b><u>Name:</u></b> ${ req . body . data . name } </p>
8076 <p><b><u>Email:</u></b> ${ req . body . data . email } </p>
8177 <p><b><u>Contact:</u></b> ${ req . body . data . contact } </p>
8278 <p><b><u>Message:</u></b> ${ req . body . data . message } </p>
83- `
84- } ;
85-
86- const response = await sendEmail ( transporter , mailOptions , next )
79+ ` ,
80+ } ;
8781
88- if ( response )
89- res . status ( 200 ) . send ( { message : "Sent" } ) ;
90- } )
82+ try {
83+ const response = await sendEmail ( transporter , mailOptions , next ) ;
9184
85+ if ( response ) res . status ( 200 ) . send ( { message : "Sent" } ) ;
86+ } catch ( err ) {
87+ next ( err ) ;
88+ }
89+ } ) ;
9290
9391/**
9492 * get the album id from google photos and pass it in the function getAlbum(<id>)
95- *
93+ *
9694 */
9795
98- app . get ( "/gallery" , verifyToken , async ( req , res , next ) => {
99- const result = await getAlbum ( ALBUMID )
100- res . json ( result )
101- } )
96+ app . get ( "/gallery" , verifyToken , async ( req , res , next ) => {
97+ const result = await getAlbum ( ALBUMID ) ;
98+ res . json ( result ) ;
99+ } ) ;
102100
103101/*
104102 * information
105103 */
106104app . get ( "/" , ( req , res , next ) => {
107- res . sendFile ( __dirname + "/" + "Information/information.html" )
108- } )
105+ res . sendFile ( __dirname + "/" + "Information/information.html" ) ;
106+ } ) ;
109107
110108// error handler
111109app . use ( ( err , req , res , next ) => {
112- res . status ( err . status || 500 )
113- res . send ( {
114- error : {
115- status : err . status || 500 ,
116- message : err . message
117- }
118- } )
119- } )
120-
110+ res . status ( err . status || 500 ) ;
111+ res . send ( {
112+ error : {
113+ status : err . status || 500 ,
114+ message : err . message ,
115+ } ,
116+ } ) ;
117+ } ) ;
121118
122119var port = process . env . PORT || 5000 ;
123120
124-
125121app . listen ( port , function ( ) {
126- console . log ( ' Express server listening on port ' + port ) ;
122+ console . log ( " Express server listening on port " + port ) ;
127123} ) ;
0 commit comments