Skip to content

Commit

Permalink
view for user Registration created (#33)
Browse files Browse the repository at this point in the history
* profile model created

* Bugs Resolved

* the dob is blank by default

* added the feature on registering users

* -[ ] Closes: #15
-[x] PEP8
Changes Summary: Created a new Register view which provides the functionality to register user and also changed the login template

* Feature added which validates the Email while Registration

* requirements.txt changed

* pep8 fixes
  • Loading branch information
ayush1999guptA authored and NeuralFlux committed May 12, 2019
1 parent 42444da commit 1764b59
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 8 deletions.
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Django==2.2.1
pytz==2019.1
setuptools==41.0.1
sqlparse==0.3.0
sqlparse==0.3.0
py3dns==3.2.0
validate-email==1.3
18 changes: 18 additions & 0 deletions users/forms.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions users/models.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
5 changes: 5 additions & 0 deletions users/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="{% static 'css/header.css' %}" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

</head>
<body>
Expand All @@ -20,5 +21,9 @@ <h1>Crispy AI</h1>

{% endblock %}
</main>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

</body>
</html>
35 changes: 29 additions & 6 deletions users/templates/registration/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,33 @@
{% block title %}Login{% endblock %}

{% block content %}
<h2>Login</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Login</button>
</form>
<div class="container">
<div class="card mx-auto " style="width: 30rem;margin-top: 5%">
<div class="card-body">
<h5 class="card-title">Login</h5>
<h6 class="card-subtitle mb-2 text-muted">Here you have to Login into your account</h6>
<form method="post" style=" display: inline;" >
{% csrf_token %}
{% for field in form %}
<p>
{{ field.label_tag }}<br>
{{ field }}
{% if field.help_text %}
<small style="color: grey">{{ field.help_text }}</small>
{% endif %}
{% for error in field.errors %}
<p style="color: red">{{ error }}</p>
{% endfor %}
</p>
{% endfor %}
<button class="btn btn-success" type="submit" >Log In</button>
</form>
<form action="{% url 'register'%}" method="get" style=" display: inline;" >
<button class="btn btn-secondary" type="submit" >Register</button>
</form>

</div>
</div>

</div>
{% endblock %}
30 changes: 30 additions & 0 deletions users/templates/users/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends 'base.html' %}
{% block content %}
<div class="container">
<div class="card mx-auto " style="width: 30rem;margin-top: 5%">
<div class="card-body">
<h5 class="card-title">Create an account</h5>
<h6 class="card-subtitle mb-2 text-muted">Here you have to create an account</h6>
<form method="post">
{% csrf_token %}
{% for field in form %}
<p>
{{ field.label_tag }}<br>
{{ field }}
{% if field.help_text %}
<small style="color: grey">{{ field.help_text }}</small>
{% endif %}
{% for error in field.errors %}
<p style="color: red">{{ error }}</p>
{% endfor %}
</p>
{% endfor %}
<button class="btn btn-success" type="submit">Register</button>
</form>

</div>
</div>

</div>

{% endblock %}
17 changes: 17 additions & 0 deletions users/templates/users/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends 'base.html' %}
{% block content %}
<div class="container" >
{% for field in form %}
<p>
{{ field.label_tag }}<br>
{% if field.help_text %}
<small style="color: grey">{{ field.help_text }}</small>
{% endif %}
{% for error in field.errors %}
<p style="color: red">{{ error }}</p>
{% endfor %}
</p>
{% endfor %}
<h4 style="color: red;">This Page is shown if your email is invalid </h4>
</div>
{% endblock %}
6 changes: 5 additions & 1 deletion users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
]
33 changes: 33 additions & 0 deletions users/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
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.
@login_required(login_url="/users/login/")
# 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})

0 comments on commit 1764b59

Please sign in to comment.