-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from tamirmatok/login-page
Add login page
- Loading branch information
Showing
14 changed files
with
36,999 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ name = "pypi" | |
|
||
[packages] | ||
django = "*" | ||
django-crispy-forms = "*" | ||
pytest = "*" | ||
|
||
[dev-packages] | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{% extends "main/base_template.html" %} | ||
{% load crispy_forms_tags %} | ||
{% load static %} | ||
|
||
{% block stylesheets %} | ||
<!-- Bootstrap core CSS --> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" | ||
integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous"> | ||
<link rel="stylesheet" type="text/css" href="{% static 'css/login.css' %}"> | ||
<title>Hotails.com - Login!</title> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
|
||
<section> | ||
<div class="text-box"> | ||
<h1>Login now!</h1> | ||
<div class="card" style="color: rgb(0, 0, 0); background: rgba(252, 252, 252, 0.3); width: 500px;"> | ||
<div class="card-body"> | ||
<form method="POST"> | ||
{% csrf_token %} | ||
<fieldset class="form-group"> | ||
{{form|crispy}} | ||
</fieldset> | ||
<div class="form-group"> | ||
<button class="btn btn-primary mt-3" type="submit">Lets Go!</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" | ||
integrity="sha384-p34f1UUtsS3wqzfto5wAAmdvj+osOnFyQFpp4Ua3gs/ZVWx6oOypYoCJhGGScy+8" | ||
crossorigin="anonymous"></script> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,89 @@ | ||
import pytest | ||
from dogowner.models import DogOwner | ||
|
||
|
||
@pytest.fixture | ||
def create_dog_owner_user(): | ||
return DogOwner.create(email='[email protected]', | ||
username='dogOwnerUser01', | ||
password='password123', | ||
dog_name='dog name', | ||
first_name='test', | ||
last_name='user', | ||
phone_number=1234567890, | ||
dog_race='dog race', | ||
dog_picture_url='https://www.google.com/user1.jpg', | ||
dog_age=4, | ||
dog_weight=2, | ||
dog_gender='M' | ||
) | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestViews: | ||
class TestAboutView: | ||
def test_redirected_to_about_section(self, client): | ||
response = client.get('/about') | ||
assert response.status_code == 301 | ||
response = client.get(response.url) | ||
assert response.status_code == 200 | ||
|
||
def test_redirected_to_homepage(self, client): | ||
response = client.get('') | ||
|
||
@pytest.mark.django_db | ||
class TestLoginView: | ||
def test_enter_login_page(self, client): | ||
response = client.get('/login/') | ||
assert response.status_code == 200 | ||
|
||
def test_valid_login_dog_owner_user_info(self, client, create_dog_owner_user): | ||
previous_logged_user = client.get('/').wsgi_request.user | ||
form = {'username': 'dogOwnerUser01', | ||
'password': 'password123', | ||
} | ||
|
||
response = client.post('/login/', form, follow=True) | ||
current_log_user = response.wsgi_request.user | ||
assert current_log_user == create_dog_owner_user.user | ||
assert previous_logged_user != current_log_user | ||
|
||
def test_invalid_login_dog_owner_user_info(self, client): | ||
form = {'username': "[email protected]", | ||
'password': "incorrect", | ||
} | ||
response = client.post('/login/', form, follow=True) | ||
assert response.wsgi_request.user.is_anonymous | ||
|
||
def test_block_logged_user_from_login_page(self, client, create_dog_owner_user): | ||
client.force_login(user=create_dog_owner_user.user) | ||
response = client.get("/login/") | ||
assert response['Location'] == '/' | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestLogoutView: | ||
def test_successful_logout(self, client, create_dog_owner_user): | ||
client.force_login(user=create_dog_owner_user.user) | ||
logged_user = client.get('/').wsgi_request.user | ||
response = client.get('/logout/') | ||
assert response['Location'] == '/login/' | ||
assert response.wsgi_request.user != logged_user | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestIndexView: | ||
def test_root_entrypoint_redirection_unlogged_user(self, client): | ||
response = client.get("/") | ||
assert response.status_code == 302 | ||
assert response['Location'] == '/login/' | ||
|
||
def test_root_entrypoint_redirection_logged_user(self, client, create_dog_owner_user): | ||
client.force_login(user=create_dog_owner_user.user) | ||
response = client.get("/") | ||
assert response.status_code == 302 | ||
assert response['Location'] == '/homepage/' | ||
|
||
|
||
class TestHomepageView: | ||
def test_unlogged_user_access_to_homepage(self, client): | ||
response = client.get("/homepage/") | ||
assert response.status_code == 302 | ||
assert response['Location'] == '/login/?next=/homepage/' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
from django.shortcuts import render | ||
from django.contrib.auth.decorators import login_required | ||
from django.shortcuts import redirect | ||
from django.contrib.auth import logout | ||
|
||
|
||
def index(request): | ||
if request.user.is_authenticated: | ||
return redirect(to='homepage') | ||
|
||
return redirect(to='login') | ||
|
||
|
||
@login_required() | ||
def homepage(request): | ||
return render(request, 'main/homepage.html') | ||
|
||
|
||
def about(request): | ||
return render(request, 'main/about.html') | ||
|
||
|
||
def logout_view(request): | ||
logout(request) | ||
return index(request) |
Oops, something went wrong.