1
0
Fork 0
forked from s3lph/matemat

Hopefully fixed now!

This commit is contained in:
s3lph 2018-09-09 03:44:49 +02:00
parent 71d7bb85ce
commit 0a27e6db56
2 changed files with 6 additions and 2 deletions

View file

@ -183,7 +183,7 @@ class MatematDatabase(object):
row = c.fetchone()
if row is None:
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):
raise AuthenticationError('Password mismatch')
elif touchkey is not None \
@ -192,6 +192,10 @@ class MatematDatabase(object):
raise AuthenticationError('Touchkey mismatch')
elif touchkey is not None and tkhash is None:
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)
def change_password(self, user: User, oldpass: str, newpass: str, verify_password: bool = True) -> None:

View file

@ -108,7 +108,7 @@ class DatabaseTest(unittest.TestCase):
self.assertEqual(u.id, user.id)
user = db.login('testuser', touchkey='0123')
self.assertEqual(u.id, user.id)
self.assertEqual(2, user.receipt_pref)
self.assertEqual(ReceiptPreference.MONTHLY, user.receipt_pref)
with self.assertRaises(AuthenticationError):
# Inexistent user should fail
db.login('nooone', 'supersecurepassword')