diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..363c5e6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +venv/* +.vscode \ No newline at end of file diff --git a/Linc/__init__.py b/Linc/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Linc/__pycache__/__init__.cpython-310.pyc b/Linc/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..0c19b57 Binary files /dev/null and b/Linc/__pycache__/__init__.cpython-310.pyc differ diff --git a/Linc/__pycache__/settings.cpython-310.pyc b/Linc/__pycache__/settings.cpython-310.pyc new file mode 100644 index 0000000..3f584ac Binary files /dev/null and b/Linc/__pycache__/settings.cpython-310.pyc differ diff --git a/Linc/__pycache__/urls.cpython-310.pyc b/Linc/__pycache__/urls.cpython-310.pyc new file mode 100644 index 0000000..85fe03d Binary files /dev/null and b/Linc/__pycache__/urls.cpython-310.pyc differ diff --git a/Linc/__pycache__/wsgi.cpython-310.pyc b/Linc/__pycache__/wsgi.cpython-310.pyc new file mode 100644 index 0000000..b7fa782 Binary files /dev/null and b/Linc/__pycache__/wsgi.cpython-310.pyc differ diff --git a/Linc/asgi.py b/Linc/asgi.py new file mode 100644 index 0000000..12476ad --- /dev/null +++ b/Linc/asgi.py @@ -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() diff --git a/Linc/settings.py b/Linc/settings.py new file mode 100644 index 0000000..4f37622 --- /dev/null +++ b/Linc/settings.py @@ -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' diff --git a/Linc/urls.py b/Linc/urls.py new file mode 100644 index 0000000..e3e5985 --- /dev/null +++ b/Linc/urls.py @@ -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"), +] diff --git a/Linc/wsgi.py b/Linc/wsgi.py new file mode 100644 index 0000000..5518a4f --- /dev/null +++ b/Linc/wsgi.py @@ -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() diff --git a/class.py b/class.py deleted file mode 100644 index f38a4a8..0000000 --- a/class.py +++ /dev/null @@ -1,23 +0,0 @@ -# classes - -class Email: - # __ means private - __read = False - - def __init__(self, subject, body): - self.subject = subject - self.body = body - - def mark_as_read(self): - self.__read = True - - def is_read(self): - return self.__read - - def is_spam(self): - return "you won 1 million" in self.subject - -e = Email("Check this out", "There are a bunch of free online course here: https://course.online") -print(e.is_spam()) # False -print(e.mark_as_read()) -print(e.is_read()) # True \ No newline at end of file diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..ee96ab5 Binary files /dev/null and b/db.sqlite3 differ diff --git a/i.html b/i.html new file mode 100644 index 0000000..e69de29 diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..8ee7bb8 --- /dev/null +++ b/manage.py @@ -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() diff --git a/people/__init__.py b/people/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/people/__pycache__/__init__.cpython-310.pyc b/people/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..0a73c4e Binary files /dev/null and b/people/__pycache__/__init__.cpython-310.pyc differ diff --git a/people/__pycache__/admin.cpython-310.pyc b/people/__pycache__/admin.cpython-310.pyc new file mode 100644 index 0000000..256264f Binary files /dev/null and b/people/__pycache__/admin.cpython-310.pyc differ diff --git a/people/__pycache__/apps.cpython-310.pyc b/people/__pycache__/apps.cpython-310.pyc new file mode 100644 index 0000000..3ff072f Binary files /dev/null and b/people/__pycache__/apps.cpython-310.pyc differ diff --git a/people/__pycache__/forms.cpython-310.pyc b/people/__pycache__/forms.cpython-310.pyc new file mode 100644 index 0000000..967506b Binary files /dev/null and b/people/__pycache__/forms.cpython-310.pyc differ diff --git a/people/__pycache__/models.cpython-310.pyc b/people/__pycache__/models.cpython-310.pyc new file mode 100644 index 0000000..c68a61e Binary files /dev/null and b/people/__pycache__/models.cpython-310.pyc differ diff --git a/people/__pycache__/urls.cpython-310.pyc b/people/__pycache__/urls.cpython-310.pyc new file mode 100644 index 0000000..9dd9984 Binary files /dev/null and b/people/__pycache__/urls.cpython-310.pyc differ diff --git a/people/__pycache__/views.cpython-310.pyc b/people/__pycache__/views.cpython-310.pyc new file mode 100644 index 0000000..83e9e92 Binary files /dev/null and b/people/__pycache__/views.cpython-310.pyc differ diff --git a/people/admin.py b/people/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/people/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/people/apps.py b/people/apps.py new file mode 100644 index 0000000..c2ddd3b --- /dev/null +++ b/people/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class PeopleConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'people' diff --git a/people/forms.py b/people/forms.py new file mode 100644 index 0000000..99673d4 --- /dev/null +++ b/people/forms.py @@ -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()) + \ No newline at end of file diff --git a/people/migrations/__init__.py b/people/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/people/migrations/__pycache__/__init__.cpython-310.pyc b/people/migrations/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..9bc8caf Binary files /dev/null and b/people/migrations/__pycache__/__init__.cpython-310.pyc differ diff --git a/people/models.py b/people/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/people/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/styles.css b/people/static/css/styles.css similarity index 97% rename from styles.css rename to people/static/css/styles.css index ac961ab..7ffb2be 100644 --- a/styles.css +++ b/people/static/css/styles.css @@ -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; diff --git a/people/static/images/pxfuel.jpg b/people/static/images/pxfuel.jpg new file mode 100644 index 0000000..254990a Binary files /dev/null and b/people/static/images/pxfuel.jpg differ diff --git a/people/templates/people/dashboard.html b/people/templates/people/dashboard.html new file mode 100644 index 0000000..4d3d963 --- /dev/null +++ b/people/templates/people/dashboard.html @@ -0,0 +1,12 @@ + + + + + + Document + + +

Dashboard

+ Logout + + \ No newline at end of file diff --git a/index.html b/people/templates/people/index.html similarity index 84% rename from index.html rename to people/templates/people/index.html index 7ef6183..007e28e 100644 --- a/index.html +++ b/people/templates/people/index.html @@ -1,12 +1,14 @@ - +{% load static %} + + - Webleb + Linc Softwares - +
@@ -31,8 +33,8 @@

Log In

- Login -

Forgot your password?

+ Login +

Forgot your password?

@@ -48,7 +50,7 @@

Sign Up

-
+
@@ -56,7 +58,7 @@

Sign Up

- Register + Register @@ -69,4 +71,3 @@

Sign Up

- diff --git a/people/templates/people/login.html b/people/templates/people/login.html new file mode 100644 index 0000000..0780d7b --- /dev/null +++ b/people/templates/people/login.html @@ -0,0 +1,15 @@ + + + + + + Login + + +

Login

+
+ {% csrf_token %} + {{loginform.as_p}} + + + \ No newline at end of file diff --git a/people/templates/people/register.html b/people/templates/people/register.html new file mode 100644 index 0000000..6905c81 --- /dev/null +++ b/people/templates/people/register.html @@ -0,0 +1,15 @@ + + + + + + Register + + +

Register

+ + {% csrf_token %} + {{registerform.as_p}} + + + \ No newline at end of file diff --git a/people/tests.py b/people/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/people/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/people/urls.py b/people/urls.py new file mode 100644 index 0000000..7a70950 --- /dev/null +++ b/people/urls.py @@ -0,0 +1,10 @@ +from django.urls import path, include +from . import views + +urlpatterns = [ + path('', views.homepage, name='homepage'), + path('register', views.register, name='register'), + path('login', views.login, name='login'), + path('dashboard', views.dashboard, name='dashboard'), + path('user_logout', views.user_logout, name='user_logout') +] diff --git a/people/views.py b/people/views.py new file mode 100644 index 0000000..7efdf45 --- /dev/null +++ b/people/views.py @@ -0,0 +1,52 @@ +from django.shortcuts import render, redirect +from . forms import CreateUserForm, LoginForm + +####### Django Authentication ###### +from django.contrib.auth.models import auth +from django.contrib.auth import authenticate, login, logout +from django.contrib.auth.decorators import login_required + +# Create your views here. + +def homepage(requests): + return render(requests, 'people/index.html') + + +def register(requests): + + form = CreateUserForm() + if requests.method == "POST": + form = CreateUserForm(requests.POST) + if form.is_valid(): + form.save() + return redirect('login') + context = {'registerform': form} + return render(requests, 'people/register.html', context=context) + + +def login(requests): + form = LoginForm() + + if requests.method == 'POST': + form = LoginForm(requests, data=requests.POST) + + if form.is_valid(): + username = requests.POST.get('username') + password = requests.POST.get('password') + + user = authenticate(requests, username=username, password=password) + + if user is not None: + auth.login(requests, user) + return redirect('dashboard') + + context= {'loginform': form} + return render(requests, 'people/login.html', context=context) +@login_required(login_url='login') +def dashboard(requests): + return render(requests, 'people/dashboard.html') + + +def user_logout(requests): + auth.logout(requests) + return redirect('/')