-
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
1 parent
79411f0
commit d9d8c2b
Showing
45 changed files
with
376 additions
and
257 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Backend | ||
- Register user mutation | ||
``` | ||
mutation RegisterUser($email: String!, $password: String!, | ||
$firstName: String!, $lastName: String!, $birth: String){ | ||
registerUser(email: $email, password: $password, | ||
firstName: $firstName, lastName: $lastName, birth: $birth){ | ||
user{ | ||
id | ||
password | ||
lastLogin | ||
birth | ||
} | ||
} | ||
} | ||
``` | ||
|
||
``` | ||
{ | ||
"email": "[email protected]", | ||
"password": "Test1234", | ||
"firstName": "fn1", | ||
"lastName": "ln1", | ||
"birth": "2024-03-06T11:26:12.306Z" | ||
} | ||
``` |
File renamed without changes.
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.contrib import admin | ||
from account.models import User | ||
|
||
# Register your models here. | ||
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,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AccountConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'account' |
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,73 @@ | ||
from django.db import models | ||
from django.contrib.auth.models import BaseUserManager, AbstractBaseUser, AbstractUser | ||
|
||
|
||
class UserManager(BaseUserManager): | ||
def create_user(self, email, birth=None, password=None): | ||
if not email: | ||
raise ValueError("Users must have an email address") | ||
|
||
user = self.model( | ||
email=self.normalize_email(email), | ||
birth=birth, | ||
) | ||
|
||
user.set_password(password) | ||
user.save(using=self._db) | ||
return user | ||
|
||
def create_superuser(self, email, birth=None, password=None): | ||
user = self.create_user( | ||
email, | ||
password=password, | ||
birth=birth, | ||
) | ||
user.is_admin = True | ||
user.save(using=self._db) | ||
return user | ||
|
||
|
||
class User(AbstractUser): | ||
email = models.EmailField( | ||
verbose_name="email address", | ||
max_length=255, | ||
unique=True, | ||
) | ||
birth = models.DateField() | ||
is_active = models.BooleanField(default=False) | ||
is_admin = models.BooleanField(default=False) | ||
|
||
groups = models.ManyToManyField( | ||
'auth.Group', | ||
verbose_name='groups', | ||
blank=True, | ||
help_text='The groups this user belongs to.', | ||
related_name='user_groups', | ||
) | ||
|
||
# Provide a unique related_name for the user_permissions field | ||
user_permissions = models.ManyToManyField( | ||
'auth.Permission', | ||
verbose_name='user permissions', | ||
blank=True, | ||
help_text='Specific permissions for this user.', | ||
related_name='user_permissions_account', # Unique related_name to resolve the clash | ||
) | ||
|
||
objects = UserManager() | ||
|
||
USERNAME_FIELD = "email" | ||
REQUIRED_FIELDS = [] | ||
|
||
def __str__(self): | ||
return self.email | ||
|
||
def has_perm(self, perm, obj=None): | ||
return True | ||
|
||
def has_module_perms(self, app_label): | ||
return True | ||
|
||
@property | ||
def is_staff(self): | ||
return self.is_admin |
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,43 @@ | ||
import graphene | ||
from django.contrib.auth import get_user_model | ||
from .queryTypes import UserType | ||
from account.models import User | ||
from datetime import datetime | ||
|
||
class UserRegistrationMutation(graphene.Mutation): | ||
user = graphene.Field(UserType) | ||
|
||
class Arguments: | ||
email = graphene.String(required=True) | ||
password = graphene.String(required=True) | ||
first_name = graphene.String(required=True) | ||
last_name = graphene.String(required=True) | ||
birth = graphene.String() # Accept birthdate as a string in ISO 8601 format | ||
|
||
def mutate(self, info, email, password, first_name, last_name, birth=None): | ||
birthdate = None | ||
if birth: | ||
# Parse the birthdate string into a datetime object | ||
birthdate = datetime.fromisoformat(birth.replace('Z', '+00:00')) | ||
|
||
# Create the user object | ||
user = User( | ||
email=email, | ||
birth=birthdate, # Replace 'birthdate' with the actual field in your model | ||
is_active=False, | ||
username=email, # Set username directly | ||
first_name=first_name, | ||
last_name=last_name, | ||
) | ||
|
||
# Set the password | ||
user.set_password(password) | ||
|
||
# Save the user | ||
user.save() | ||
|
||
# Return the mutation result | ||
return UserRegistrationMutation(user=user) | ||
|
||
class Mutation(graphene.ObjectType): | ||
register_user = UserRegistrationMutation.Field() |
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,7 @@ | ||
from account.models import User | ||
from graphene_django.types import DjangoObjectType | ||
import graphene | ||
|
||
class UserType(DjangoObjectType): | ||
class Meta: | ||
model = 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,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests 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,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
This file was deleted.
Oops, something went wrong.
58 changes: 0 additions & 58 deletions
58
server/blog/migrations/0002_rename_author_id_article_author_and_more.py
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
server/blog/migrations/0004_alter_article_link_alter_article_title.py
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.