Skip to content

Commit

Permalink
Creating user successfully, now need to protect the routes
Browse files Browse the repository at this point in the history
  • Loading branch information
MdSamsuzzohaShayon committed Mar 10, 2024
1 parent d9d8c2b commit 7fff6cc
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 10 deletions.
14 changes: 9 additions & 5 deletions server/READNE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ mutation RegisterUser($email: String!, $password: String!,
id
password
lastLogin
firstName
lastName
birth
}
}
Expand All @@ -17,10 +19,12 @@ mutation RegisterUser($email: String!, $password: String!,

```
{
"email": "u1@example.com",
"email": "u2@example.com",
"password": "Test1234",
"firstName": "fn1",
"lastName": "ln1",
"birth": "2024-03-06T11:26:12.306Z"
"firstName": "fn2",
"lastName": "ln2",
"birth": "2024-03-08T08:14:45.562Z"
}
```
```
- The `--run-syncdb` option helps to synchronize the database tables with the current state of your models without relying on the migration history.
- `./manage.py migrate --run-syncdb`
3 changes: 2 additions & 1 deletion server/account/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import admin
from account.models import User
from django.contrib.auth.admin import UserAdmin

# Register your models here.
admin.site.register(User)
# admin.site.register(User, UserAdmin)
2 changes: 1 addition & 1 deletion server/account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class User(AbstractUser):
max_length=255,
unique=True,
)
birth = models.DateField()
birth = models.DateField(null=True, blank=True, default=None)
is_active = models.BooleanField(default=False)
is_admin = models.BooleanField(default=False)

Expand Down
2 changes: 1 addition & 1 deletion server/account/resolvers/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Arguments:
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
birth = graphene.String(required=False) # Accept birthdate as a string in ISO 8601 format

def mutate(self, info, email, password, first_name, last_name, birth=None):
birthdate = None
Expand Down
14 changes: 14 additions & 0 deletions server/account/resolvers/queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import graphene
from graphene_django import DjangoObjectType
from .queryTypes import GetUserType
from ..models import User

class Query(graphene.ObjectType):
users = graphene.List(GetUserType)
question_by_id = graphene.Field(GetUserType, id=graphene.String())

def resolve_users(root, info, **kwargs):
return User.objects.all()

def resolve_user_by_id(root, info, id):
return User.objects.get(pk=id)
6 changes: 5 additions & 1 deletion server/account/resolvers/queryTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@

class UserType(DjangoObjectType):
class Meta:
model = User
model = User
class GetUserType(DjangoObjectType):
class Meta:
model = User
exclude = ("password",)
3 changes: 2 additions & 1 deletion server/core/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
from blog.resolvers.queries import Query as BlogQuery
from blog.resolvers.mutations import Mutation as BlogMutation
from account.resolvers.mutations import Mutation as AccountMutation
from account.resolvers.queries import Query as AccountQuery

class Mutation(BlogMutation, AccountMutation):
pass

class Query(BlogQuery):
class Query(BlogQuery, AccountQuery):
pass

schema = graphene.Schema(query=Query, mutation=Mutation)

0 comments on commit 7fff6cc

Please sign in to comment.