-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fm
committed
Oct 10, 2022
1 parent
f89515d
commit bbf1763
Showing
27 changed files
with
500 additions
and
22 deletions.
There are no files selected for viewing
Empty file.
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,16 @@ | ||
""" | ||
ASGI config for aahizz 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/3.2/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'aahizz.settings') | ||
|
||
application = get_asgi_application() |
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,127 @@ | ||
""" | ||
Django settings for aahizz project. | ||
Generated by 'django-admin startproject' using Django 3.2. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/3.2/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/3.2/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/3.2/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = 'django-insecure-8tt3$#%3ur&h6u7#7xw_=u6aj7h2^kln6fm3%*)g8^_3#kj2h)' | ||
|
||
# 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', | ||
'users', | ||
] | ||
|
||
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 = 'aahizz.urls' | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [BASE_DIR / "templates",], | ||
'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 = 'aahizz.wsgi.application' | ||
|
||
# Database | ||
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases | ||
# ENGINE_DEFAULT = 'django.db.backends.mysql' | ||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': BASE_DIR / 'db.sqlite3', | ||
# 'HOST': os.environ.get('LOCAL_DB_HOST'), | ||
# 'NAME': os.environ.get('LOCAL_DB_NAME'), | ||
# 'USER': os.environ.get('LOCAL_DB_USER'), | ||
# 'PASSWORD': os.environ.get('LOCAL_DB_PASS'), | ||
|
||
} | ||
} | ||
|
||
# Password validation | ||
# https://docs.djangoproject.com/en/3.2/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/3.2/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/3.2/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' | ||
|
||
# Default primary key field type | ||
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field | ||
|
||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' | ||
|
||
AUTH_USER_MODEL = "users.User" |
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,31 @@ | ||
"""aahizz URL Configuration | ||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/3.2/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 include, path | ||
from users.views import ( | ||
login_view, | ||
logout_view, | ||
register_view | ||
) | ||
|
||
urlpatterns = [ | ||
path('users', include('users.urls')), | ||
path('admin/', admin.site.urls), | ||
|
||
path('login/', login_view), | ||
path('logout/', logout_view), | ||
path('register/', register_view), | ||
] |
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,16 @@ | ||
""" | ||
WSGI config for aahizz 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/3.2/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'aahizz.settings') | ||
|
||
application = get_wsgi_application() |
Binary file not shown.
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,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', 'aahizz.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() |
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,36 @@ | ||
{% load static %} | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<!-- Required meta tags --> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
|
||
<!-- Bootstrap CSS --> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous"> | ||
|
||
|
||
<script src="https://unpkg.com/[email protected]"></script> | ||
<!-- <link rel='stylesheet' href='{% static "recipes/recipes-htmx.css" %}' />--> | ||
</head> | ||
<body> | ||
{% include 'navbar.html' %} | ||
|
||
<div class='container'> | ||
|
||
{% block content %} | ||
<h3>This will be replaced</h3> | ||
{% endblock content %} | ||
</div> | ||
|
||
|
||
<!-- Option 1: Bootstrap Bundle with Popper --> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script> | ||
|
||
<script> | ||
document.body.addEventListener("htmx:configRequest", (event)=>{ | ||
event.detail.headers['X-CSRFToken'] = '{{ csrf_token }}' | ||
}) | ||
</script> | ||
</body> | ||
</html> |
Empty file.
Empty file.
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,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
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,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class UsersConfig(AppConfig): | ||
name = 'users' |
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 @@ | ||
# Generated by Django 3.2 on 2022-10-10 21:17 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('auth', '0012_alter_user_first_name_max_length'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='User', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('password', models.CharField(max_length=128, verbose_name='password')), | ||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), | ||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), | ||
('email', models.EmailField(max_length=255, unique=True)), | ||
('firstname', models.CharField(default=None, max_length=255, null=True)), | ||
('surname', models.CharField(default=None, max_length=255, null=True)), | ||
('name', models.CharField(default=None, max_length=255, null=True)), | ||
('is_active', models.BooleanField(default=True)), | ||
('is_staff', models.BooleanField(default=False)), | ||
('avatar', models.ImageField(blank=True, default=None, null=True, upload_to='')), | ||
('telephone', models.CharField(blank=True, default=None, max_length=20, null=True)), | ||
('created_at', models.DateTimeField(auto_now_add=True, null=True)), | ||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')), | ||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] |
Empty file.
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,70 @@ | ||
from django.db import models | ||
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin | ||
from django.contrib.auth.models import Permission | ||
from django.contrib.contenttypes.models import ContentType | ||
from rest_framework.exceptions import APIException | ||
from django.conf import settings | ||
from django.contrib import admin | ||
|
||
|
||
class UserManager(BaseUserManager): | ||
|
||
def create_user(self, email, password, **extra_fields): | ||
"""Creates and saves a new user""" | ||
groups = extra_fields.pop('groups', None) | ||
if not email: | ||
raise ValueError('Users must have an email address') | ||
|
||
user = self.model(email=self.normalize_email(email), **extra_fields) | ||
user.set_password(password) | ||
user.is_active = True | ||
user.save() | ||
if groups: | ||
for group in groups: | ||
user.groups.add(group) | ||
user.save() | ||
return user | ||
|
||
def create_superuser(self, email, password): | ||
|
||
"""Creates and saves a new super user""" | ||
user = self.create_user(email, password) | ||
user.is_staff = True | ||
user.is_superuser = True | ||
user.save() | ||
return user | ||
|
||
def _assign_customer_based_permissions(self, user, customer_obj): | ||
customer_obj.customer_users.add(user) | ||
customer_obj.save() | ||
|
||
content_type_customer = ContentType.objects.get_for_model(Customer) | ||
all_prop_permissions = Permission.objects.filter(content_type=content_type_customer) | ||
for perm in all_prop_permissions: | ||
assign_perm(perm.codename, user, customer_obj) | ||
|
||
UserCustomerRole.objects.create(customer=customer_obj, user=user, user_type="OWNER") | ||
|
||
class User(AbstractBaseUser, PermissionsMixin): | ||
"""User model for auth""" | ||
|
||
email = models.EmailField(max_length=255, unique=True) | ||
firstname = models.CharField(max_length=255, null=True, default=None) | ||
surname = models.CharField(max_length=255, null=True, default=None) | ||
name = models.CharField(max_length=255, null=True, default=None) | ||
is_active = models.BooleanField(default=True) | ||
is_staff = models.BooleanField(default=False) | ||
avatar = models.ImageField(max_length=None, blank=True, null=True, default=None) | ||
telephone = models.CharField(max_length=20, blank=True, default=None, null=True) | ||
created_at = models.DateTimeField(auto_now_add=True, null=True) | ||
|
||
# TODO field: | ||
@property | ||
def customer_dachb_profile(self): | ||
pass | ||
|
||
objects = UserManager() | ||
|
||
USERNAME_FIELD = 'email' | ||
|
||
admin.site.register(User) |
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,19 @@ | ||
{% extends "base.html" %} | ||
|
||
|
||
{% block content %} | ||
|
||
{% if not request.user.is_authenticated %} | ||
<div style='margin-top:30px;'> | ||
<form method='POST'>{% csrf_token %} | ||
{{ form.as_p }} | ||
<button type='submit'>Login</button> | ||
</form> | ||
|
||
<p>Need an account? Please <a href='/register'>Register</a></p> | ||
</div> | ||
{% else %} | ||
<p>You're already logged in. Would you like to <a href='/logout/'>logout</a>?</p> | ||
{% endif %} | ||
|
||
{% endblock %} |
Oops, something went wrong.