Skip to content

Commit

Permalink
Fix login
Browse files Browse the repository at this point in the history
  • Loading branch information
yaelnoyman1 committed Jan 19, 2023
1 parent 25bce95 commit 20983f1
Show file tree
Hide file tree
Showing 25 changed files with 162 additions and 146 deletions.
Empty file removed accounts/__init__.py
Empty file.
6 changes: 0 additions & 6 deletions accounts/apps.py

This file was deleted.

30 changes: 0 additions & 30 deletions accounts/migrations/0001_initial.py

This file was deleted.

33 changes: 0 additions & 33 deletions accounts/migrations/0002_test_data.py

This file was deleted.

Empty file removed accounts/migrations/__init__.py
Empty file.
8 changes: 0 additions & 8 deletions accounts/models.py

This file was deleted.

Binary file removed accounts/static/builtin_avatars/man1.png
Binary file not shown.
Binary file removed accounts/static/builtin_avatars/man2.png
Binary file not shown.
Binary file removed accounts/static/builtin_avatars/man3.png
Binary file not shown.
Binary file removed accounts/static/builtin_avatars/woman1.png
Binary file not shown.
Binary file removed accounts/static/builtin_avatars/woman2.png
Binary file not shown.
36 changes: 0 additions & 36 deletions accounts/templates/login/login.html

This file was deleted.

18 changes: 0 additions & 18 deletions accounts/views.py

This file was deleted.

3 changes: 1 addition & 2 deletions finalProject_g4/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'projboard.apps.ProjboardConfig',
'accounts.apps.AccountsConfig'
'projboard.apps.ProjboardConfig'

]

Expand Down
7 changes: 4 additions & 3 deletions finalProject_g4/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
from django.contrib import admin
from django.urls import path
from projboard import views
from accounts.views import login_form
from django.contrib.auth.views import LogoutView

urlpatterns = [
path('admin/', admin.site.urls),
Expand All @@ -29,7 +27,10 @@
path('signup/', views.sign_up, name='signup'),
path('article/<str:user_nickname>/<str:article_pk>/', views.show_article, name='show_article'),
path('edit_article/<str:article_pk>/', views.edit_article, name='edit_article'),
path('delete_article/<str:article_pk>/', views.delete_article, name='delete_article')
path('delete_article/<str:article_pk>/', views.delete_article, name='delete_article'),
path('logout/', views.logout_user, name='logout'),
path('login/', views.login_user, name="login")

]

handler404 = views.error_404
15 changes: 14 additions & 1 deletion projboard/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django import forms
from .models.article import Article
from projboard.models.user import User
from django.contrib.auth.models import User as Custom_user
from .models.user import User


class CreateArticleForm(forms.ModelForm):
Expand Down Expand Up @@ -42,3 +43,15 @@ class EditArticleForm(forms.ModelForm):
class Meta:
model = Article
fields = ('title', 'subject_id', 'content')


class UserForm(forms.ModelForm):
class Meta:
model = Custom_user
fields = ('username', 'password', 'email')


class CustomUserForm(forms.ModelForm):
class Meta:
model = User
fields = ('nickname', 'name')
5 changes: 4 additions & 1 deletion projboard/migrations/0004_test_user_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ class Migration(migrations.Migration):

dependencies = [
('projboard', '0003_alter_article_subject_id'),
('projboard', '0009_user_user1'),
]

def generate_user_data(apps, schema_editor):
from projboard.models.user import User
from django.contrib.auth.models import User as Custom_user

test_data = [
['[email protected]', '123456', 'John Doe', 'User1'],
Expand All @@ -20,7 +22,8 @@ def generate_user_data(apps, schema_editor):
]
with transaction.atomic():
for u in test_data:
User(email=u[0], password=u[1], name=u[2], nickname=u[3]).save()
user = Custom_user.objects.create_user(username=u[3], password=u[1])
User(email=u[0], password=u[1], name=u[2], nickname=u[3], user1=user).save()

operations = [
migrations.RunPython(generate_user_data),
Expand Down
22 changes: 22 additions & 0 deletions projboard/migrations/0009_user_user1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.1.3 on 2023-01-19 17:20

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


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('projboard', '0003_alter_article_subject_id'),
]

operations = [
migrations.AddField(
model_name='user',
name='user1',
field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL),
),
]
2 changes: 2 additions & 0 deletions projboard/models/user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models
from django.contrib.auth.models import User as Custom_user


class User(models.Model):
Expand All @@ -9,6 +10,7 @@ class User(models.Model):
name- User's name
nickname- User's nickname
"""
user1 = models.OneToOneField(Custom_user, on_delete=models.CASCADE, null=True)
email = models.EmailField(max_length=150, unique=True)
password = models.CharField(max_length=70)
name = models.CharField(max_length=100)
Expand Down
15 changes: 15 additions & 0 deletions projboard/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.db.models.signals import post_save
from django.contrib.auth.models import User as Custom_user
from django.dispatch import receiver
from models.user import User


@receiver(post_save, sender=Custom_user)
def create_custom_user(sender, instance, created, **kwargs):
if created:
User.objects.create(user=instance)


@receiver(post_save, sender=Custom_user)
def save_custom_user(sender, instance, **kwargs):
instance.User.save()
5 changes: 2 additions & 3 deletions projboard/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,15 @@
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="accountDisplay" role="button"
data-bs-toggle="dropdown" aria-expanded="false">
<img src="{{ request.user.account.avatar_url }}" width="26">
Welcome {{ request.user.get_username }}!
</a>
<ul class="dropdown-menu" aria-labelledby="accountDisplay">
<li><a class="dropdown-item" href="{% url 'logout' %}">Logout</a></li>
<li><a class="dropdown-item" href="/logout">Logout</a></li>
</ul>
</li>
{% else %}
<li class="nav-item">
<a class="nav-link" href="{% url 'login' %}?next={{request.path}}">Login</a>
<a class="nav-link" href="/login">Login</a>
</li>
{% endif %}
</ul>
Expand Down
45 changes: 45 additions & 0 deletions projboard/templates/login/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{% extends 'base.html' %}
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'css/authentication.css' %}">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" integrity="sha384-gfdkjb5BdAXd+lj+gudLWI+BXq4IuLW5IT+brZEZsLFm++aCMlF1V92rMkPaX4PP" crossorigin="anonymous">
{% block content %}
<div class="container h-100">
<div class="d-flex justify-content-center h-100">
<div class="user_card">
<div class="d-flex justify-content-center">
<h1 id="form-title">LOGIN</h1>
</div>
<div class="d-flex justify-content-center form_container">
<form method="POST" action="">
{% csrf_token %}
<div class="input-group mb-3">
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-user"></i></span>
</div>
<input type="text" name="username" placeholder="Username..." class="form-control">
</div>
<div class="input-group mb-2">
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-key"></i></span>
</div>
<input type="password" name="password" placeholder="Password..." class="form-control" >
</div>
{% for message in messages %}
<p id="messages">{{ message }}</p>
{% endfor %}
<div class="d-flex justify-content-center mt-3 login_container">
<input class="btn login_btn" type="submit" value="Login">
</div>
</form>

</div>
<div class="mt-4">
<div class="d-flex justify-content-center links">
Don't have an account? <a href="#" class="ml-2">Sign Up</a>
</div>

</div>
</div>
</div>
</div>
{% endblock %}
1 change: 0 additions & 1 deletion projboard/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
from projboard.models.article import Article, User, View_Article, Like, Subject


TITLE = "Article Test"
CONTENT = "I'm not gonna write all that!"
VALID_USER = "smarticleUser"
Expand Down
6 changes: 3 additions & 3 deletions projboard/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,13 @@ def test_edit_article_form():


def test_login(client):
response = client.get('/accounts/login/')
response = client.get('/login/')
assert response.status_code == 200
template_names = set(tmpl.origin.template_name for tmpl in response.templates)
assert 'login/login.html' in template_names


def test_logout(client):
response = client.post('/accounts/logout/')
response = client.post('/logout/')
assert response.status_code == 302
assert response.url == '/'
assert response.url == '/login/'
Loading

0 comments on commit 20983f1

Please sign in to comment.