[go: nahoru, domu]

Skip to content

Commit

Permalink
deployment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
seraleman committed Oct 7, 2021
1 parent 0264d08 commit 60d1486
Show file tree
Hide file tree
Showing 22 changed files with 58 additions and 51 deletions.
Binary file modified authApp/__pycache__/admin.cpython-39.pyc
Binary file not shown.
3 changes: 0 additions & 3 deletions authApp/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from django.contrib import admin

# Register your models here.

from .models.user import User
from .models.account import Account

Expand Down
18 changes: 18 additions & 0 deletions authApp/migrations/0002_alter_user_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.7 on 2021-10-07 19:46

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('authApp', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='user',
name='email',
field=models.EmailField(max_length=100, verbose_name='Email'),
),
]
Binary file not shown.
Binary file modified authApp/models/__pycache__/account.cpython-39.pyc
Binary file not shown.
Binary file modified authApp/models/__pycache__/user.cpython-39.pyc
Binary file not shown.
4 changes: 1 addition & 3 deletions authApp/models/account.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from django.db import models
from .user import User


class Account(models.Model):
id = models.AutoField(primary_key=True)
user = models.ForeignKey(
User, related_name='account', on_delete=models.CASCADE)
user = models.ForeignKey(User, related_name='account', on_delete=models.CASCADE)
balance = models.IntegerField(default=0)
lastChangeDate = models.DateTimeField()
isActive = models.BooleanField(default=True)
20 changes: 11 additions & 9 deletions authApp/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager
from django.contrib.auth.hashers import make_password


class UserManager(BaseUserManager):
def create_user(self, username, password=None):
""" Creates and saves a user with the given username and password """
"""
Creates and saves a user with the given username and password.
"""
if not username:
raise ValueError('Users must have an username')
user = self.model(username=username)
Expand All @@ -14,7 +15,9 @@ def create_user(self, username, password=None):
return user

def create_superuser(self, username, password):
""" Creates and saves a superuser with the given username and password """
"""
Creates and saves a superuser with the given username and password.
"""
user = self.create_user(
username=username,
password=password,
Expand All @@ -23,16 +26,15 @@ def create_superuser(self, username, password):
user.save(using=self._db)
return user


class User(AbstractBaseUser, PermissionsMixin):
id = models.BigAutoField(primary_key=True)
username = models.CharField('Username', max_length=15, unique=True)
password = models.CharField('Password', max_length=256)
name = models.CharField('Name', max_length=30)
email = models.CharField('Email', max_length=100)
username = models.CharField('Username', max_length = 15, unique=True)
password = models.CharField('Password', max_length = 256)
name = models.CharField('Name', max_length = 30)
email = models.EmailField('Email', max_length = 100)

def save(self, **kwargs):
some_salt = 'mMUj0DrIK6vgtdIYepkIxN'
some_salt = 'mMUj0DrIK6vgtdIYepkIxN'
self.password = make_password(self.password, some_salt)
super().save(**kwargs)

Expand Down
Binary file modified authApp/serializers/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file modified authApp/serializers/__pycache__/accountSerializer.cpython-39.pyc
Binary file not shown.
Binary file modified authApp/serializers/__pycache__/userSerializer.cpython-39.pyc
Binary file not shown.
3 changes: 1 addition & 2 deletions authApp/serializers/accountSerializer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from authApp.models.account import Account
from rest_framework import serializers


class AccountSerializer(serializers.ModelSerializer):
class Meta:
model = Account
fields = ['balance', 'lastChangeDate', 'IsActive']
fields = ['balance', 'lastChangeDate', 'isActive']
27 changes: 12 additions & 15 deletions authApp/serializers/userSerializer.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from collections import UserString
from rest_framework import serializers
from authApp.models.user import User
from authApp.models.account import Account
from authApp.serializers.accountSerializer import AccountSerializer


class UserSerializer(serializers.ModelSerializer):
account = AccountSerializer()

class Meta:
model = User
fields = ['id', 'username', 'password', 'name', 'email', 'account']
Expand All @@ -20,16 +17,16 @@ def create(self, validated_data):

def to_representation(self, obj):
user = User.objects.get(id=obj.id)
account = Account.objects.get(user=obj.id)
account = Account.objects.get(user=obj.id)
return {
'id': user.id,
'username': user.username,
'name': user.name,
'email': user.email,
'account': {
'id': account.id,
'balance': account.balance,
'lastChangeDate': account.lastChangeDate,
'isActive': account.isActive
}
}
'id': user.id,
'username': user.username,
'name': user.name,
'email': user.email,
'account': {
'id': account.id,
'balance': account.balance,
'lastChangeDate': account.lastChangeDate,
'isActive': account.isActive
}
}
Binary file modified authApp/views/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file modified authApp/views/__pycache__/userCreateView.cpython-39.pyc
Binary file not shown.
Binary file modified authApp/views/__pycache__/userDetailView.cpython-39.pyc
Binary file not shown.
17 changes: 7 additions & 10 deletions authApp/views/userCreateView.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
from rest_framework import serializers, status, views
from rest_framework import status, views
from rest_framework.response import Response
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer, TokenObtainSerializer
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer

from authApp.serializers.userSerializer import UserSerializer


class UserCreateView(views.APIView):

def post(self, request, *args, **kwargs):
serializer = UserSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
serializer.save()

tokenData = {
"username": request.data["username"],
"password": request.data["password"]
}
tokenSerializer = TokenObtainSerializer(data=tokenData)
tokenSerializer.is_valid(raise_excepetion=True)

tokenData = {"username":request.data["username"],
"password":request.data["password"]}
tokenSerializer = TokenObtainPairSerializer(data=tokenData)
tokenSerializer.is_valid(raise_exception=True)

return Response(tokenSerializer.validated_data, status=status.HTTP_201_CREATED)
6 changes: 3 additions & 3 deletions authApp/views/userDetailView.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
from authApp.models.user import User
from authApp.serializers.userSerializer import UserSerializer


class UserDetailView(generics.RetrieveAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
permission_classes = (IsAuthenticated,)

def get(self, request, *args, **kwargs):

token = request.META.get('HTTP_AUTHORIZATION')[7:]
tokenBackend = TokenBackend(algorithm=settings.SIMPLE_JWT['ALGORITHM'])
valid_data = tokenBackend.decode(token, verify=False)
valid_data = tokenBackend.decode(token,verify=False)

if valid_data['user_id'] != kwargs['pk']:
stringResponse = {'detail':'Unauthorized Request'}
Expand Down
Binary file modified authProject/__pycache__/settings.cpython-39.pyc
Binary file not shown.
Binary file modified authProject/__pycache__/urls.cpython-39.pyc
Binary file not shown.
8 changes: 4 additions & 4 deletions authProject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

import django_heroku
from pathlib import Path
from datetime import timedelta

Expand Down Expand Up @@ -43,14 +44,14 @@
]

SIMPLE_JWT = {
'ACCES_TOKEN_LIFETIME': timedelta(minutes=5),
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=5),
'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
'ROTATE_REFRESH_TOKEN': False,
'ROTATE_REFRESH_TOKENS': False,
'BLACKLIST_AFTER_ROTATION': True,
'UPDATE_LAST_LOGIN': False,

'ALGORITHM': 'HS256',
'USER_ID_FIELD': id,
'USER_ID_FIELD': 'id',
'USER_ID_CLAIM': 'user_id',
}

Expand Down Expand Up @@ -154,5 +155,4 @@

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

import django_heroku
django_heroku.settings(locals())
3 changes: 1 addition & 2 deletions authProject/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.urls import path
from rest_framework_simplejwt.views import (
TokenObtainPairView, TokenRefreshView)
from rest_framework_simplejwt.views import (TokenObtainPairView, TokenRefreshView)
from authApp import views

urlpatterns = [
Expand Down

0 comments on commit 60d1486

Please sign in to comment.