Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: python # => 1
python: # => 2
- "3.6"
- "3.7"
services: # => 3
- mysql
env: # => 4
-DJANGO=2.0.1 DB=mysql
install: # => 5
- pip install -r requirements.txt
before_script: # => 6
- mysql -e 'create database test;' -u root
script: # => 7
- python manage.py test

6 changes: 5 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,7 @@
STATIC_URL = '/static/'

LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'home'

LOGOUT_REDIRECT_URL = 'home'

CRISPY_TEMPLATE_PACK = 'bootstrap4'
11 changes: 9 additions & 2 deletions Argon/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@
1. Import the include() function: from django.urls import include, path
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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Argon
# Argon
1 change: 0 additions & 1 deletion accounts/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from django.contrib import admin

# Register your models here.
14 changes: 14 additions & 0 deletions accounts/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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',)
1 change: 0 additions & 1 deletion accounts/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from django.db import models

# Create your models here.
1 change: 0 additions & 1 deletion accounts/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from django.test import TestCase

# Create your tests here.
4 changes: 2 additions & 2 deletions accounts/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.urls import path
from accounts.views import SignUpView

from .views import SignUpView

urlpatterns = [
path('signup/', SignUpView.as_view(), name='signup'),
]
]
40 changes: 33 additions & 7 deletions accounts/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
from django.contrib.auth.forms import UserCreationForm
from django.shortcuts import render
from django.shortcuts import redirect
from django.views.generic.edit import FormView
from .forms import SignUpForm
from django.contrib.auth import authenticate
from django.contrib.auth import login
from django.contrib import messages

from django.urls import reverse_lazy

from django.views import generic
class SignUpView(FormView):
form_class = SignUpForm
template_name = 'signup.html'

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

class SignUpView(generic.CreateView):
form_class = UserCreationForm
success_url = reverse_lazy('login')
template_name = 'signup.html'
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() # saves the form data
# authenticates the user info
user = authenticate(username=username,
password=raw_password)
user.set_password(raw_password)
user.save() # save the user in the user table
# this will show an alert if the account is created
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})
Binary file modified db.sqlite3
Binary file not shown.
1 change: 0 additions & 1 deletion home/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from django.contrib import admin

# Register your models here.
1 change: 0 additions & 1 deletion home/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from django.db import models

# Create your models here.
1 change: 0 additions & 1 deletion home/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from django.test import TestCase

# Create your tests here.
3 changes: 1 addition & 2 deletions home/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.urls import path

from .views import HomePageView


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
16 changes: 13 additions & 3 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
<!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>
<!--this block will check if there is an message then it will itrate all messages and will show an alert on the current page-->
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{message.tags}}">
{{message}}
</div>
{% endfor %}
{% endif %}
<div>
{% block content %}

{% endblock content %}
</div>
</body>
</html>
10 changes: 3 additions & 7 deletions templates/home.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{% extends 'base.html' %}

{% block content %}

<h1>This is HomePage.</h1>

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

30 changes: 20 additions & 10 deletions templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
{% 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>

{% endblock content %}
<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 %}
44 changes: 20 additions & 24 deletions templates/signup.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@

{% 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>



{% endblock content %}
<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 %}