Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(login): support registry lock #26

Merged
merged 2 commits into from
Jan 14, 2025
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
5 changes: 5 additions & 0 deletions apps/account/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ class OriginPasswordInvalid(APIException):
class PhoneVerifyCodeInvalid(APIException):
status_code = status.HTTP_400_BAD_REQUEST
default_detail = gettext_lazy("Phone Verify Code Invalid")


class RegistryLocked(APIException):
status_code = status.HTTP_503_SERVICE_UNAVAILABLE
default_detail = gettext_lazy("Registry Disabled")
8 changes: 8 additions & 0 deletions apps/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
WeChatAuthType,
)
from apps.account.exceptions import (
RegistryLocked,
StateInvalid,
UserNotExist,
WeChatLoginFailed,
Expand All @@ -38,6 +39,8 @@
VerifyCodeRequestSerializer,
WeChatLoginReqSerializer,
)
from apps.home.constants import BuildInKeys
from apps.home.models import MetaConfig
from core.auth import ApplicationAuthenticate
from core.utils import is_wechat

Expand Down Expand Up @@ -112,6 +115,11 @@ def sign_up(self, request, *args, **kwargs):
sign up
"""

# check registry locked
registry_lock_config: MetaConfig | None = MetaConfig.objects.filter(key=BuildInKeys.REGISTRY_LOCKED[0]).first()
if registry_lock_config and registry_lock_config.val:
raise RegistryLocked()

# validate request
request_serializer = UserRegistrySerializer(data=request.data, context={"user_ip": get_ip(request)})
request_serializer.is_valid(raise_exception=True)
Expand Down
1 change: 1 addition & 0 deletions apps/home/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ class BuildInKeys:
PRIVACY_AGREEMENT: CONFIG_DEFAULT_T = "privacy_agreement", ""
BACKGROUND_IMAGE: CONFIG_DEFAULT_T = "background_image", ""
USERNAME_EXTRA_REGEX: CONFIG_DEFAULT_T = "username_extra_regex", ""
REGISTRY_LOCKED: CONFIG_DEFAULT_T = "registry_locked", ""
74 changes: 73 additions & 1 deletion locale/zh_Hans/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-12-27 13:19+0800\n"
"POT-Creation-Date: 2025-01-14 13:29+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -78,6 +78,9 @@ msgstr "原密码不正确"
msgid "Phone Verify Code Invalid"
msgstr "电话验证码错误"

msgid "Registry Disabled"
msgstr "未开放注册"

msgid "Username Cannot be Empty"
msgstr "用户名不能为空"

Expand Down Expand Up @@ -369,3 +372,72 @@ msgstr "认证 Token 非法"

msgid "App Auth Failed"
msgstr "应用鉴权失败"

msgid "Mail Address"
msgstr "邮件地址"

msgid "Code Verify Failed"
msgstr "代码验证失败"

msgid "LIST"
msgstr "LIST"

msgid "CREATE"
msgstr "CREATE"

msgid "UPDATE"
msgstr "UPDATE"

msgid "PARTIAL_UPDATE"
msgstr "PARTIAL_UPDATE"

msgid "DESTROY"
msgstr "DESTROY"

msgid "Request Failed"
msgstr "请求失败"

msgid "Server Error"
msgstr "服务器异常"

msgid "Login Required"
msgstr "未登录"

msgid "Login Failed"
msgstr "登录失败"

msgid "Permission Denied"
msgstr "未经授权"

msgid "Operate Error"
msgstr "异常操作"

msgid "Resource Not Found"
msgstr "资源未找到"

msgid "Service Closed"
msgstr "服务已关闭"

msgid "Soft Delete"
msgstr "软删除"

msgid "Invalid Page Number"
msgstr "页码错误"

msgid "TCaptcha"
msgstr "腾讯云验证码"

msgid "Success"
msgstr "成功"

msgid "Low"
msgstr "低"

msgid "High"
msgstr "高"

msgid "TCaptcha Verify Failed"
msgstr "验证码校验失败"

msgid "App Performance"
msgstr "应用性能"
Loading