diff --git a/backend/videoflix/auth/views.py b/backend/videoflix/auth/views.py index 5700884..a55c365 100644 --- a/backend/videoflix/auth/views.py +++ b/backend/videoflix/auth/views.py @@ -53,7 +53,9 @@ class RegisterView(APIView): def send_email(self, user): merge_data = { - 'name': user.username + 'name': user.username, + 'email': user.email, + 'token': user.verify_email } html_body = render_to_string("mail.html", merge_data) @@ -64,4 +66,8 @@ class RegisterView(APIView): to=['andre.kempf.dev@gmail.com'] ) message.attach_alternative(html_body, "text/html") - message.send(fail_silently=False) \ No newline at end of file + message.send(fail_silently=False) + +class VerifyEmailView(APIView): + def post(self, request): + pass \ No newline at end of file diff --git a/backend/videoflix/templates/mail.html b/backend/videoflix/templates/mail.html index ea3ff02..a4ab908 100644 --- a/backend/videoflix/templates/mail.html +++ b/backend/videoflix/templates/mail.html @@ -40,7 +40,7 @@ Thank you for registering with Videoflix. To complete your registration and verify your email address, please click the link below:
- Activate account + Activate accountIf you did not create an account with us, please disregard this email.
diff --git a/backend/videoflix/users/admin.py b/backend/videoflix/users/admin.py index c13af5a..12ef327 100644 --- a/backend/videoflix/users/admin.py +++ b/backend/videoflix/users/admin.py @@ -13,9 +13,7 @@ class CustomUserAdmin(UserAdmin): 'Individual data', { 'fields': ( - 'custom', - 'phone', - 'address', + 'verify_email', ) } ) diff --git a/backend/videoflix/users/models.py b/backend/videoflix/users/models.py index fa9f6da..5378cdc 100644 --- a/backend/videoflix/users/models.py +++ b/backend/videoflix/users/models.py @@ -1,7 +1,17 @@ -from django.contrib.auth.models import AbstractUser +import secrets +import string from django.db import models +from django.contrib.auth.models import AbstractUser class CustomUser(AbstractUser): - custom = models.CharField(max_length=1000, blank=True) - phone = models.CharField(max_length=20, blank=True) - address = models.CharField(max_length=150, blank=True) \ No newline at end of file + verify_email = models.CharField(max_length=15, blank=True) + + def save(self, *args, **kwargs): + if not self.verify_email: + self.verify_email = self.generate_verification_token() + super().save(*args, **kwargs) + + @staticmethod + def generate_verification_token(length=15): + characters = string.ascii_letters + string.digits + return ''.join(secrets.choice(characters) for _ in range(length)) diff --git a/backend/videoflix/videoflix/urls.py b/backend/videoflix/videoflix/urls.py index 6b18d44..9fe4ad8 100644 --- a/backend/videoflix/videoflix/urls.py +++ b/backend/videoflix/videoflix/urls.py @@ -17,7 +17,7 @@ Including another URLconf from django.contrib import admin from django.urls import path, include from users import views -from auth.views import LoginView, RegisterView +from auth.views import LoginView, RegisterView, VerifyEmailView urlpatterns = [ path('admin/', admin.site.urls), @@ -25,4 +25,6 @@ urlpatterns = [ path('users/