chore: add otp based login
This commit is contained in:
+89
-12
@@ -1,7 +1,7 @@
|
||||
const {Router} = require('express')
|
||||
const router = Router()
|
||||
const userController = require('../controllers/userController');
|
||||
const electionController = require('../controllers/electionController');
|
||||
const { Router } = require("express");
|
||||
const router = Router();
|
||||
const userController = require("../controllers/userController");
|
||||
const electionController = require("../controllers/electionController");
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -48,7 +48,84 @@ const electionController = require('../controllers/electionController');
|
||||
* description: Validation error. Indicates that the request body contains invalid data.
|
||||
*/
|
||||
// Login User
|
||||
router.post('/login', userController.login);
|
||||
router.post("/login", userController.login);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /auth/otp:
|
||||
* post:
|
||||
* summary: Send OTP to user for login
|
||||
* description: Allows users to log in with their phone number by sending an OTP.
|
||||
* tags:
|
||||
* - Auth
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* phone:
|
||||
* type: string
|
||||
* example:
|
||||
* phone: "09124569875"
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OTP sent successfully.
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* example:
|
||||
* message: "OTP sent successfully."
|
||||
*/
|
||||
router.post("/otp", userController.otp);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /auth/otp/verify:
|
||||
* post:
|
||||
* summary: Verify the OTP sent to user
|
||||
* description: Allows users to log in by verifying the OTP sent to their phone number.
|
||||
* tags:
|
||||
* - Auth
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* phone:
|
||||
* type: string
|
||||
* code:
|
||||
* type: string
|
||||
* example:
|
||||
* phone: "09124569875"
|
||||
* code: "12345"
|
||||
* responses:
|
||||
* 200:
|
||||
* description: User logged in successfully.
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* token:
|
||||
* type: string
|
||||
* example:
|
||||
* token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
|
||||
* 401:
|
||||
* description: Unauthorized. Indicates that the provided credentials are invalid.
|
||||
* 403:
|
||||
* description: Forbidden. Indicates that the account is inactive. Contact the admin for assistance.
|
||||
* 422:
|
||||
* description: Validation error. Indicates that the request body contains invalid data.
|
||||
*/
|
||||
router.post("/otp/verify", userController.verifyOtp);
|
||||
/**
|
||||
* @swagger
|
||||
* /auth/logout:
|
||||
@@ -73,7 +150,7 @@ router.post('/login', userController.login);
|
||||
* description: Unauthorized. Indicates that the user is not logged in.
|
||||
*/
|
||||
// Logout User
|
||||
router.delete('/logout', userController.logout);
|
||||
router.delete("/logout", userController.logout);
|
||||
/**
|
||||
* @swagger
|
||||
* /auth/user:
|
||||
@@ -96,7 +173,7 @@ router.delete('/logout', userController.logout);
|
||||
* description: Unauthorized. Indicates that the user is not authenticated or the token is invalid.
|
||||
*/
|
||||
// Data User
|
||||
router.get('/user', userController.getuser);
|
||||
router.get("/user", userController.getuser);
|
||||
/**
|
||||
* @swagger
|
||||
* /auth/forget-password:
|
||||
@@ -154,7 +231,7 @@ router.get('/user', userController.getuser);
|
||||
* description: Error message indicating the internal server error.
|
||||
*/
|
||||
// Change Password
|
||||
router.post('/changePassword' , userController.forgetPassGenerateToken);
|
||||
router.post("/changePassword", userController.forgetPassGenerateToken);
|
||||
/**
|
||||
* @swagger
|
||||
* /auth/changePassword/{token}:
|
||||
@@ -213,7 +290,7 @@ router.post('/changePassword' , userController.forgetPassGenerateToken);
|
||||
* description: Error message indicating the internal server error.
|
||||
*/
|
||||
// Change Password :token param
|
||||
router.put('/changePassword/:token' , userController.forgetPassGetToken);
|
||||
router.put("/changePassword/:token", userController.forgetPassGetToken);
|
||||
|
||||
///////// voter
|
||||
|
||||
@@ -272,7 +349,7 @@ router.put('/changePassword/:token' , userController.forgetPassGetToken);
|
||||
*/
|
||||
|
||||
//Voter Login
|
||||
router.post('/voter/login' , electionController.voterLogin);
|
||||
router.post("/voter/login", electionController.voterLogin);
|
||||
/**
|
||||
* @swagger
|
||||
* /auth/voter/user:
|
||||
@@ -316,6 +393,6 @@ router.post('/voter/login' , electionController.voterLogin);
|
||||
* description: Error message indicating the internal server error.
|
||||
*/
|
||||
// user Voter Data
|
||||
router.get('/voter/user' , electionController.getVoterUser);
|
||||
router.get("/voter/user", electionController.getVoterUser);
|
||||
|
||||
module.exports = router
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user