diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f874641 --- /dev/null +++ b/.travis.yml @@ -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 + \ No newline at end of file diff --git a/Argon/settings.py b/Argon/settings.py index 2d59599..07f1839 100644 --- a/Argon/settings.py +++ b/Argon/settings.py @@ -33,6 +33,7 @@ INSTALLED_APPS = [ 'home.apps.HomeConfig', 'accounts.apps.AccountsConfig', + 'crispy_forms', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -122,4 +123,7 @@ STATIC_URL = '/static/' LOGIN_REDIRECT_URL = 'home' -LOGOUT_REDIRECT_URL = 'home' \ No newline at end of file + +LOGOUT_REDIRECT_URL = 'home' + +CRISPY_TEMPLATE_PACK = 'bootstrap4' diff --git a/Argon/urls.py b/Argon/urls.py index 79a45fe..3164db1 100644 --- a/Argon/urls.py +++ b/Argon/urls.py @@ -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'), ] diff --git a/README.md b/README.md index 9d583c8..b3f09a7 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# Argon \ No newline at end of file +# Argon diff --git a/accounts/admin.py b/accounts/admin.py index 8c38f3f..4f57ae9 100644 --- a/accounts/admin.py +++ b/accounts/admin.py @@ -1,3 +1,2 @@ from django.contrib import admin - # Register your models here. diff --git a/accounts/forms.py b/accounts/forms.py new file mode 100644 index 0000000..5a8c0fe --- /dev/null +++ b/accounts/forms.py @@ -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',) diff --git a/accounts/models.py b/accounts/models.py index 71a8362..ca200a0 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -1,3 +1,2 @@ from django.db import models - # Create your models here. diff --git a/accounts/tests.py b/accounts/tests.py index 7ce503c..9331e78 100644 --- a/accounts/tests.py +++ b/accounts/tests.py @@ -1,3 +1,2 @@ from django.test import TestCase - # Create your tests here. diff --git a/accounts/urls.py b/accounts/urls.py index 3cd99a8..0c93007 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -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'), - ] \ No newline at end of file +] diff --git a/accounts/views.py b/accounts/views.py index 1068239..8d460bb 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -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) + # + 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}) diff --git a/db.sqlite3 b/db.sqlite3 index 5f72dbd..e41c709 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/home/admin.py b/home/admin.py index 8c38f3f..4f57ae9 100644 --- a/home/admin.py +++ b/home/admin.py @@ -1,3 +1,2 @@ from django.contrib import admin - # Register your models here. diff --git a/home/models.py b/home/models.py index 71a8362..ca200a0 100644 --- a/home/models.py +++ b/home/models.py @@ -1,3 +1,2 @@ from django.db import models - # Create your models here. diff --git a/home/tests.py b/home/tests.py index 7ce503c..9331e78 100644 --- a/home/tests.py +++ b/home/tests.py @@ -1,3 +1,2 @@ from django.test import TestCase - # Create your tests here. diff --git a/home/urls.py b/home/urls.py index 133fae6..141715f 100644 --- a/home/urls.py +++ b/home/urls.py @@ -1,8 +1,7 @@ from django.urls import path - from .views import HomePageView urlpatterns = [ path('', HomePageView.as_view(), name='home'), - ] \ No newline at end of file +] diff --git a/home/views.py b/home/views.py index a99a422..72569da 100644 --- a/home/views.py +++ b/home/views.py @@ -2,4 +2,4 @@ class HomePageView(TemplateView): - template_name = 'home.html' \ No newline at end of file + template_name = 'home.html' diff --git a/requirements.txt b/requirements.txt index c9b752b..4f8fd3e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ Django==2.0.1 -pkg-resources==0.0.0 pytz==2019.1 sqlparse==0.3.0 diff --git a/templates/base.html b/templates/base.html index 56eb78a..f5973ff 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,16 +1,26 @@ - + {% load staticfiles %} + + + + Argon

Argon

+ + {% if messages %} + {% for message in messages %} +
+ {{message}} +
+ {% endfor %} + {% endif %}
{% block content %} - {% endblock content %}
- \ No newline at end of file diff --git a/templates/home.html b/templates/home.html index 7c958ae..c86dde2 100644 --- a/templates/home.html +++ b/templates/home.html @@ -1,10 +1,6 @@ {% extends 'base.html' %} - {% block content %} - -

This is HomePage.

- -

Login

-

SignUp

+

This is HomePage

+

Login

+

SignUp

{% endblock content %} - diff --git a/templates/registration/login.html b/templates/registration/login.html index 4106d71..1548252 100644 --- a/templates/registration/login.html +++ b/templates/registration/login.html @@ -1,12 +1,22 @@ {% extends 'base.html' %} - +{% load crispy_forms_tags %} {% block content %} - -

Log In

-
- {% csrf_token %} - {{ form.as_p }} - -
- -{% endblock content %} \ No newline at end of file +
+
+
+
+
+
+
+ {% csrf_token %} +

Log In

+ {{ form|crispy }} + +
+
+
+
+
+
+
+{% endblock content %} diff --git a/templates/signup.html b/templates/signup.html index 9982a8b..cf74820 100644 --- a/templates/signup.html +++ b/templates/signup.html @@ -1,26 +1,22 @@ - {% extends 'base.html' %} - +{% load crispy_forms_tags %} {% block content %} - - - -

Sign up

- -
- {% csrf_token %} - {{ form.as_p }} - -

- -

- -

- - -

-
- - - -{% endblock content %} \ No newline at end of file +
+
+ +
+
+ +
+
+ {% csrf_token %} +

Sign up

+ {{ form|crispy }} +

+
+
+
+
+
+
+{% endblock content %}