Skip to content

Commit

Permalink
test: cover verify header function (#15)
Browse files Browse the repository at this point in the history
* test: cover verify header function

* chore: auto format by pre-commit
  • Loading branch information
xyb authored Dec 28, 2023
1 parent 5f67b4a commit 094a05c
Show file tree
Hide file tree
Showing 20 changed files with 394 additions and 217 deletions.
75 changes: 75 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
hooks:
- id: codespell

- repo: https://github.com/PyCQA/autoflake
rev: v2.2.1
hooks:
- id: autoflake
name: autoflake
args: ["--in-place", "--remove-unused-variables", "--remove-all-unused-imports"]
language: python
files: \.py$

- repo: https://github.com/asottile/reorder_python_imports
rev: v3.11.0
hooks:
- id: reorder-python-imports
args:
- --py37-plus

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.290
hooks:
- id: ruff
args:
- --fix
- --exit-non-zero-on-fix

- repo: https://github.com/rtts/djhtml
rev: '3.0.6' # replace with the latest tag on GitHub
hooks:
- id: djhtml
entry: djhtml --tabwidth 2
- id: djcss
exclude: static/.*
- id: djjs
exclude: static/.*

- repo: https://github.com/asottile/pyupgrade
rev: v3.11.1
hooks:
- id: pyupgrade
args:
- --py37-plus

- repo: https://github.com/asottile/add-trailing-comma
rev: v3.1.0
hooks:
- id: add-trailing-comma
args:
- --py36-plus

- repo: https://github.com/psf/black
rev: "23.9.1"
hooks:
- id: black
args:
- --line-length
- "88"

- repo: https://github.com/asottile/add-trailing-comma
rev: v3.1.0
hooks:
- id: add-trailing-comma
args:
- --py36-plus
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ All configurations can be set via environment variables.
The following are the configured default values:

```python
# 0: production, 1: devlopment
# 0: production, 1: development
DJANGO_DEBUG = 1

# specify hosts seperated by commas
# specify hosts separated by commas
DJANGO_ALLOWED_HOSTS = '*'

# 1: print email to screen, not sending
Expand Down
7 changes: 1 addition & 6 deletions authuser/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

from .models import User

#admin.site.register(User, UserAdmin)
# admin.site.register(User, UserAdmin)
4 changes: 2 additions & 2 deletions authuser/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class AuthuserConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'authuser'
default_auto_field = "django.db.models.BigAutoField"
name = "authuser"
74 changes: 59 additions & 15 deletions authuser/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,80 @@
# Generated by Django 4.1.4 on 2023-01-04 07:54
from django.db import migrations
from django.db import models

import authuser.models
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
("auth", "0012_alter_user_first_name_max_length"),
]

operations = [
migrations.CreateModel(
name='User',
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)),
('is_active', models.BooleanField(default=True)),
('is_admin', models.BooleanField(default=False)),
('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')),
(
"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)),
("is_active", models.BooleanField(default=True)),
("is_admin", models.BooleanField(default=False)),
(
"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,
"abstract": False,
},
managers=[
('objects', authuser.models.UserManager()),
("objects", authuser.models.UserManager()),
],
),
]
33 changes: 14 additions & 19 deletions authuser/models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.base_user import BaseUserManager
from django.utils import timezone
from django.contrib.auth.models import PermissionsMixin
from django.db import models


class UserManager(BaseUserManager):

use_in_migrations = True

def _create_user(self, email, password, **extra_fields):
'''Create and save a user with the given email, and password.'''
"""Create and save a user with the given email, and password."""
if not email:
raise ValueError('The given email must be set')
raise ValueError("The given email must be set")

email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
Expand All @@ -18,34 +19,28 @@ def _create_user(self, email, password, **extra_fields):
return user

def create_user(self, email, password=None, **extra_fields):
extra_fields.setdefault('is_staff', False)
extra_fields.setdefault('is_superuser', False)
extra_fields.setdefault("is_staff", False)
extra_fields.setdefault("is_superuser", False)
return self._create_user(email, password, **extra_fields)

def create_superuser(self, email, password, **extra_fields):
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
extra_fields.setdefault("is_staff", True)
extra_fields.setdefault("is_superuser", True)

if extra_fields.get('is_staff') is not True:
raise ValueError('Superuser must have is_staff=True.')
if extra_fields.get('is_superuser') is not True:
raise ValueError('Superuser must have is_superuser=True.')
if extra_fields.get("is_staff") is not True:
raise ValueError("Superuser must have is_staff=True.")
if extra_fields.get("is_superuser") is not True:
raise ValueError("Superuser must have is_superuser=True.")

return self._create_user(email, password, **extra_fields)

from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.models import PermissionsMixin
from django.db import models
from django.utils.translation import gettext_lazy as _


class User(AbstractBaseUser, PermissionsMixin):

email = models.EmailField(unique=True, max_length=255, blank=False)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)

objects = UserManager()

USERNAME_FIELD = 'email'
USERNAME_FIELD = "email"
REQUIRED_FIELDS = []
2 changes: 0 additions & 2 deletions authuser/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from django.test import TestCase

# Create your tests here.
2 changes: 0 additions & 2 deletions authuser/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from django.shortcuts import render

# Create your views here.
3 changes: 1 addition & 2 deletions drf_passwordless_jwt/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
For more information on this file, see
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'drf_passwordless_jwt.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "drf_passwordless_jwt.settings")

application = get_asgi_application()
1 change: 1 addition & 0 deletions drf_passwordless_jwt/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LONG_LIVE_TIME = "9999-12-31T23:59:59"
3 changes: 1 addition & 2 deletions drf_passwordless_jwt/serializers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import jwt
from django.conf import settings
from django.core.validators import RegexValidator
from drfpasswordless.serializers import EmailAuthSerializer
from rest_framework import serializers

import jwt

from .utils import decode_jwt


Expand Down
Loading

0 comments on commit 094a05c

Please sign in to comment.