Skip to content

Commit

Permalink
Merge pull request #84 from Sahayana/mypage
Browse files Browse the repository at this point in the history
[Mypage] 마이페이지 api 개발 완료
  • Loading branch information
Sahayana authored Nov 21, 2023
2 parents 1824251 + 7007522 commit ffdecd2
Show file tree
Hide file tree
Showing 39 changed files with 1,276 additions and 743 deletions.
12 changes: 12 additions & 0 deletions alaltalk/cache_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""캐싱에 필요한 Key 관리"""

# Friend
RECOMMEND_FRIEND = "recommend_friend_{user_id}"
USER_LIKE_DATA = "user_like_data_{user_id}"

# Search

USER_YOUTUBE = "youtube_user_{user_id}"
USER_BOOK = "book_user_{user_id}"
USER_NEWS = "news_user_{user_id}"
USER_SHOPPING = "shopping_user_{user_id}"
1 change: 1 addition & 0 deletions alaltalk/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"six",
"rest_framework",
"rest_framework_simplejwt",
"rest_framework_simplejwt.token_blacklist",
"django_extensions",
]

Expand Down
35 changes: 15 additions & 20 deletions alaltalk/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,28 @@
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path
from ninja import NinjaAPI

from alaltalk.views import landing_home
from apps.chat.apis.v1.chat_room_router import router as chat_room_router
from apps.search.apis.v1.like_cancel_router import router as like_cancel_router
from apps.search.apis.v1.like_router import router as like_router
from apps.search.apis.v1.search_router import router as search_router

# from ninja import NinjaAPI

# from apps.chat.apis.v1.chat_room_router import router as chat_room_router
# from apps.search.apis.v1.like_cancel_router import router as like_cancel_router
# from apps.search.apis.v1.like_router import router as like_router
# from apps.search.apis.v1.search_router import router as search_router

# from alaltalk import views

# api = NinjaAPI()
# api.add_router("/search/", search_router)
# api.add_router("/like/", like_router)
# api.add_router("/like_cancel/", like_cancel_router)
# api.add_router("/chat_room/", chat_room_router)
api = NinjaAPI()
api.add_router("/search/", search_router)
api.add_router("/like/", like_router)
api.add_router("/like_cancel/", like_cancel_router)
api.add_router("/chat_room/", chat_room_router)

urlpatterns = [
path("admin/", admin.site.urls),
path("", landing_home, name="landing_page"),
path("account/", include("apps.account.urls")),
path("friend/", include("apps.friend.urls"))
# path("accounts/", include("accounts.urls")),
# path("chat/", include("chat.urls")),
# path("api/", api.urls),
path("friend/", include("apps.friend.urls")),
path("chat/", include("apps.chat.urls")),
path("api/", api.urls),
]

# if settings.DEBUG:
# urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
2 changes: 1 addition & 1 deletion alaltalk/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
def landing_home(request):
user = request.user
if user.is_authenticated:
return redirect("accounts:mypage")
return redirect("account:v1:mypage")
return render(request, "landing/landing_page.html", {})
1 change: 1 addition & 0 deletions apps/account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
is_superuser = models.BooleanField(default=False)
is_recommend_on = models.BooleanField(default=True)
is_like_public = models.BooleanField(default=True)
is_deleted = models.BooleanField(default=False)

USERNAME_FIELD = "email"
REQUIRED_FIELDS = ["nickname"]
Expand Down
Empty file.
144 changes: 0 additions & 144 deletions apps/account/services/accounts_service.py

This file was deleted.

32 changes: 27 additions & 5 deletions apps/account/services/user_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from django.utils.http import urlsafe_base64_decode

from apps.account.models import CustomUser, UserLikeKeyWord, UserProfileImage
from apps.account.tasks import send_email_verification
from apps.account.utils import accounts_verify_token
from apps.account.tasks import send_email_verification, send_temporary_password
from apps.account.utils import accounts_verify_token, random_string_generator


class UserService:
Expand All @@ -26,9 +26,7 @@ def create_single_user(
email=email, nickname=nickname, bio=bio, password=password
)
if img:
image = UserProfileImage.objects.create(user=user, img=img)
user.profile_image = image
user.save()
UserProfileImage.objects.create(user=user, img=img)

# TODO: Celery 비동기 처리
transaction.on_commit(lambda: send_email_verification.delay(user.id))
Expand Down Expand Up @@ -84,3 +82,27 @@ def like_public_setting(cls, user_id: int, value: str) -> CustomUser:
raise KeyError("value 값은 'ON'/'OFF'만 가능합니다.")

return user

@classmethod
def delete_user_account(cls, user_id: int):

user = CustomUser.objects.get(id=user_id)
user.is_deleted = True
user.save()
return user

@classmethod
@transaction.atomic()
def change_temporary_password(cls, user_id: int):

user = CustomUser.objects.get(id=user_id)
temp_password = random_string_generator(length=10)

user.set_password(temp_password)
user.save()

transaction.on_commit(
lambda: send_temporary_password.delay(user.id, temp_password)
)

return user
15 changes: 13 additions & 2 deletions apps/account/tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from celery import shared_task
from django.core.mail import EmailMessage
from django.core.mail import EmailMessage, send_mail
from django.template.loader import render_to_string
from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode
Expand All @@ -11,7 +11,7 @@


@shared_task
def send_email_verification(user_id: int) -> None:
def send_email_verification(user_id: int):
"""
새로 생성한 유저에게 사용자 인증 이메일을 전송합니다.
"""
Expand All @@ -27,3 +27,14 @@ def send_email_verification(user_id: int) -> None:
)
email_message = EmailMessage(EMAIL_VERIFY_TITLE, message, to=[user.email])
return email_message.send()


@shared_task
def send_temporary_password(email: str, temp_pw: str):
return send_mail(
"[alaltalk] 임시 비밀번호 메일입니다.",
f"회원님의 임시 비밀번호는 {temp_pw} 입니다.\n로그인 후 비밀번호를 꼭 변경해주세요.",
"[email protected]",
[email],
fail_silently=False,
)
Loading

0 comments on commit ffdecd2

Please sign in to comment.