Skip to content

Commit

Permalink
signin route correction
Browse files Browse the repository at this point in the history
  • Loading branch information
manupanand committed Nov 11, 2024
1 parent 69797e6 commit c4033ec
Show file tree
Hide file tree
Showing 11 changed files with 421 additions and 211 deletions.
8 changes: 8 additions & 0 deletions TestReadme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
"privilege": false
}
```
#### user body -sign in
```
{
"username": "[email protected]",
"password": "SecurePassword123",
}
```

### sample question document

Expand Down
163 changes: 163 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"author": "manu p anand",
"license": "GPL-3.0",
"dependencies": {
"axios": "^1.7.7",
"body-parser": "^1.20.3",
"cors": "^2.8.5",
"crypto-js": "^4.2.0",
Expand All @@ -25,6 +26,7 @@
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.8.0",
"morgan": "^1.10.0",
"redis": "^4.7.0",
"winston": "^3.16.0",
"zod": "^3.23.8"
}
Expand Down
18 changes: 17 additions & 1 deletion src/config/inputValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const signupBody=zod.object({
firstName:zod.string(),
lastName:zod.string()
})
const signInBody=zod.object({
username:zod.string().email(),
password:zod.string(),

})
const inputvalidate=(input)=>{

try{
Expand All @@ -18,4 +23,15 @@ const inputvalidate=(input)=>{
}

}
module.exports=inputvalidate
const signInValidate=(input)=>{

try{
const validate=signInBody.safeParse(input)
logger.info("Input valid is returned")
return validate
}catch(error){
logger.error(" Error in input validation",error)
}

}
module.exports={inputvalidate,signInValidate}
35 changes: 35 additions & 0 deletions src/config/passwordValidate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const logger= require('./logger')
const {User}=require('../model/user.models')
const {Admin}=require('../model/admin.models')
const {decrypt}=require('./crypt')



async function validateUserPassword(inputPassword,id,key){
try{const user=await User.findOne(id)
const userPassword=decrypt(user.password,key)

if(userPassword==inputPassword){
logger.info("User password is valid")
return true
}
}catch(error){
logger.error("Error in validating password",error)
}


}
async function validateAdminPassword(inputPassword,id){
try{const admin=await Admin.findOne(id)
const adminPassword=decrypt(admin.password,key)

if(adminPassword==inputPassword){
logger.info("User password is valid")
return true
}
}catch(error){
logger.error("Error in validating password",error)
}
}

module.exports={validateUserPassword,validateAdminPassword}
32 changes: 32 additions & 0 deletions src/config/redis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const logger=require('./logger')
const { createClient }=require('redis');

let client;

async function connectRedis(){
try{
if(client){
return client;
}else{
const client = createClient({
password: process.env.REDIS_PWD,
socket: {
host: process.env.REDIS_URL,
port: process.env.REDIS_PORT
}
});
await client.connect()
logger.info("Redis client connected successfully")
return client;
}



}catch(error){
logger.error('Error in connecting to redis',error)
}

}
module.exports={connectRedis,getClient:()=>client}


Loading

0 comments on commit c4033ec

Please sign in to comment.