Skip to content
Snippets Groups Projects
Commit 50cc2361 authored by V S Tharunika's avatar V S Tharunika
Browse files

authentication to input added

parent c33dbda3
Branches
No related tags found
No related merge requests found
const Joi = require('joi')
module.exports={
register(reg, res, next){
const schema ={
email: Joi.string().email(),
password: Joi.string().regex(
new regExp('^[a-zA-Z0-9]{8-32}$')
)
}
const {error, value} = Joi.Validate(req.body, schema)
if(error){
switch(error.details[0].context.key){
case 'email':
res.status(400).send({
error: 'You must provide a valid email address'
})
break
case 'password':
res.status(400).send({
error: ' The password provided failed to match the following rules <br> 1.It must contain only the following characters: lower case, upper case, numerics <br> 2.It must be at least 8 characters in lenght and not greater than 32 characters'
})
break
default:
res.status(400).send({
error:'Invalid registration information'
})
}
}
else{
next()
}
}
}
const AuthenticationController = require('./controllers/AuthenticationController')
const AuthenticationControllerPolicy = require('./policies/AuthenticationControllerPolicy')
module.exports = (app) => {
app.post('/register',
AuthenticationControllerPolicy.register,
AuthenticationController.register)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment