You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
661 B

from django.contrib.auth.models import User
from cashonly.models import Account
7 years ago
class CashBackend(object):
7 years ago
def authenticate(self, card_number=None, pin=None):
if not card_number.isdigit():
raise ValueError('card_number has to consist of digits only!')
7 years ago
if len(pin) > 0 and not pin.isdigit():
raise ValueError('pin has to consist of digits only or \
has to be empty!')
7 years ago
try:
account = Account.objects.get(card_number=card_number)
except Account.DoesNotExist:
return None
7 years ago
if account.check_pin(pin):
return account.user
7 years ago
return None