// POST API for user to login router.post('/login', async (req, res) => { // Validate request before checking user login const validation = userLoginValidation(req.body); if (validation.error) return res.status(400).send(validation.error.details[0].message);; // Check if email exist const user = await User.findOne({email: req.body.email}); if (!user) return res.status(400).send('Email doesnt exist.'); // Check if password is correct const validPass = await bcrypt.compare(req.body.password, user.password); if (!validPass) return res.status(400).send('Invalid login.'); // Create and assign a token to logged in user const token = jwt.sign({_id: user._id}, process.env.TOKEN_SECRET); res.header('auth-token', token).send({ login: true, message: 'Login successful' }); });
const FailClosed = function(config) { if(!(this instanceof FailClosed)) { return new FailClosed(config); } const self = this; // constant configuration self._config = config; const configValidationResult = FailClosed.schema.config.validate( self._config, { abortEarly: false, convert: false } ); if (configValidationResult.error) { throw configValidationResult.error; } self._retryCount = self._config.retryCount === undefined ? 1 : self._config.retryCount; }
let err = riddleSchema.validate(riddle).error;
const FailOpen = function(config) { if(!(this instanceof FailOpen)) { return new FailOpen(config); } const self = this; // constant configuration self._config = config; const configValidationResult = FailOpen.schema.config.validate( self._config, { abortEarly: false, convert: false } ); if (configValidationResult.error) { throw configValidationResult.error; } self._retryCount = self._config.retryCount === undefined ? 1 : self._config.retryCount; }
let err = activitySchema.validate(activity).error;
let err = websiteSchema.validate(website).error;
let err = factSchema.validate(fact).error;