Esempio n. 1
0
 def clean(self):
     cleaned_data = self.cleaned_data
     if cleaned_data.get('number'):
         if match_number(cleaned_data.get('number')):
             raise forms.ValidationError(u'Wrong Card Number! Should be 14 digits not starting from 0')
         try:
             card = Card.objects.get(number=cleaned_data.get('number'))
         except Card.DoesNotExist:
             raise forms.ValidationError(u'Card doesn\'t exist!')
     else:
         raise forms.ValidationError(u'Enter Card Number')
     return cleaned_data
Esempio n. 2
0
    def create_user(self, number, password, is_active=True, is_admin=False):

        # Creates Card and Card Account

        if match_number(number):
            raise ValueError(u"Wrong Card Number! Must be 16 digits starting from 1.")
        if match_password(password):
            raise ValueError(u"Wrong Password! Must be 4 digits.")

        card = self.model(
            number=number,
            is_active=is_active,
            is_admin=is_admin
        )

        card.set_password(password)
        card.save(using=self._db)

        return card