Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Backend/momment/accounts/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file modified Backend/momment/accounts/__pycache__/views.cpython-39.pyc
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2023-01-06 08:02
# Generated by Django 3.2.13 on 2023-01-11 14:43

from django.db import migrations, models

Expand Down
18 changes: 0 additions & 18 deletions Backend/momment/accounts/migrations/0003_alter_user_birth.py

This file was deleted.

18 changes: 0 additions & 18 deletions Backend/momment/accounts/migrations/0004_alter_user_birth.py

This file was deleted.

7 changes: 4 additions & 3 deletions Backend/momment/accounts/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.db import models
from django.contrib.auth.models import BaseUserManager, AbstractBaseUser

class Manager(BaseUserManager):

class Account(BaseUserManager):

def create_user(self, email, name, birth, digit, address, password=None):
if not email:
Expand Down Expand Up @@ -47,10 +48,10 @@ class User(AbstractBaseUser):
create_at = models.DateTimeField(verbose_name='date joined', auto_now_add=True)
last_login = models.DateTimeField(verbose_name='last login', auto_now=True)

object = Manager()
object = Account()

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['name', 'digit', 'address']
REQUIRED_FIELDS = ['name', 'digit', 'address', 'birth']

def __str__(self):
return self.email
Expand Down
8 changes: 8 additions & 0 deletions Backend/momment/accounts/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework.serializers import ModelSerializer, ReadOnlyField
from .models import Account

class LoginSerializer(ModelSerializer):

class Meta:
model = Account
fields = ['email', 'name']
37 changes: 23 additions & 14 deletions Backend/momment/accounts/views.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
from django.shortcuts import render
from django.conf import settings
from django.shortcuts import redirect
from rest_framework.views import APIView
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
# 커스텀 로그인
from django.http import HttpResponse, JsonResponse

from django.views.decorators.csrf import csrf_exempt
from accounts.models import User, Manager
from accounts.models import User, Account
import requests, json, re
from django.contrib.auth import authenticate

from django.contrib.auth.hashers import check_password
from rest_framework import status
from json.decoder import JSONDecodeError
from rest_framework.authtoken.models import Token
from rest_framework.permissions import IsAuthenticated


# 카카오 로그인
from rest_framework.views import APIView
from django.conf import settings
from django.shortcuts import redirect
from rest_framework.response import Response

# Create your views here.

Expand Down Expand Up @@ -43,8 +45,10 @@ def signup(request):
if not re.match(regex_password, password):
return JsonResponse({'message' : 'INVALID_PASSWORD'}, status = 400)

User.object.create_user(email=email, password=password, name=name, digit=digit, birth=birth, address=address)
return JsonResponse({'message' : 'SUCCESS'}, status=201)
user = User.object.create_user(email=email, password=password, name=name, digit=digit, birth=birth, address=address)

token = Token.objects.create(user=user)
return JsonResponse({'message' : 'SUCCESS', 'token' : token.key}, status=200)

except KeyError:
return JsonResponse({'message' : 'KEY_ERROR'}, status=400)
Expand All @@ -57,9 +61,14 @@ def login(request):
email = data['email']
password = data['password']

User.object.filter(email=email).
user = User.object.filter(email=email)

if not check_password(password, user.get().password):
return JsonResponse({'message' : 'WRONG_PASSWORD'})

token = Token.objects.get(user=user.get())

return JsonResponse({'message' : 'LOGIN_SUCCESS'})
return JsonResponse({'message' : 'LOGIN_SUCCESS', 'token' : token.key}, status=200)
except:
return JsonResponse({'message' : 'LOGIN_FAILED'})

Expand Down
Binary file modified Backend/momment/db.sqlite3
Binary file not shown.
Binary file modified Backend/momment/momment/__pycache__/settings.cpython-39.pyc
Binary file not shown.
23 changes: 16 additions & 7 deletions Backend/momment/momment/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,20 @@ def get_secret(setting, secrets=secrets):

AUTH_USER_MODEL = 'accounts.User'

# 로그인 토큰 발급
REST_FRAMEWORK = {
# 'DEFAULT_AUTHENTICATION_CLASSES': [
# 'rest_framework.authentication.TokenAuthentication',
# ],
# 'DEFAULT_PERMISSION_CLASSES': [
# # 'rest_framework.permissions.IsAuthenticated',
# ]
}
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication',
],
'DEFAULT_PERMISSION_CLASSES': [
# 'rest_framework.permissions.IsAuthenticated',
]
}

# # 로그인 비밀번호 검증
# 없어도 잘 돌아간다.
# PASSWORD_HASHERS = [
# 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
# 'django.contrib.auth.hashers.PBKDF2PasswordHasher',
# 'django.contrib.auth.hashers.Argon2PasswordHasher',
# ]