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"
|
import { User } from "@db_models"
|
||||||
|
|
||||||
export default async ({ username, password, hash }, user) => {
|
export default async ({ username, password, hash }, user) => {
|
||||||
if (typeof user === "undefined") {
|
if (typeof user === "undefined") {
|
||||||
let isEmail = username.match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/)
|
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) {
|
if (!user) {
|
||||||
throw new OperationError(401, "User not found")
|
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")
|
throw new OperationError(401, "User is disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof hash !== "undefined") {
|
if (!bcrypt.compareSync(password, user.password)) {
|
||||||
if (user.password !== hash) {
|
throw new OperationError(401, "Invalid credentials")
|
||||||
throw new OperationError(401, "Invalid credentials")
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
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