Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] User Creation and Login #16

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#IDE files
.idea/

#environment files
env/
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# pykla-web
The official website for Python Kampla (PyKla)

Login for pykla website. Django version 2.1.3.
To get reset password email, use the following command in the shell. python -m smtpd -n -c DebuggingServer localhost:1025
File renamed without changes.
Binary file added pykla/accounts/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added pykla/accounts/__pycache__/admin.cpython-36.pyc
Binary file not shown.
Binary file added pykla/accounts/__pycache__/forms.cpython-36.pyc
Binary file not shown.
Binary file added pykla/accounts/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file added pykla/accounts/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file added pykla/accounts/__pycache__/views.cpython-36.pyc
Binary file not shown.
6 changes: 6 additions & 0 deletions pykla/accounts/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.contrib import admin
from .models import UserProfile

# Register your models here.

admin.site.register(UserProfile)
5 changes: 5 additions & 0 deletions pykla/accounts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class AccountsConfig(AppConfig):
name = 'accounts'
32 changes: 32 additions & 0 deletions pykla/accounts/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django.contrib.auth.models import User

class RegForm(UserCreationForm):
email = forms.EmailField(required=True)

class Meta:
model = User
fields = [
'username','first_name','last_name','email','password1', 'password2'
]

def save(self, commit=True):
user = super(RegForm, self).save(commit=False)
user.first_name = forms.cleaned_data('first_name')
user.last_name = forms.cleaned_data('last_name')
user.email = forms.cleaned_data('email')


if commit:
user.save()

return user

#edit user profile
class EditProfile(UserChangeForm):
class Meta:
model = User
fields = [
'username', 'first_name', 'last_name','password'
]
29 changes: 29 additions & 0 deletions pykla/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 2.1.3 on 2019-01-14 13:39

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='UserProfile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=20)),
('last_name', models.CharField(max_length=20)),
('username', models.CharField(max_length=20)),
('tel', models.IntegerField(default=0)),
('email', models.EmailField(max_length=254)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
Empty file.
Binary file not shown.
Binary file not shown.
23 changes: 23 additions & 0 deletions pykla/accounts/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save

# user profile model
class UserProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
username = models.CharField(max_length=20)
tel = models.IntegerField(default=0)
email = models.EmailField()

def __str__(self):
return '%s - %s - %s' %(self.username, self.first_name, self.tel)

# method creating user profile. Uses django signal to save user after being created
def create_profile(sender, **kwargs ):
if kwargs['created']:
UserProfile.objects.create(user=kwargs['instance'])

post_save.connect(create_profile, sender=User)

16 changes: 16 additions & 0 deletions pykla/accounts/templates/acc/edit_pass.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{%extends 'base.html'%}

{%block body%}
<div class="container">
<h1>Password reset</h1>
<p>
Forgotten your password? Enter your email address below, and we'll email instructions for setting a new one.
</p>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Reset password</button>
</form>
</div>

{% endblock%}
10 changes: 10 additions & 0 deletions pykla/accounts/templates/acc/edit_pro.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{%extends 'base.html'%}

{% block body%}
<form method="POST">
{%csrf_token%}
{{form.as_p}}
<button class="btn btn-primary" type="submit">Submit</button>
</form>

{% endblock%}
11 changes: 11 additions & 0 deletions pykla/accounts/templates/acc/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'base.html'%}

{% block body%}
<div>
<form method="post">
{% csrf_token %}
{{form.as_p}}
<button type="submit">Login</button>
</form>
</div>
{%endblock%}
7 changes: 7 additions & 0 deletions pykla/accounts/templates/acc/logout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends 'base.html'%}

{% block body%}
<h2>
Logged out!!!
</h2>
{% endblock %}
14 changes: 14 additions & 0 deletions pykla/accounts/templates/acc/pass_reset.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends 'base.html'%}

{%block body%}
<div>
<form method="POST">
{% csrf_token%}
{{form.as_p}}
<button class="btn btn-primary" type="submit">Request Password Reset</button>

</form>

</div>

{%endblock%}
8 changes: 8 additions & 0 deletions pykla/accounts/templates/acc/password_reset_complete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends 'base.html'%}

{% block body %}
<div class="alert alert-info">Your password has been reset</div>

<a href="{% url 'login'%}">Sign in here</a>

{% endblock %}
10 changes: 10 additions & 0 deletions pykla/accounts/templates/acc/password_reset_confirm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{%extends 'base.html'%}

{%block body%}
<form method="POST">
{% csrf_token%}
{{form.as_p}}
<button class="btn btn-outline-info" type="submit">Reset Password</button>
</form>

{%endblock%}
6 changes: 6 additions & 0 deletions pykla/accounts/templates/acc/password_reset_done.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends 'base.html'%}

{% block body %}
<div class="alert alert-info">A PASSWORD RESET CODE HAS BEEN SENT TO YOUR EMAIL</div>

{% endblock %}
15 changes: 15 additions & 0 deletions pykla/accounts/templates/acc/profile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends 'base.html'%}

{% block body%}
<div class="container">
<p>

{{user}}
{{user.first_name}}
{{user.last_name}}

</p>
<a href="{%url 'edit_profile'%}">EDIT</a>
</div>

{% endblock%}
10 changes: 10 additions & 0 deletions pykla/accounts/templates/acc/reg.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends 'base.html'%}

{% block body%}
<form method="post">
{%csrf_token%}
{{form.as_p}}
<button type="submit">Submit</button>
</form>

{% endblock%}
65 changes: 65 additions & 0 deletions pykla/accounts/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

{% block head%}
<meta charset="UTF-8">

<title>Pykla</title>

{% endblock %}

</head>

<body>

<nav class="navbar navbar-expand-lg navbar-light" style="background-color: #e3f2fd;">
<a class="navbar-brand" href="{% url 'index'%}">Pykla</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarSupportedContent">
{% if user.is_authenticated%}
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="{% url 'index'%}">HOME <span class="sr-only"></span></a>
</li>
<li>
<a class="nav-link" href="{%url 'profile'%}">PROFILE</a>
</li>
<li>
<a class="nav-link" href="{% url 'edit_pass'%}">EDIT PASSWORD</a>
</li>
<li>
<a class="nav-link" href="{% url 'logout'%}">LOGOUT</a>
</li>
</ul>
{%else%}

<ul class="navbar-nav mr-auto nav-right">
<li class="nav-item">
<a class="nav-link" href="{% url 'index'%}">HOME <span class="sr-only"></span></a>
</li>
<li>
<a class="nav-link" href="{% url 'login'%}">LOGIN</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'register'%}">REGISTER</a>
</li>
</ul>
{%endif%}

</div>
</nav>

<div class="">
{% block body%}
<h2>Home</h2>
{% endblock%}
</div>


</body>
</html>
3 changes: 3 additions & 0 deletions pykla/accounts/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dru94 could you add a few tests

31 changes: 31 additions & 0 deletions pykla/accounts/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django.urls import path
from django.conf.urls import url
from . import views
from django.contrib.auth.views import LoginView,LogoutView, PasswordResetView, PasswordResetDoneView, \
PasswordResetConfirmView, PasswordResetCompleteView

urlpatterns=[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dru94 what do you think about using social login instead, I'm thinking maybe GitHub and Google. I suggest you use Django Allauth but you can suggest any other package that does the same thing

path('', views.index, name='index'),
path('register/', views.reg, name='register'),
path('login/', LoginView.as_view(template_name='acc/login.html'), name='login'),

path('logout/', LogoutView.as_view(template_name='acc/logout.html'),name='logout'),

path('profile/', views.profile, name='profile'),

path('profile/edit', views.edit_profile, name='edit_profile'),

path('edit_password/', views.edit_pass, name='edit_pass'),

path('password/', PasswordResetView.as_view(template_name='acc/pass_reset.html'),name='pass_reset'),

url(r'^reset-password/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', PasswordResetConfirmView.as_view(),
{'template_name': 'accounts/reset_password_confirm.html',
'post_reset_redirect': 'accounts:password_reset_complete'}, name='password_reset_confirm'),

path('password-reset/done/',PasswordResetDoneView.as_view(template_name='acc/password_reset_done.html'),
name='password_reset_done'),

path('password-reset-complete/', PasswordResetCompleteView.as_view(template_name='acc/password_reset_complete.html'),
name='password_reset_complete'),
]
Loading