Merge pull request #617 from mz8i/feature/login-username-warn
Warn of wrong username on login screen
This commit is contained in:
commit
2c9335c1eb
@ -54,40 +54,34 @@ async function createUser(user) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function authUser(username: string, password: string) {
|
async function authUser(username: string, password: string) {
|
||||||
try {
|
const user = await db.oneOrNone(
|
||||||
const user = await db.one(
|
`SELECT
|
||||||
`SELECT
|
user_id,
|
||||||
user_id,
|
(
|
||||||
(
|
pass = crypt($2, pass)
|
||||||
pass = crypt($2, pass)
|
) AS auth_ok,
|
||||||
) AS auth_ok,
|
is_blocked,
|
||||||
is_blocked,
|
blocked_on,
|
||||||
blocked_on,
|
blocked_reason
|
||||||
blocked_reason
|
FROM users
|
||||||
FROM users
|
WHERE
|
||||||
WHERE
|
username = $1
|
||||||
username = $1
|
`, [
|
||||||
`, [
|
username,
|
||||||
username,
|
password
|
||||||
password
|
]
|
||||||
]
|
);
|
||||||
);
|
|
||||||
|
|
||||||
if (user && user.auth_ok) {
|
if (user == undefined) {
|
||||||
if (user.is_blocked) {
|
return { error: 'The username does not exist in the system' };
|
||||||
return { error: `Account temporarily blocked.${user.blocked_reason == undefined ? '' : ' Reason: '+user.blocked_reason}` };
|
} else if (user.auth_ok) {
|
||||||
}
|
if (user.is_blocked) {
|
||||||
return { user_id: user.user_id };
|
return { error: `Account temporarily blocked.${user.blocked_reason == undefined ? '' : ' Reason: '+user.blocked_reason}` };
|
||||||
} else {
|
|
||||||
return { error: 'Username or password not recognised' };
|
|
||||||
}
|
}
|
||||||
} catch(err) {
|
return { user_id: user.user_id };
|
||||||
if (err instanceof errors.QueryResultError) {
|
} else {
|
||||||
console.error(`Authentication failed for user ${username}`);
|
console.error(`Authentication failed for user ${username}`);
|
||||||
return { error: 'Username or password not recognised' };
|
return { error: 'Username / password pair not recognised' };
|
||||||
}
|
|
||||||
console.error('Error:', err);
|
|
||||||
return { error: 'Database error' };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user