forked from s3lph/matemat
Hopefully fixed now!
This commit is contained in:
parent
71d7bb85ce
commit
0a27e6db56
2 changed files with 6 additions and 2 deletions
|
@ -183,7 +183,7 @@ class MatematDatabase(object):
|
||||||
row = c.fetchone()
|
row = c.fetchone()
|
||||||
if row is None:
|
if row is None:
|
||||||
raise AuthenticationError('User does not exist')
|
raise AuthenticationError('User does not exist')
|
||||||
user_id, username, email, pwhash, tkhash, admin, member, balance, receipt_pref = row
|
user_id, username, email, pwhash, tkhash, admin, member, balance, receipt_p = row
|
||||||
if password is not None and not compare_digest(crypt.crypt(password, pwhash), pwhash):
|
if password is not None and not compare_digest(crypt.crypt(password, pwhash), pwhash):
|
||||||
raise AuthenticationError('Password mismatch')
|
raise AuthenticationError('Password mismatch')
|
||||||
elif touchkey is not None \
|
elif touchkey is not None \
|
||||||
|
@ -192,6 +192,10 @@ class MatematDatabase(object):
|
||||||
raise AuthenticationError('Touchkey mismatch')
|
raise AuthenticationError('Touchkey mismatch')
|
||||||
elif touchkey is not None and tkhash is None:
|
elif touchkey is not None and tkhash is None:
|
||||||
raise AuthenticationError('Touchkey not set')
|
raise AuthenticationError('Touchkey not set')
|
||||||
|
try:
|
||||||
|
receipt_pref: ReceiptPreference = ReceiptPreference(receipt_p)
|
||||||
|
except ValueError:
|
||||||
|
raise DatabaseConsistencyError(f'{receipt_p} is not a valid ReceiptPreference')
|
||||||
return User(user_id, username, balance, email, admin, member, receipt_pref)
|
return User(user_id, username, balance, email, admin, member, receipt_pref)
|
||||||
|
|
||||||
def change_password(self, user: User, oldpass: str, newpass: str, verify_password: bool = True) -> None:
|
def change_password(self, user: User, oldpass: str, newpass: str, verify_password: bool = True) -> None:
|
||||||
|
|
|
@ -108,7 +108,7 @@ class DatabaseTest(unittest.TestCase):
|
||||||
self.assertEqual(u.id, user.id)
|
self.assertEqual(u.id, user.id)
|
||||||
user = db.login('testuser', touchkey='0123')
|
user = db.login('testuser', touchkey='0123')
|
||||||
self.assertEqual(u.id, user.id)
|
self.assertEqual(u.id, user.id)
|
||||||
self.assertEqual(2, user.receipt_pref)
|
self.assertEqual(ReceiptPreference.MONTHLY, user.receipt_pref)
|
||||||
with self.assertRaises(AuthenticationError):
|
with self.assertRaises(AuthenticationError):
|
||||||
# Inexistent user should fail
|
# Inexistent user should fail
|
||||||
db.login('nooone', 'supersecurepassword')
|
db.login('nooone', 'supersecurepassword')
|
||||||
|
|
Loading…
Reference in a new issue