Skip to content

Commit

Permalink
[fix] accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
Hwang-Jaeryeong committed Jan 21, 2024
1 parent 2329a30 commit 800e446
Show file tree
Hide file tree
Showing 27 changed files with 68 additions and 24 deletions.
Binary file modified accounts/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file modified accounts/__pycache__/views.cpython-311.pyc
Binary file not shown.
5 changes: 4 additions & 1 deletion accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Generated by Django 3.2.16 on 2024-01-19 06:02
# Generated by Django 3.2.16 on 2024-01-21 19:09

import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


Expand All @@ -12,6 +13,7 @@ class Migration(migrations.Migration):

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
('llo', '0001_initial'),
]

operations = [
Expand All @@ -32,6 +34,7 @@ class Migration(migrations.Migration):
('phone_number', models.CharField(max_length=15, unique=True)),
('nickname', models.CharField(blank=True, max_length=255)),
('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')),
('selected_team', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='llo.selectedteam')),
('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={
Expand Down
18 changes: 0 additions & 18 deletions accounts/migrations/0002_customuser_selected_team.py

This file was deleted.

Binary file modified accounts/migrations/__pycache__/0001_initial.cpython-311.pyc
Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from django.db import models
from django.contrib.auth.models import AbstractUser
from llo.models import SelectedTeam

class CustomUser(AbstractUser):
phone_number = models.CharField(max_length=15, unique=True)
nickname = models.CharField(max_length=255, blank=True)
selected_team = models.IntegerField(null=True, blank=True)
selected_team = models.ForeignKey(SelectedTeam, null=True, blank=True, on_delete=models.SET_NULL)
16 changes: 12 additions & 4 deletions accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@
from rest_framework_simplejwt.tokens import RefreshToken
from .models import CustomUser
from .serializers import CustomUserSerializer
from llo.models import SelectedTeam

@api_view(['POST'])
@permission_classes([AllowAny])
def register_user(request):
data = request.data
serializer = CustomUserSerializer(data=data)
selected_team = request.data.get('selected_team')
selected_team_id = request.data.get('selected_team') # 'selected_team'로부터 팀 ID를 받아옴
if serializer.is_valid():
serializer.save(selected_team=selected_team)
return Response(serializer.data, status=status.HTTP_201_CREATED)
user = serializer.save()

# 선택한 팀 정보를 사용자와 연결
if selected_team_id:
selected_team = SelectedTeam.objects.get(id=selected_team_id)
user.selected_team = selected_team
user.save()

return Response({'detail': 'User registered successfully'}, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

@api_view(['POST'])
Expand All @@ -42,9 +50,9 @@ def login_user(request):

# 인증 실패
return Response({'detail': 'Invalid credentials'}, status=status.HTTP_401_UNAUTHORIZED)

@api_view(['POST'])
@permission_classes([IsAuthenticated])
def logout_user(request):
# You can add additional logout logic here if needed
return Response({'detail': 'Successfully logged out'}, status=status.HTTP_200_OK)

Binary file modified madcamp_week4_BE/__pycache__/settings.cpython-311.pyc
Binary file not shown.
Binary file modified madcamp_week4_BE/__pycache__/urls.cpython-311.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions madcamp_week4_BE/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
'accounts',
'info',
'llo',
'news',
]

# Authentication backends
Expand Down
1 change: 1 addition & 0 deletions madcamp_week4_BE/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
path('accounts/', include('accounts.urls')),
path('info/', include('info.urls')),
path('llo/', include('llo.urls')),
path('news/', include('news.urls')),
]
Empty file added news/__init__.py
Empty file.
Binary file added news/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file added news/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file added news/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file added news/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file added news/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file added news/__pycache__/views.cpython-311.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions news/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions news/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class NewsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'news'
Empty file added news/migrations/__init__.py
Empty file.
Binary file added news/migrations/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions news/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions news/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
7 changes: 7 additions & 0 deletions news/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# news/urls.py
from django.urls import path
from .views import user_team_info

urlpatterns = [
path('user_team_info/', user_team_info, name='user_team_info'),
]
26 changes: 26 additions & 0 deletions news/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# news/views.py
from django.shortcuts import get_object_or_404
from rest_framework.decorators import api_view
from rest_framework.response import Response
from accounts.models import CustomUser
from llo.models import SelectedTeam

@api_view(['GET'])
def user_team_info(request):
user = request.user # 현재 로그인한 사용자
if user.is_authenticated:
selected_team = user.selected_team

if selected_team:
logo_url = request.build_absolute_uri(selected_team.logo.url)
response_data = {
'logo_url': logo_url,
'team_name': selected_team.team_name,
'news_text': f"{selected_team.team_name} News"
}
return Response(response_data)
else:
return Response({'error': 'No team selected for the user.'}, status=400)
else:
return Response({'error': 'User not authenticated.'}, status=401)

0 comments on commit 800e446

Please sign in to comment.