Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
29 changes: 0 additions & 29 deletions .github/workflows/isort.yml

This file was deleted.

13 changes: 7 additions & 6 deletions .github/workflows/black.yml → .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Formatter-CI Workflow
name: Style Checker Workflow

on:
pull_request:
Expand All @@ -11,7 +11,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [ 3.11 ]
python-version: [ 3.12 ]

steps:
- uses: actions/checkout@v4
Expand All @@ -22,8 +22,9 @@ jobs:
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --no-root
- name: Run Formatter check
pip install uv
uv sync --extra dev
- name: Run Style checker
run: |
poetry run black ./ --check
uv run isort ./ --check
uv run black ./ --check
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/

### PyCharm+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
Expand Down
1 change: 0 additions & 1 deletion .idea/runConfigurations/Jusicool_Server.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion api/urls.py
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
urlpatterns = []
from django.urls import include, path

urlpatterns = [
path(
"/user",
include("api.users.urls"),
name="user",
),
]
Empty file added api/users/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions api/users/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from drf_spectacular.utils import OpenApiExample, extend_schema

from api.users.serializers import SendVerifyCodeSerializer

email_send_schema = extend_schema(
tags=["users"],
summary="Send email verification code",
description="사용자 이메일로 인증 코드를 발송합니다. 분당 최대 2회의 요청만 허용됩니다.",
request=SendVerifyCodeSerializer,
responses={204: None},
examples=[
OpenApiExample(
name="Valid request",
value={"email": "[email protected]"},
request_only=True,
)
],
)
7 changes: 7 additions & 0 deletions api/users/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from rest_framework import serializers


class SendVerifyCodeSerializer(serializers.Serializer):
email = serializers.EmailField(
help_text="이메일 주소",
)
11 changes: 11 additions & 0 deletions api/users/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.urls import path

from api.users.views import EmailRequestView

urlpatterns = [
path(
"/email/send",
EmailRequestView.as_view(),
name="email-send",
),
]
28 changes: 28 additions & 0 deletions api/users/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from rest_framework import status
from rest_framework.permissions import AllowAny
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.views import APIView

from api.users.schema import email_send_schema
from api.users.serializers import SendVerifyCodeSerializer
from apps.users.services import UserVerificationService
from core.exceptions import InvalidRequestError
from core.throttles import OneMinuteAnonRateThrottle


class EmailRequestView(APIView):
permission_classes = [AllowAny]
throttle_classes = [OneMinuteAnonRateThrottle]

@email_send_schema
def post(self, request: Request) -> Response:
input_serializer = SendVerifyCodeSerializer(data=request.data)
if not input_serializer.is_valid():
raise InvalidRequestError

UserVerificationService().send_verification_code(
email=input_serializer.validated_data["email"],
)

return Response(status=status.HTTP_204_NO_CONTENT)
Empty file added apps/users/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions apps/users/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class UsersConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "apps.users"
133 changes: 133 additions & 0 deletions apps/users/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Generated by Django 5.2.8 on 2025-11-08 17:59

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


class Migration(migrations.Migration):

initial = True

dependencies = [
("auth", "0012_alter_user_first_name_max_length"),
]

operations = [
migrations.CreateModel(
name="User",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("password", models.CharField(max_length=128, verbose_name="password")),
(
"last_login",
models.DateTimeField(
blank=True, null=True, verbose_name="last login"
),
),
(
"is_superuser",
models.BooleanField(
default=False,
help_text="Designates that this user has all permissions without explicitly assigning them.",
verbose_name="superuser status",
),
),
(
"username",
models.CharField(
error_messages={
"unique": "A user with that username already exists."
},
help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
max_length=150,
unique=True,
validators=[
django.contrib.auth.validators.UnicodeUsernameValidator()
],
verbose_name="username",
),
),
(
"first_name",
models.CharField(
blank=True, max_length=150, verbose_name="first name"
),
),
(
"last_name",
models.CharField(
blank=True, max_length=150, verbose_name="last name"
),
),
(
"is_staff",
models.BooleanField(
default=False,
help_text="Designates whether the user can log into this admin site.",
verbose_name="staff status",
),
),
(
"is_active",
models.BooleanField(
default=True,
help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
verbose_name="active",
),
),
(
"date_joined",
models.DateTimeField(
default=django.utils.timezone.now, verbose_name="date joined"
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"email",
models.EmailField(
max_length=254, unique=True, verbose_name="사용자 이메일 주소"
),
),
("school", models.CharField(null=True, verbose_name="학교 코드")),
(
"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",
),
),
(
"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={
"db_table": "user",
},
managers=[
("objects", django.contrib.auth.models.UserManager()),
],
),
]
Empty file.
19 changes: 19 additions & 0 deletions apps/users/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.contrib.auth.models import AbstractUser
from django.db import models

from core.models import TimeStampedModel


class User(TimeStampedModel, AbstractUser):
email = models.EmailField(
"사용자 이메일 주소",
unique=True,
)

school = models.CharField(
"학교 코드",
null=True,
)

class Meta:
db_table = "user"
18 changes: 18 additions & 0 deletions apps/users/services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import logging

from django.db import transaction

from apps.users.models import User
from apps.users.tasks import send_email_verify_code


class UserVerificationService:

@transaction.atomic
def send_verification_code(self, email: str) -> None:
User.objects.get_or_create(
email=email,
defaults={"is_active": False},
)

send_email_verify_code.delay(email=email)
41 changes: 41 additions & 0 deletions apps/users/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import random

from celery import shared_task
from django.conf import settings
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string

from core.cache.cache import Cache
from core.cache.prefix import CacheKeyPrefix


@shared_task()
def send_email_verify_code(email: str) -> None:
code = random.randint(100000, 999999)

Cache.set(
prefix=CacheKeyPrefix.email_verification_code,
key=email,
value=code,
timeout=60 * 60,
)

html_content = render_to_string(
template_name="verify_code.html",
context={
"recipient_name": email,
"verification_code": code,
},
)

email = EmailMultiAlternatives(
subject=f"Jusicool 메일 인증 코드",
body=html_content,
to=[email],
from_email=settings.EMAIL_HOST_USER,
)
email.attach_alternative(
html_content,
"text/html",
)
email.send()
7 changes: 7 additions & 0 deletions config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Django가 시작될 때 Celery app을 로드합니다.
"""

from .celery import app as celery_app

__all__ = ("celery_app",)
6 changes: 6 additions & 0 deletions config/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from celery import Celery

app = Celery("jusicool")
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks()
app.conf.timezone = "Asia/Seoul"
Loading
Loading