Skip to content

Commit

Permalink
django auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Collins331 committed Mar 6, 2024
1 parent 881cf8c commit 5c2b027
Show file tree
Hide file tree
Showing 37 changed files with 358 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
venv/*
.vscode
Empty file added Linc/__init__.py
Empty file.
Binary file added Linc/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added Linc/__pycache__/settings.cpython-310.pyc
Binary file not shown.
Binary file added Linc/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file added Linc/__pycache__/wsgi.cpython-310.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions Linc/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for Linc project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Linc.settings')

application = get_asgi_application()
130 changes: 130 additions & 0 deletions Linc/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
"""
Django settings for Linc project.
Generated by 'django-admin startproject' using Django 5.0.3.
For more information on this file, see
https://docs.djangoproject.com/en/5.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.0/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-ez&ty*!+s@(5)lmltzjb^i&avblpabsaqtsbw@bupy#dnhbl7u'

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

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'people',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'Linc.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'Linc.wsgi.application'


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

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}

AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.ModelBackend",
"sesame.backends.ModelBackend",
]

LOGIN_REDIRECT_URL = 'dashboard'

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

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


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

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
26 changes: 26 additions & 0 deletions Linc/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
URL configuration for Linc project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/5.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
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 sesame.views import LoginView


urlpatterns = [
path('secretadmin/', admin.site.urls),
path('', include('people.urls')),
path("sesame/login/", LoginView.as_view(), name="sesame-login"),
]
16 changes: 16 additions & 0 deletions Linc/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for Linc project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Linc.settings')

application = get_wsgi_application()
23 changes: 0 additions & 23 deletions class.py

This file was deleted.

Binary file added db.sqlite3
Binary file not shown.
Empty file added i.html
Empty file.
22 changes: 22 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Linc.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
Empty file added people/__init__.py
Empty file.
Binary file added people/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added people/__pycache__/admin.cpython-310.pyc
Binary file not shown.
Binary file added people/__pycache__/apps.cpython-310.pyc
Binary file not shown.
Binary file added people/__pycache__/forms.cpython-310.pyc
Binary file not shown.
Binary file added people/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file added people/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file added people/__pycache__/views.cpython-310.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions people/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions people/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class PeopleConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'people'
17 changes: 17 additions & 0 deletions people/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from django.contrib.auth.models import User
from django import forms
from django.forms.widgets import PasswordInput, TextInput

###### Register user ######
class CreateUserForm(UserCreationForm):
class Meta:
model = User
fields = ['first_name', 'last_name', 'username', 'email', 'password1', 'password2']

#### Authenticate User ######

class LoginForm(AuthenticationForm):
username = forms.CharField(widget=TextInput())
password = forms.CharField(widget=PasswordInput())

Empty file added people/migrations/__init__.py
Empty file.
Binary file not shown.
3 changes: 3 additions & 0 deletions people/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
2 changes: 1 addition & 1 deletion styles.css → people/static/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ display: none;
width: 100%;
height: 100%;
background-color: #2b2e38;
background-image: url('/img/pattern_japanese-pattern-2_1_2_0-0_0_1__ffffff00_000000.png');
background-image: url('../images/pxfuel.png');
position: absolute;
border-radius: 6px;
-webkit-transform-style: preserve-3d;
Expand Down
Binary file added people/static/images/pxfuel.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions people/templates/people/dashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Dashboard</h1>
<a href='{% url "user_logout" %}'>Logout</a>
</body>
</html>
17 changes: 9 additions & 8 deletions index.html → people/templates/people/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<!doctype html>
{% load static %}

<!DOCTYPE html>
<html lang="en">
<head>
<title>Webleb</title>
<title>Linc Softwares</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://unicons.iconscout.com/release/v2.1.9/css/unicons.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
</head>
<body>
<div class="section">
Expand All @@ -31,8 +33,8 @@ <h4 class="mb-4 pb-3">Log In</h4>
<input type="password" class="form-style" placeholder="Password">
<i class="input-icon uil uil-lock-alt"></i>
</div>
<a href="https://www.web-leb.com/code" class="btn mt-4">Login</a>
<p class="mb-0 mt-4 text-center"><a href="https://www.web-leb.com/code" class="link">Forgot your password?</a></p>
<a href="{% url 'login' %}" class="btn mt-4">Login</a>
<p class="mb-0 mt-4 text-center"><a href="{% url 'register' %}" class="link">Forgot your password?</a></p>
</div>
</div>
</div>
Expand All @@ -48,15 +50,15 @@ <h4 class="mb-3 pb-3">Sign Up</h4>
<input type="tel" class="form-style" placeholder="Phone Number">
<i class="input-icon uil uil-phone"></i>
</div>
<div class="form-group mt-2">
<div class="form-group mt-2">
<input type="email" class="form-style" placeholder="Email">
<i class="input-icon uil uil-at"></i>
</div>
<div class="form-group mt-2">
<input type="password" class="form-style" placeholder="Password">
<i class="input-icon uil uil-lock-alt"></i>
</div>
<a href="https://www.web-leb.com/code" class="btn mt-4">Register</a>
<a href="{% url 'register' %}" class="btn mt-4">Register</a>
</div>
</div>
</div>
Expand All @@ -69,4 +71,3 @@ <h4 class="mb-3 pb-3">Sign Up</h4>
</div>
</body>
</html>

15 changes: 15 additions & 0 deletions people/templates/people/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
</head>
<body>
<h1>Login</h1>
<form method='POST', autocomplete='off'>
{% csrf_token %}
{{loginform.as_p}}
<input type='Submit' value="Login"/>
</body>
</html>
15 changes: 15 additions & 0 deletions people/templates/people/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register</title>
</head>
<body>
<h1>Register</h1>
<form method='POST', autocomplete='off'>
{% csrf_token %}
{{registerform.as_p}}
<input type='Submit' value="Register"/>
</body>
</html>
3 changes: 3 additions & 0 deletions people/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.
Loading

0 comments on commit 5c2b027

Please sign in to comment.