@@ -4,6 +4,9 @@ const garageService=require("../services/garage.service");
44const slotService = require ( "../services/slot.service" ) ;
55const jwt = require ( "jsonwebtoken" ) ;
66
7+ /* ------------ Configs ----------- */
8+
9+ // cookie options
710let options = {
811 path : "/" ,
912 sameSite : true ,
@@ -17,12 +20,21 @@ let options_otp = {
1720 maxAge : 1000 * 60 * 5 ,
1821 httpOnly : true ,
1922} ;
23+
24+ /* ------------ Controllers ----------- */
25+
26+
27+ //renderRegister... renders the register page
2028const renderRegister = ( req , res ) => {
2129 res . render ( "users/register" ) ;
2230} ;
31+
32+ //renderLogin... renders the login page
2333const renderLogin = ( req , res ) => {
2434 res . render ( "users/login" ) ;
2535} ;
36+
37+ //renderDashboard... renders the dashboard page
2638const renderDashboard = async ( req , res ) => {
2739 var bookings = await bookingService . FindByUser ( req . body . user_id ) ;
2840 for ( let booking of bookings ) {
@@ -35,9 +47,13 @@ const renderDashboard = async (req, res) => {
3547 }
3648 res . render ( "users/dashboard" , { body : req . body , bookings : bookings } ) ;
3749} ;
50+
51+ //renderAddMoney... renders the add money page
3852const renderAddMoney = ( req , res ) => {
3953 res . render ( "users/addmoney" , { money : req . body . money , body : req . body } ) ;
4054} ;
55+
56+ //renderVerify... renders the otp verify page
4157const renderVerify = async ( req , res ) => {
4258 if ( req . body . verified === true ) {
4359 res . send ( "Already Verified" ) ;
@@ -47,6 +63,8 @@ const renderVerify = async (req, res) => {
4763 res . render ( "users/verify" , { email : req . body . email } ) ;
4864 }
4965} ;
66+
67+ //renderRegister... renders the register page
5068const register = async ( req , res ) => {
5169 try {
5270 const result = await userService . Register ( req . body ) ;
@@ -59,6 +77,7 @@ const register = async (req, res) => {
5977 }
6078} ;
6179
80+ //sendOtp... sends otp to the user
6281const sendOtp = async ( username ) => {
6382 try {
6483 var gen_otp = await userService . generateOtp ( username ) ;
@@ -68,6 +87,7 @@ const sendOtp = async (username) => {
6887 }
6988} ;
7089
90+ // login... logs in the user
7191const login = async ( req , res ) => {
7292 try {
7393 const result = await userService . Login (
@@ -83,12 +103,14 @@ const login = async (req, res) => {
83103 }
84104} ;
85105
106+ // logout... logs out the user
86107const logout = ( req , res ) => {
87108 res . clearCookie ( "isloggedin" ) ;
88109 req . flash ( "success" , "Logged out Successfully." ) ;
89110 res . redirect ( "/" ) ;
90111} ;
91112
113+ //verify.. verifies the otp and logs in the user
92114const verify = async ( req , res ) => {
93115 var otp = req . body . otp ;
94116 let token = req . cookies [ "otp" ] ;
@@ -106,10 +128,12 @@ const verify = async (req, res) => {
106128 }
107129} ;
108130
131+ //renderImageChange... renders the upload image page
109132const renderImage = ( req , res ) => {
110133 res . render ( "users/uploadimage" , { body : req . body } ) ;
111134} ;
112135
136+ //upload Image... uploads the image
113137const uploadImage = async ( req , res ) => {
114138 var path = req . file [ "path" ] ;
115139 var userid = req . body . user_id ;
@@ -124,6 +148,7 @@ const uploadImage = async (req, res) => {
124148 }
125149} ;
126150
151+ //addMoney... adds money to the user
127152const addMoney = async ( req , res ) => {
128153 var add_money = req . body . added_money ;
129154 try {
@@ -136,6 +161,7 @@ const addMoney = async (req, res) => {
136161 }
137162} ;
138163
164+ //apiOtp... compares the given otp with the otp stored in cookie
139165const apiOtp = ( req , res ) => {
140166 var str = req . params . value ;
141167 let token = req . cookies [ "otp" ] ;
@@ -144,11 +170,13 @@ const apiOtp = (req, res) => {
144170 else res . send ( "0" ) ;
145171} ;
146172
173+ //resendOtp... resends the otp to the user
147174const resendOTP = ( req , res ) => {
148175 req . flash ( "alert" , "Your OTP has been resent successfully to your email." ) ;
149176 res . redirect ( "/users/verify" ) ;
150177} ;
151178
179+ //renderTransactions... renders the transactions page
152180const renderTransactions = async ( req , res ) => {
153181 var transactions = await userService . getTransactions ( req . body . user_id ) ;
154182 res . render ( "users/transactions" , {
@@ -157,6 +185,7 @@ const renderTransactions = async (req, res) => {
157185 } ) ;
158186} ;
159187
188+ //renderBookings... renders the booking page
160189const renderBookings = async ( req , res ) => {
161190 var bookings = await bookingService . FindByUser ( req . body . user_id ) ;
162191 for ( let booking of bookings ) {
@@ -170,6 +199,7 @@ const renderBookings = async (req, res) => {
170199 res . render ( "users/bookings" , { body : req . body , bookings : bookings } ) ;
171200} ;
172201
202+ //renderBooking... renders the booking details page
173203const renderBooking = async ( req , res ) =>
174204{
175205 var id = req . params . id ;
0 commit comments