Skip to content

Commit

Permalink
Merge pull request #187 from weaverse-techtide/dev
Browse files Browse the repository at this point in the history
10월14일11:09
  • Loading branch information
AlbertImKr authored Oct 14, 2024
2 parents bfea40a + 6ca9c24 commit eaab622
Show file tree
Hide file tree
Showing 22 changed files with 653 additions and 270 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,4 @@ python manage.py runserver

### 최종 검토 및 문서화

![week3](assets/images/week3.png)
![week3](assets/images/week3.png)
4 changes: 2 additions & 2 deletions accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ def __str__(self):
return self.email

def get_image_url(self):
if getattr(self, "image", None):
return self.image.image_url
if hasattr(self, "image") and hasattr(self.image, "url"):
return self.image.url
return "https://paullab.co.kr/images/weniv-licat.png"
Binary file added assets/images/유연우.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/유원길.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/이유정.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/임홍광.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions courses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ class Course(models.Model):
updated_at = models.DateTimeField(auto_now=True, verbose_name="수정일")

def get_thumbnail(self):
if hasattr(self, "images") and self.images.exists():
return self.images.first().file.url
if hasattr(self, "image"):
return self.image.url
return "https://www.gravatar.com/avatar/205e460b479e2e5b48aec077"

def update(self, **kwargs):
Expand Down
11 changes: 7 additions & 4 deletions courses/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Meta:

def get_video_url(self, obj):
if getattr(obj, "video", None):
return obj.video.video_url
return obj.video.url
return None

def get_video_duration(self, obj):
Expand Down Expand Up @@ -164,17 +164,16 @@ class Meta:
]

def get_author_image(self, obj):
print(obj.author.image.image_url)
if getattr(obj.author, "image", None):
return obj.author.image.image_url
return obj.author.image.url
return None

def get_author_name(self, obj):
return obj.author.nickname

def get_video_url(self, obj):
if getattr(obj, "video", None):
return obj.video.video_url
return obj.video.url
return None

def get_thumbnail_url(self, obj):
Expand Down Expand Up @@ -233,6 +232,8 @@ def get_thumbnail(self, obj):
return obj.get_thumbnail()

def get_author_image(self, obj):
if getattr(obj.author, "image", None):
return obj.author.image.url
return "https://paullab.co.kr/images/weniv-licat.png"

def get_author_name(self, obj):
Expand Down Expand Up @@ -314,6 +315,8 @@ class Meta:
]

def get_author_image(self, obj):
if getattr(obj.author, "image", None):
return obj.author.image.url
return "https://paullab.co.kr/images/weniv-licat.png"

def get_author_name(self, obj):
Expand Down
4 changes: 2 additions & 2 deletions courses/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def create_user():
user = User.objects.create_user(
email=TEST_USER_EMAIL, password=TEST_USER_PASSWORD, nickname="testuser"
)
Image.objects.create(user=user, image_url="test.jpg")
Image.objects.create(user=user, url="test.jpg")
return user


Expand All @@ -148,7 +148,7 @@ def create_staff_user():
is_staff=True,
nickname="staffuser",
)
Image.objects.create(user=user, image_url="test.jpg")
Image.objects.create(user=user, url="test.jpg")
return user


Expand Down
41 changes: 37 additions & 4 deletions jwtauth/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging

import jwt
from allauth.socialaccount.providers.google.views import GoogleOAuth2Adapter
from allauth.socialaccount.providers.oauth2.client import OAuth2Client
Expand Down Expand Up @@ -166,23 +165,57 @@ def post(self, request):


class GoogleLogin(SocialLoginView):
"""
사용자가 구글 로그인을 할 때 사용, 구글 로그인을 위한 소셜 로그인 뷰입니다.
사용자가 구글사이트에서 로그인을 완료하면, 사용자 정보를 받아서 회원가입 또는 로그인 처리합니다.
닉네임은 이메일 주소의 @ 앞부분을 사용하고, 비밀번호는 사용하지 않습니다.
쿠기에 리프레시 토큰과 액세스 토큰을 저장합니다.
"""

adapter_class = GoogleOAuth2Adapter
callback_url = settings.GOOGLE_CALLBACK_URL
client_class = OAuth2Client

def get(self, request, *args, **kwargs):
"""
GET 요청: 구글 로그인 페이지로 리다이렉트
"""
return super().get(request, *args, **kwargs)

def get_response(self):
"""
소셜 로그인 완료 후 사용자 정보 처리
"""
response = super().get_response()

user = self.user

if not User.objects.filter(email=user.email).exists():
user = User.objects.create_user(
nickname=user.mail.split("@")[0],
email=user.email,
)
user.set_unusable_password()
user.save()

access_token = generate_access_token(user)
refresh_token = generate_refresh_token(user)

response = redirect(settings.LOGIN_REDIRECT_URL)
same_site = None if settings.DEBUG else "Lax"
response.set_cookie(
key="refresh_token",
value=refresh_token,
httponly=True,
secure=not settings.DEBUG,
samesite="None",
samesite=same_site,
max_age=60 * 60 * 24 * 14,
)
response.set_cookie(
key="access_token",
value=access_token,
secure=not settings.DEBUG,
samesite=same_site,
max_age=60 * 30,
)
response.data = {"access_token": access_token}

return response
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Generated by Django 5.1.1 on 2024-10-14 05:25

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('materials', '0007_alter_image_author'),
]

operations = [
migrations.AlterModelOptions(
name='image',
options={'ordering': ['-created_at']},
),
migrations.AlterModelOptions(
name='video',
options={'ordering': ['-created_at']},
),
migrations.AlterModelOptions(
name='videoeventdata',
options={'ordering': ['-timestamp']},
),
migrations.AddField(
model_name='image',
name='is_deleted',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='video',
name='is_deleted',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='image',
name='image_url',
field=models.ImageField(blank=True, null=True, upload_to='images/', verbose_name='이미지 파일'),
),
migrations.AlterField(
model_name='video',
name='video_url',
field=models.FileField(blank=True, null=True, upload_to='videos/', verbose_name='비디오 파일'),
),
migrations.AlterField(
model_name='videoeventdata',
name='duration',
field=models.FloatField(verbose_name='동영상 전체 길이'),
),
migrations.AlterField(
model_name='videoeventdata',
name='video',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='video_event_datas', to='materials.video', verbose_name='시청 기록의 해당 동영상'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.1.1 on 2024-10-14 06:31

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('materials', '0008_alter_image_options_alter_video_options_and_more'),
]

operations = [
migrations.RemoveField(
model_name='image',
name='image_url',
),
migrations.RemoveField(
model_name='video',
name='video_url',
),
]
23 changes: 23 additions & 0 deletions materials/migrations/0010_image_url_video_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.1.1 on 2024-10-14 06:34

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('materials', '0009_remove_image_image_url_remove_video_video_url'),
]

operations = [
migrations.AddField(
model_name='image',
name='url',
field=models.URLField(default='https://paullab.co.kr/images/weniv-licat.png', verbose_name='이미지 URL'),
),
migrations.AddField(
model_name='video',
name='url',
field=models.URLField(default='https://www.youtube.com/watch?v=bZh8oUIDfdI&t=1s', verbose_name='동영상 URL'),
),
]
Loading

0 comments on commit eaab622

Please sign in to comment.