Updates for the event images
This commit is contained in:
1
mobile_web_api/forms/__init__.py
Normal file
1
mobile_web_api/forms/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .user_forms import *
|
||||
0
mobile_web_api/forms/event_forms.py
Normal file
0
mobile_web_api/forms/event_forms.py
Normal file
42
mobile_web_api/forms/user_forms.py
Normal file
42
mobile_web_api/forms/user_forms.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# accounts/forms.py
|
||||
from django import forms
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth import authenticate
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class RegisterForm(forms.ModelForm):
|
||||
password = forms.CharField(widget=forms.PasswordInput)
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['email', 'phone_number', 'password']
|
||||
|
||||
def clean_email(self):
|
||||
phone_number = self.cleaned_data.get('phone_number')
|
||||
if User.objects.filter(phone_number=phone_number).exists():
|
||||
raise forms.ValidationError("phone_number is already registered.")
|
||||
return phone_number
|
||||
|
||||
def save(self, commit=True):
|
||||
user = super().save(commit=False)
|
||||
user.set_password(self.cleaned_data['password'])
|
||||
if commit:
|
||||
user.save()
|
||||
return user
|
||||
|
||||
|
||||
class LoginForm(forms.Form):
|
||||
username = forms.CharField()
|
||||
password = forms.CharField(widget=forms.PasswordInput)
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
username = cleaned_data.get('username')
|
||||
password = cleaned_data.get('password')
|
||||
user = authenticate(username=username, password=password)
|
||||
if not user:
|
||||
raise forms.ValidationError("Invalid credentials.")
|
||||
cleaned_data['user'] = user
|
||||
return cleaned_data
|
||||
Reference in New Issue
Block a user