forked from yahyaaly151989/Mastering_Django
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78c8f5a
commit 2de359d
Showing
68 changed files
with
1,044 additions
and
0 deletions.
There are no files selected for viewing
Binary file modified
BIN
+0 Bytes
(100%)
Module04/bookmarks/account/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
Module04/bookmarks/account/__pycache__/views.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+1.39 KB
Module05/bookmarks/account/__pycache__/authentication.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.contrib import admin | ||
from .models import Profile | ||
|
||
@admin.register(Profile) | ||
class ProfileAdmin(admin.ModelAdmin): | ||
list_display = ['user', 'date_of_birth', 'photo'] | ||
raw_id_fields = ['user'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AccountConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'account' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.contrib.auth.models import User | ||
|
||
class EmailAuthBackend(): | ||
def authenticate(self, request, username=None, password=None): | ||
try: | ||
user = User.objects.get(email=username) | ||
if user.check_password(password): | ||
return user | ||
return None | ||
except (User.DoesNotExist, User.MultipleObjectsReturned): | ||
return None | ||
|
||
def get_user(self, user_id): | ||
try: | ||
return User.objects.get(pk=user_id) | ||
except User.DoesNotExist: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from django import forms | ||
from django.contrib.auth.models import User | ||
from .models import Profile | ||
|
||
|
||
class LoginForm(forms.Form): | ||
username = forms.CharField() | ||
password = forms.CharField(widget=forms.PasswordInput) | ||
|
||
|
||
class UserRegistrationForm(forms.ModelForm): | ||
password = forms.CharField(label= 'password', widget=forms.PasswordInput) | ||
password2 = forms.CharField(label= 'Repeat password', widget=forms.PasswordInput) | ||
|
||
class Meta: | ||
model = User | ||
fields = ['username', 'first_name', 'email'] | ||
|
||
def clean_password2(self): | ||
cd = self.cleaned_data | ||
|
||
if cd['password'] != cd['password2']: | ||
raise forms.ValidationError("Passwords don't match.") | ||
return cd['password2'] | ||
|
||
def clean_email(self): | ||
data = self.cleaned_data['email'] | ||
if User.objects.filter(email=data).exists(): | ||
raise forms.ValidationError('Email already exists.') | ||
return data | ||
|
||
|
||
class UserEditForm(forms.ModelForm): | ||
class Meta: | ||
model = User | ||
fields = ['first_name', 'last_name', 'email'] | ||
|
||
def clean_email(self): | ||
data = self.cleaned_data['email'] | ||
qs = User.objects.exclude(id=self.instance.id).filter(email=data) | ||
if qs.exists(): | ||
raise forms.ValidationError('Email already exists.') | ||
return data | ||
|
||
class ProfileEditForm(forms.ModelForm): | ||
class Meta: | ||
model = Profile | ||
fields = ['date_of_birth', 'photo'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 4.2.4 on 2023-09-22 05:52 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Profile', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('date_of_birth', models.DateField(blank=True, null=True)), | ||
('photo', models.ImageField(blank=True, upload_to='users/%Y/%m/%d/')), | ||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
Module05/bookmarks/account/migrations/0002_alter_profile_photo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.4 on 2023-09-22 14:33 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('account', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='profile', | ||
name='photo', | ||
field=models.ImageField(blank=True, upload_to='users/%Y/%m/%d'), | ||
), | ||
] |
Empty file.
Binary file added
BIN
+1.46 KB
Module05/bookmarks/account/migrations/__pycache__/0001_initial.cpython-311.pyc
Binary file not shown.
Binary file added
BIN
+844 Bytes
Module05/bookmarks/account/migrations/__pycache__/0002_alter_profile_photo.cpython-311.pyc
Binary file not shown.
Binary file added
BIN
+188 Bytes
Module05/bookmarks/account/migrations/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.db import models | ||
from django.conf import settings | ||
|
||
class Profile(models.Model): | ||
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) | ||
|
||
date_of_birth = models.DateField(blank=True, null=True) | ||
photo = models.ImageField(upload_to='users/%Y/%m/%d', blank=True) | ||
|
||
def __str__(self): | ||
return f'Profile of {self.user.username}' |
Oops, something went wrong.