Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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

37 changes: 4 additions & 33 deletions Argon/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,28 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '*9r6b3_lr!jlk1)f3z&7=)x#b)%089yv0vsc_yeb$k9qwm-z3('

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'home.apps.HomeConfig',
'accounts.apps.AccountsConfig',
'crispy_forms',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand All @@ -50,9 +40,7 @@
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'Argon.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
Expand All @@ -68,24 +56,17 @@
},
},
]

WSGI_APPLICATION = 'Argon.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
Expand All @@ -100,26 +81,16 @@
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATIC_URL = '/static/'

LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'home'
CRISPY_TEMPLATE_PACK = 'bootstrap4'
9 changes: 5 additions & 4 deletions Argon/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
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'),
]
4 changes: 0 additions & 4 deletions Argon/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
For more information on this file, see
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Argon.settings")

application = get_wsgi_application()
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.
2 changes: 0 additions & 2 deletions accounts/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from django.apps import AppConfig


class AccountsConfig(AppConfig):
name = 'accounts'
11 changes: 11 additions & 0 deletions accounts/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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.
6 changes: 2 additions & 4 deletions accounts/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from django.urls import path

from .views import SignUpView

from accounts.views import SignUpView
urlpatterns = [
path('signup/', SignUpView.as_view(), name='signup'),
]
]
38 changes: 29 additions & 9 deletions accounts/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
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.views import generic


class SignUpView(generic.CreateView):
form_class = UserCreationForm
success_url = reverse_lazy('login')
from django.contrib import messages
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})
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
user = authenticate(username=username, password=raw_password)#authenticates the user info
user.set_password(raw_password)#will set the password
user.save()#save the user in the user table
messages.success(request,f'Account created for {username}')#this will show an alert if the account is created succesfully
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.
2 changes: 0 additions & 2 deletions home/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from django.apps import AppConfig


class HomeConfig(AppConfig):
name = 'home'
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.
5 changes: 1 addition & 4 deletions home/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from django.urls import path

from .views import HomePageView


urlpatterns = [
path('', HomePageView.as_view(), name='home'),
]
]
4 changes: 1 addition & 3 deletions home/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from django.views.generic import TemplateView


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 %}
Loading