2022-08-09 06:27:55 +00:00
|
|
|
from django import forms
|
2022-09-26 11:48:15 +00:00
|
|
|
from django.contrib.auth.hashers import make_password, identify_hasher
|
2022-08-09 06:27:55 +00:00
|
|
|
from django.core.exceptions import ValidationError
|
|
|
|
|
|
|
|
from ..models.auth import APIUser
|
|
|
|
|
|
|
|
|
|
|
|
class APIUserForm(forms.ModelForm):
|
|
|
|
model = APIUser
|
|
|
|
fields = ["username", "password"]
|
|
|
|
|
|
|
|
def clean_password(self):
|
|
|
|
raw = self.cleaned_data['password']
|
|
|
|
|
|
|
|
if not raw:
|
|
|
|
return ValidationError("You did not enter a password.")
|
|
|
|
|
2022-09-26 11:48:15 +00:00
|
|
|
try:
|
|
|
|
identify_hasher(raw)
|
|
|
|
return make_password(raw)
|
|
|
|
except:
|
|
|
|
return raw
|