-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
view for user Registration created (#33)
* 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
1 parent
42444da
commit 1764b59
Showing
9 changed files
with
148 additions
and
8 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -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 |
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,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 |
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
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
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
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,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 %} |
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,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 %} |
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
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 |
---|---|---|
@@ -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}) |