Fixed ldap auth bullshit!
This commit is contained in:
parent
8fc201f5f7
commit
78de2c8344
|
@ -7,6 +7,20 @@ import execawait from '../libs/execawait.js'
|
||||||
const AUTH = Router()
|
const AUTH = Router()
|
||||||
let valid = {}
|
let valid = {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ...
|
||||||
|
* @param {string} hash The hash to be converted to hex.
|
||||||
|
* @returns {string} hex of hash
|
||||||
|
*/
|
||||||
|
function hash2hex(hash) {
|
||||||
|
return hash
|
||||||
|
.split('')
|
||||||
|
.map(e => e
|
||||||
|
.charCodeAt(0)
|
||||||
|
.toString(16)
|
||||||
|
)
|
||||||
|
.join('')
|
||||||
|
}
|
||||||
|
|
||||||
AUTH.post('/register', async (req, res) => {
|
AUTH.post('/register', async (req, res) => {
|
||||||
const { captcha, password, username } = req.body
|
const { captcha, password, username } = req.body
|
||||||
|
@ -36,9 +50,10 @@ AUTH.post('/register', async (req, res) => {
|
||||||
|
|
||||||
bcrypt.hash(password, 10).then(
|
bcrypt.hash(password, 10).then(
|
||||||
hash => {
|
hash => {
|
||||||
|
const hexHash = hash2hex(hash)
|
||||||
glauth.query(
|
glauth.query(
|
||||||
"INSERT INTO users(name, primarygroup, passbcrypt) VALUES($1::text, 0, $2::text)",
|
"INSERT INTO users(name, primarygroup, passbcrypt, qam_pass) VALUES($1::text, 0, $2::text, $3::text)",
|
||||||
[ username, hash ]
|
[ username, hexHash, hash ]
|
||||||
).then(
|
).then(
|
||||||
() => res.send("Account registered!")
|
() => res.send("Account registered!")
|
||||||
).catch(
|
).catch(
|
||||||
|
@ -61,7 +76,7 @@ AUTH.post('/login', async (req, res) => {
|
||||||
if (!user)
|
if (!user)
|
||||||
return(res.send("User doesn't exist!"))
|
return(res.send("User doesn't exist!"))
|
||||||
|
|
||||||
bcrypt.compare(password, user.passbcrypt).then(
|
bcrypt.compare(password, user.qam_pass).then(
|
||||||
match => {
|
match => {
|
||||||
if (!match)
|
if (!match)
|
||||||
return res.send("Password's is incorrect!")
|
return res.send("Password's is incorrect!")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user