Untitled
unknown
javascript
3 years ago
943 B
10
Indexable
static signIn(req, res) {
let body = req.body
adminModel
.findOne({ token: body.token })
.then((result) => {
if (result) {
compare(
body.password,
Buffer.from(result.password, 'utf-8').toString(),
(err, same) => {
if (err) {
JSONResponse.error(req, res, 500, 'Server Error', err)
} else if (same) {
JWTHelper.setToken(
req,
res,
{
type: 2,
self: result._id.toString(),
},
'jwt_auth'
)
JSONResponse.success(req, res, 200, 'Successful login')
} else {
JSONResponse.error(
req,
res,
401,
"Password doesn't match"
)
}
}
)
} else JSONResponse.error(req, res, 404, 'No document found')
})
.catch((err) => {
JSONResponse.error(req, res, 500, 'Database Error', err)
})
}Editor is loading...