diff --git a/requirements.txt b/requirements.txt index 394957f..ed4b331 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ Django==2.2.1 pytz==2019.1 setuptools==41.0.1 -sqlparse==0.3.0 \ No newline at end of file +sqlparse==0.3.0 +py3dns==3.2.0 +validate-email==1.3 \ No newline at end of file diff --git a/users/forms.py b/users/forms.py new file mode 100644 index 0000000..a9c7443 --- /dev/null +++ b/users/forms.py @@ -0,0 +1,18 @@ +from django.contrib.auth.forms import UserCreationForm +from django import forms +from django.contrib.auth.models import User +from .models import ProfileModel + + +class UserRegisterForm(UserCreationForm): + email = forms.EmailField(max_length=254, help_text='Required. Inform a valid email address.') + + class Meta: + model = User + fields = ['username', 'email', 'password1', 'password2'] + + def save(self, commit=True): + user = super(UserRegisterForm, self).save(commit=False) + if commit: + user.save() + return user diff --git a/users/models.py b/users/models.py index 423cc36..9b628c4 100644 --- a/users/models.py +++ b/users/models.py @@ -1,5 +1,7 @@ + from django.db import models from django.contrib.auth.models import User +from django.urls import reverse # Create your models here. @@ -9,3 +11,9 @@ class ProfileModel(models.Model): discription = models.CharField(max_length=500) dob = models.DateField() profile_image = models.ImageField() + + def get_absolute_url(self): + return reverse('login') + + def __str__(self): + return self.university diff --git a/users/templates/base.html b/users/templates/base.html index 3d4305f..0f76c77 100644 --- a/users/templates/base.html +++ b/users/templates/base.html @@ -8,6 +8,7 @@ + @@ -20,5 +21,9 @@

Crispy AI

{% endblock %} + + + + diff --git a/users/templates/registration/login.html b/users/templates/registration/login.html index d965c23..53b1ba0 100644 --- a/users/templates/registration/login.html +++ b/users/templates/registration/login.html @@ -3,10 +3,33 @@ {% block title %}Login{% endblock %} {% block content %} -

Login

-
- {% csrf_token %} - {{ form.as_p }} - -
+
+
+
+
Login
+
Here you have to Login into your account
+
+ {% csrf_token %} + {% for field in form %} +

+ {{ field.label_tag }}
+ {{ field }} + {% if field.help_text %} + {{ field.help_text }} + {% endif %} + {% for error in field.errors %} +

{{ error }}

+ {% endfor %} +

+ {% endfor %} + +
+
+ +
+ +
+
+ +
{% endblock %} diff --git a/users/templates/users/register.html b/users/templates/users/register.html new file mode 100644 index 0000000..7fe2329 --- /dev/null +++ b/users/templates/users/register.html @@ -0,0 +1,30 @@ +{% extends 'base.html' %} +{% block content %} +
+
+
+
Create an account
+
Here you have to create an account
+
+ {% csrf_token %} + {% for field in form %} +

+ {{ field.label_tag }}
+ {{ field }} + {% if field.help_text %} + {{ field.help_text }} + {% endif %} + {% for error in field.errors %} +

{{ error }}

+ {% endfor %} +

+ {% endfor %} + +
+ +
+
+ +
+ +{% endblock %} \ No newline at end of file diff --git a/users/templates/users/test.html b/users/templates/users/test.html new file mode 100644 index 0000000..d67d320 --- /dev/null +++ b/users/templates/users/test.html @@ -0,0 +1,17 @@ +{% extends 'base.html' %} +{% block content %} +
+ {% for field in form %} +

+ {{ field.label_tag }}
+ {% if field.help_text %} + {{ field.help_text }} + {% endif %} + {% for error in field.errors %} +

{{ error }}

+ {% endfor %} +

+ {% endfor %} +

This Page is shown if your email is invalid

+
+{% endblock %} \ No newline at end of file diff --git a/users/urls.py b/users/urls.py index a5cb33f..af7cf0c 100644 --- a/users/urls.py +++ b/users/urls.py @@ -5,5 +5,9 @@ urlpatterns = [ path('', include('django.contrib.auth.urls')), # home page for users - path('', views.Home, name='Home') + path('', views.Home, name='Home'), + # #login path only created to redirect after registrations + # path('login',views.login,name='login'), + # Register Page + path('register', views.UserRegister, name='register'), ] diff --git a/users/views.py b/users/views.py index a8058db..6e88b01 100644 --- a/users/views.py +++ b/users/views.py @@ -1,5 +1,9 @@ from django.shortcuts import render, redirect from django.contrib.auth.decorators import login_required +from .forms import UserRegisterForm +from django.http import Http404 +from validate_email import validate_email +from django.contrib import messages # Create your views here. @@ -7,3 +11,32 @@ # Custom login url is specified in the decorator. def Home(request): return render(request, './users/home.html') + +# def login(request): +# return render(request,'./registration/login.html') + + +def UserRegister(request): + + if request.method == 'POST': + form = UserRegisterForm(request.POST) + if form.is_valid(): + email = form.cleaned_data.get('email') + is_valid = validate_email(email, check_mx=True) + if is_valid: + is_valid = validate_email(email, verify=True) + if is_valid: + username = form.cleaned_data.get('username') + messages.success(request, f'Account Created for {username}!') + form.save() + return redirect('Home') + else: + return render(request, './users/test.html', {'form': form}) + else: + return render(request, './users/test.html', {'form': form}) + + else: + return render(request, './users/test.html', {'form': form}) + else: + form = UserRegisterForm() + return render(request, './users/register.html', {'form': form})