mirror of https://gitgud.io/fatchan/jschan.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
871 B
39 lines
871 B
'use strict';
|
|
|
|
const loginAccount = require(__dirname+'/../../models/forms/login.js');
|
|
|
|
module.exports = async (req, res, next) => {
|
|
|
|
const errors = [];
|
|
|
|
//check exist
|
|
if (!req.body.username || req.body.username.length <= 0) {
|
|
errors.push('Missing username');
|
|
}
|
|
if (!req.body.password || req.body.password.length <= 0) {
|
|
errors.push('Missing password');
|
|
}
|
|
|
|
//check too long
|
|
if (req.body.username && req.body.username.length > 50) {
|
|
errors.push('Username must be 50 characters or less');
|
|
}
|
|
if (req.body.password && req.body.password.length > 100) {
|
|
errors.push('Password must be 100 characters or less');
|
|
}
|
|
|
|
if (errors.length > 0) {
|
|
return res.status(400).render('message', {
|
|
'title': 'Bad request',
|
|
'errors': errors,
|
|
'redirect': '/login.html'
|
|
})
|
|
}
|
|
|
|
try {
|
|
await loginAccount(req, res, next);
|
|
} catch (err) {
|
|
return next(err);
|
|
}
|
|
|
|
}
|
|
|