added verify token in custom user model
This commit is contained in:
parent
537519a3dd
commit
3b4e1634ab
5 changed files with 27 additions and 11 deletions
|
|
@ -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)
|
||||
|
||||
|
|
@ -65,3 +67,7 @@ class RegisterView(APIView):
|
|||
)
|
||||
message.attach_alternative(html_body, "text/html")
|
||||
message.send(fail_silently=False)
|
||||
|
||||
class VerifyEmailView(APIView):
|
||||
def post(self, request):
|
||||
pass
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
Thank you for registering with Videoflix. To complete your registration
|
||||
and verify your email address, please click the link below:
|
||||
</p>
|
||||
<a class="btn" href="">Activate account</a>
|
||||
<a class="btn" href="http://localhost:4200/verify-email?token={{ token }}&email={{ email }}">Activate account</a>
|
||||
<p>
|
||||
If you did not create an account with us, please disregard this email.
|
||||
</p>
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@ class CustomUserAdmin(UserAdmin):
|
|||
'Individual data',
|
||||
{
|
||||
'fields': (
|
||||
'custom',
|
||||
'phone',
|
||||
'address',
|
||||
'verify_email',
|
||||
)
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
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))
|
||||
|
|
|
|||
|
|
@ -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/<int:id>/', views.user_detail),
|
||||
path('auth/login/', LoginView.as_view()),
|
||||
path('auth/register/', RegisterView.as_view()),
|
||||
path('auth/verify-email/', VerifyEmailView.as_view()),
|
||||
|
||||
]
|
||||
|
|
|
|||
Loading…
Reference in a new issue