-
Notifications
You must be signed in to change notification settings - Fork 61
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
0 parents
commit 6bc6afa
Showing
256 changed files
with
47,352 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Binary file not shown.
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,6 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. | ||
from .models import Profile | ||
|
||
admin.site.register(Profile) |
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 AccountsConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'accounts' |
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,33 @@ | ||
# Generated by Django 4.0.3 on 2022-03-07 04:59 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Profile', | ||
fields=[ | ||
('uid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
('created_at', models.DateTimeField(auto_now=True)), | ||
('updated_at', models.DateTimeField(auto_now_add=True)), | ||
('is_email_verified', models.BooleanField(default=False)), | ||
('email_token', models.CharField(blank=True, max_length=100, null=True)), | ||
('profile_image', models.ImageField(upload_to='profile')), | ||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='profile', to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] |
Empty file.
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,29 @@ | ||
|
||
from django.db import models | ||
from django.contrib.auth.models import User | ||
from base.models import BaseModel | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
import uuid | ||
from base.emails import send_account_activation_email | ||
|
||
class Profile(BaseModel): | ||
user = models.OneToOneField(User , on_delete=models.CASCADE , related_name="profile") | ||
is_email_verified = models.BooleanField(default=False) | ||
email_token = models.CharField(max_length=100 , null=True , blank=True) | ||
profile_image = models.ImageField(upload_to = 'profile') | ||
|
||
|
||
|
||
@receiver(post_save , sender = User) | ||
def send_email_token(sender , instance , created , **kwargs): | ||
try: | ||
if created: | ||
email_token = str(uuid.uuid4()) | ||
Profile.objects.create(user = instance , email_token = email_token) | ||
email = instance.email | ||
send_account_activation_email(email , email_token) | ||
|
||
except Exception as e: | ||
print(e) | ||
|
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,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
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,8 @@ | ||
from django.urls import path | ||
from accounts.views import login_page,register_page , activate_email | ||
|
||
urlpatterns = [ | ||
path('login/' , login_page , name="login" ), | ||
path('register/' , register_page , name="register"), | ||
path('activate/<email_token>/' , activate_email , name="activate_email"), | ||
] |
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,77 @@ | ||
from cmath import log | ||
from tkinter import E | ||
from django.shortcuts import redirect, render | ||
from django.contrib import messages | ||
from django.contrib.auth.models import User | ||
from django.contrib.auth import authenticate , login , logout | ||
from django.http import HttpResponseRedirect,HttpResponse | ||
# Create your views here. | ||
from .models import Profile | ||
|
||
|
||
def login_page(request): | ||
|
||
if request.method == 'POST': | ||
email = request.POST.get('email') | ||
password = request.POST.get('password') | ||
user_obj = User.objects.filter(username = email) | ||
|
||
if not user_obj.exists(): | ||
messages.warning(request, 'Account not found.') | ||
return HttpResponseRedirect(request.path_info) | ||
|
||
|
||
if not user_obj[0].profile.is_email_verified: | ||
messages.warning(request, 'Your account is not verified.') | ||
return HttpResponseRedirect(request.path_info) | ||
|
||
user_obj = authenticate(username = email , password= password) | ||
if user_obj: | ||
login(request , user_obj) | ||
return redirect('/') | ||
|
||
|
||
|
||
messages.warning(request, 'Invalid credentials') | ||
return HttpResponseRedirect(request.path_info) | ||
|
||
|
||
return render(request ,'accounts/login.html') | ||
|
||
|
||
def register_page(request): | ||
|
||
if request.method == 'POST': | ||
first_name = request.POST.get('first_name') | ||
last_name = request.POST.get('last_name') | ||
email = request.POST.get('email') | ||
password = request.POST.get('password') | ||
user_obj = User.objects.filter(username = email) | ||
|
||
if user_obj.exists(): | ||
messages.warning(request, 'Email is already taken.') | ||
return HttpResponseRedirect(request.path_info) | ||
|
||
print(email) | ||
|
||
user_obj = User.objects.create(first_name = first_name , last_name= last_name , email = email , username = email) | ||
user_obj.set_password(password) | ||
user_obj.save() | ||
|
||
messages.success(request, 'An email has been sent on your mail.') | ||
return HttpResponseRedirect(request.path_info) | ||
|
||
|
||
return render(request ,'accounts/register.html') | ||
|
||
|
||
|
||
|
||
def activate_email(request , email_token): | ||
try: | ||
user = Profile.objects.get(email_token= email_token) | ||
user.is_email_verified = True | ||
user.save() | ||
return redirect('/') | ||
except Exception as e: | ||
return HttpResponse('Invalid Email token') |
Empty file.
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,13 @@ | ||
import imp | ||
from django.conf import settings | ||
from django.core.mail import send_mail | ||
|
||
|
||
|
||
|
||
def send_account_activation_email(email , email_token): | ||
return | ||
subject = 'Your account needs to be verified' | ||
email_from = settings.EMAIL_HOST_USER | ||
message = f'Hi, click on the link to activate your account http://127.0.0.1:8000/accounts/activate/{email_token}' | ||
send_mail(subject , message , email_from , [email]) |
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,15 @@ | ||
from django.db import models | ||
import uuid | ||
|
||
|
||
|
||
class BaseModel(models.Model): | ||
uid = models.UUIDField(primary_key=True , editable=False , default=uuid.uuid4) | ||
created_at = models.DateTimeField(auto_now= True) | ||
updated_at = models.DateTimeField(auto_now_add= True) | ||
|
||
class Meta: | ||
abstract = True | ||
|
||
|
||
|
Binary file not shown.
Empty file.
Binary file not shown.
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,16 @@ | ||
""" | ||
ASGI config for ecomm project. | ||
It exposes the ASGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ecomm.settings') | ||
|
||
application = get_asgi_application() |
Oops, something went wrong.