Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Argon/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
INSTALLED_APPS = [
'home.apps.HomeConfig',
'accounts.apps.AccountsConfig',
'crispy_forms',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down Expand Up @@ -122,4 +123,6 @@
STATIC_URL = '/static/'

LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'home'

CRISPY_TEMPLATE_PACK = 'bootstrap4'
14 changes: 10 additions & 4 deletions Argon/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include

from django.urls import path
from django.urls import include
from django.contrib.auth import views as auth_views
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/', include('django.contrib.auth.urls')),
path('accounts/', include('accounts.urls')),
path('', include('home.urls')),
]
path('login/', auth_views.LoginView.as_view(template_name='registration/login.html'), name='login'),




]

2 changes: 2 additions & 0 deletions Argon/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Argon.settings")

application = get_wsgi_application()


13 changes: 13 additions & 0 deletions accounts/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm


class SignUpForm(UserCreationForm):
first_name = forms.CharField(max_length=30, required=False, )
last_name = forms.CharField(max_length=30, required=False, )
email = forms.EmailField(max_length=50, required=True, )

class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2',)
6 changes: 4 additions & 2 deletions accounts/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from django.urls import path
from accounts.views import SignUpView

from .views import SignUpView

urlpatterns = [
path('signup/', SignUpView.as_view(), name='signup'),
]

]

41 changes: 34 additions & 7 deletions accounts/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
from django.contrib.auth.forms import UserCreationForm

from django.http import HttpResponseRedirect
from django.shortcuts import render, redirect
from django.views.generic.edit import FormView
from .forms import SignUpForm
from django.contrib.auth import authenticate, login
from django.views.generic import TemplateView
from django.urls import reverse_lazy
from django.contrib import messages

class SignUpView(FormView):
form_class = SignUpForm
template_name = 'signup.html'

from django.views import generic
def get(self, request, *args, **kwargs):
form = self.form_class(None)
return render(request, self.template_name, {'form': form})

def post(self, request, *args, **kwargs):
form = self.form_class(request.POST)
if form.is_valid():
form.save(commit=False)
# <process form cleaned data>
username = form.cleaned_data['username']
raw_password = form.cleaned_data['password1']
form.save()

user = authenticate(username=username, password=raw_password)
user.set_password(raw_password)
user.save()
messages.success(request,f'Account created for {username}')
if user is not None:

if user.is_active:
login(request, user)
return redirect('home')

return render(request, self.template_name, {'form': form})

class SignUpView(generic.CreateView):
form_class = UserCreationForm
success_url = reverse_lazy('login')
template_name = 'signup.html'
Binary file modified db.sqlite3
Binary file not shown.
6 changes: 5 additions & 1 deletion home/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@

urlpatterns = [
path('', HomePageView.as_view(), name='home'),
]
]




2 changes: 1 addition & 1 deletion home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class HomePageView(TemplateView):
template_name = 'home.html'
template_name = 'home.html'
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Django==2.0.1
pkg-resources==0.0.0
pytz==2019.1
sqlparse==0.3.0
27 changes: 19 additions & 8 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
<!DOCTYPE html>
<html>
<head>
{% load staticfiles %}
<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">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<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>
<title>Argon</title>

</head>
<body>
<header>
<h1><a href="{% url 'home' %}">Argon</a></h1>
</header>
<div>
{% block content %}

{% endblock content %}
</div>
</body>
</html>
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{message.tags}}">
{{message}}
</div>
{% endfor %}

{% endif %}
<div>
{% block content %}
{% endblock content %}
</div>
</body>
3 changes: 1 addition & 2 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

{% block content %}

<h1>This is HomePage.</h1>
<h1>This is HomePage</h1>

<p><a href="{% url 'login' %}">Login</a></p>
<p><a href="{% url 'signup' %}">SignUp</a></p>
{% endblock content %}

31 changes: 22 additions & 9 deletions templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
{% extends 'base.html' %}

{% load crispy_forms_tags %}
{% block content %}

<h2>Log In</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Log In</button>
</form>

<div class="containor">
<div class="container">
<div class="row centered-form">

<div class="col-xs-12 col-sm-8 col-md-4 col-sm-offset-2 col-md-offset-4">
<div class="panel panel-default">

<div class="panel-body">

<form method="post">
{% csrf_token %}
<h2>Log In</h2>
{{ form|crispy }}
<button type="submit">Log In</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock content %}
41 changes: 19 additions & 22 deletions templates/signup.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@

{% extends 'base.html' %}

{% load crispy_forms_tags %}
{% block content %}



<h1 align="center">Sign up</h1>

<form method="post">
{% csrf_token %}
{{ form.as_p }}

<p><label for="email">Email:</label><input type="email" name="email"></p> <!––we created this field––>

<p><label for="first_name">First name:</label><input type="text" name="first_name"></p> <!––we created this field––><!––we created this field––>

<p><label for="last_name">Last name:</label><input type="text" name="last_name"></p><!––we created this field––>


<p align="center"><button type="submit">Sign up</button></p>
</form>



<div class="container">
<div class="row centered-form">

<div class="col-xs-12 col-sm-8 col-md-4 col-sm-offset-2 col-md-offset-4">
<div class="panel panel-default">

<div class="panel-body">
<form method="post">
{% csrf_token %}
<h1 align="center">Sign up</h1>
{{ form|crispy }}
<p align="center"><button type="submit" class="btn btn-primary">Sign up</button></p>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock content %}