mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
Fix indentation and remove unused hash login method
This commit is contained in:
parent
f0f612942a
commit
3268cb819a
@ -2,13 +2,13 @@ import bcrypt from "bcrypt"
|
||||
import { User } from "@db_models"
|
||||
|
||||
export default async ({ username, password, hash }, user) => {
|
||||
if (typeof user === "undefined") {
|
||||
let isEmail = username.match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/)
|
||||
if (typeof user === "undefined") {
|
||||
let isEmail = username.match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/)
|
||||
|
||||
let query = isEmail ? { email: username } : { username: username }
|
||||
let query = isEmail ? { email: username } : { username: username }
|
||||
|
||||
user = await User.findOne(query).select("+email").select("+password")
|
||||
}
|
||||
user = await User.findOne(query).select("+email").select("+password")
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
throw new OperationError(401, "User not found")
|
||||
@ -18,15 +18,9 @@ export default async ({ username, password, hash }, user) => {
|
||||
throw new OperationError(401, "User is disabled")
|
||||
}
|
||||
|
||||
if (typeof hash !== "undefined") {
|
||||
if (user.password !== hash) {
|
||||
throw new OperationError(401, "Invalid credentials")
|
||||
}
|
||||
} else {
|
||||
if (!bcrypt.compareSync(password, user.password)) {
|
||||
throw new OperationError(401, "Invalid credentials")
|
||||
}
|
||||
}
|
||||
if (!bcrypt.compareSync(password, user.password)) {
|
||||
throw new OperationError(401, "Invalid credentials")
|
||||
}
|
||||
|
||||
return user
|
||||
}
|
||||
return user
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user