mirror of
https://gitlab.com/little-lines/backend.git
synced 2024-11-21 23:16:51 +00:00
Merge branch 'main' of https://gitlab.com/openKMITL/little-lines/backend
This commit is contained in:
commit
0feed90cfc
1 changed files with 6 additions and 6 deletions
|
@ -72,22 +72,22 @@ const updateUser = asyncHandler(async (req, res) => {
|
|||
// Login user => api/users/login
|
||||
const loginUser = asyncHandler(async (req, res) => {
|
||||
try {
|
||||
const { username, password } = req.body;
|
||||
const { email, password } = req.body;
|
||||
|
||||
if(!username || !password) {
|
||||
return res.status(400).send('Please enter username & password');
|
||||
if(!email || !password) {
|
||||
return res.status(400).send('Please enter email & password');
|
||||
}
|
||||
|
||||
const users = await user.findOne({ username }).select('+password');
|
||||
const users = await user.findOne({ email }).select('+password');
|
||||
|
||||
if(!users) {
|
||||
return res.status(400).send('Invalid username or Password');
|
||||
return res.status(400).send('Invalid Email');
|
||||
}
|
||||
|
||||
const isPasswordMatched = await users.comparePassword(password);
|
||||
|
||||
if(!isPasswordMatched) {
|
||||
return res.status(401).send('Invalid username or Password');
|
||||
return res.status(401).send('Invalid Password');
|
||||
}
|
||||
|
||||
sendToken(users, 200, res);
|
||||
|
|
Loading…
Reference in a new issue