Skip to content

Commit 2c0afcb

Browse files
Modified
1 parent 5b1b629 commit 2c0afcb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+885
-1689
lines changed

backend/api/serializers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class UserCreateSerializer(serializers.ModelSerializer):
8989

9090
class Meta:
9191
model = User
92-
fields = ["username", "password", "password_retype"]
92+
fields = ["username", "email", "first_name", "last_name", "password", "password_retype"]
9393

9494
def validate(self, attrs):
9595
password_retype = attrs.pop("password_retype")
@@ -107,16 +107,18 @@ def validate(self, attrs):
107107
def create(self, validated_data):
108108
with transaction.atomic():
109109
user = User.objects.create_user(**validated_data)
110-
111-
# By default newly registered accounts are inactive.
112-
user.is_active = False
110+
# 新注册的用户默认为活跃状态
111+
user.is_active = True
113112
user.save(update_fields=["is_active"])
114113

115114
return user
116115

117116

118117
class UserCreateErrorSerializer(serializers.Serializer):
119118
username = serializers.ListSerializer(child=serializers.CharField(), required=False)
119+
email = serializers.ListSerializer(child=serializers.CharField(), required=False)
120+
first_name = serializers.ListSerializer(child=serializers.CharField(), required=False)
121+
last_name = serializers.ListSerializer(child=serializers.CharField(), required=False)
120122
password = serializers.ListSerializer(child=serializers.CharField(), required=False)
121123
password_retype = serializers.ListSerializer(
122124
child=serializers.CharField(), required=False

backend/api/settings.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"django.contrib.sessions",
3434
"django.contrib.messages",
3535
"django.contrib.staticfiles",
36+
"corsheaders",
3637
"rest_framework",
3738
"rest_framework_simplejwt",
3839
"drf_spectacular",
@@ -45,6 +46,7 @@
4546
MIDDLEWARE = [
4647
"django.middleware.security.SecurityMiddleware",
4748
"django.contrib.sessions.middleware.SessionMiddleware",
49+
"corsheaders.middleware.CorsMiddleware",
4850
"django.middleware.common.CommonMiddleware",
4951
"django.middleware.csrf.CsrfViewMiddleware",
5052
"django.contrib.auth.middleware.AuthenticationMiddleware",
@@ -169,3 +171,38 @@
169171
],
170172
},
171173
}
174+
175+
######################################################################
176+
# CORS
177+
######################################################################
178+
CORS_ALLOWED_ORIGINS = [
179+
"http://localhost:3000",
180+
"http://localhost:3001",
181+
"http://127.0.0.1:3000",
182+
"http://127.0.0.1:3001",
183+
]
184+
185+
CORS_ALLOW_CREDENTIALS = True
186+
187+
# 允许的 HTTP 方法
188+
CORS_ALLOW_METHODS = [
189+
"DELETE",
190+
"GET",
191+
"OPTIONS",
192+
"PATCH",
193+
"POST",
194+
"PUT",
195+
]
196+
197+
# 允许的 HTTP 头
198+
CORS_ALLOW_HEADERS = [
199+
"accept",
200+
"accept-encoding",
201+
"authorization",
202+
"content-type",
203+
"dnt",
204+
"origin",
205+
"user-agent",
206+
"x-csrftoken",
207+
"x-requested-with",
208+
]

backend/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies = [
99
"djangorestframework-simplejwt>=5.3",
1010
"drf-spectacular>=0.28",
1111
"django-unfold>=0.43.0",
12+
"django-cors-headers>=4.6.0",
1213
]
1314

1415
[dependency-groups]

backend/uv.lock

Lines changed: 121 additions & 105 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/apps/web/actions/change-password-action.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

frontend/apps/web/actions/delete-account-action.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

frontend/apps/web/actions/profile-action.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

frontend/apps/web/actions/register-action.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
1-
import { profileAction } from '@/actions/profile-action'
2-
import { ProfileForm } from '@/components/forms/profile-form'
3-
import { getApiClient } from '@/lib/api'
4-
import { authOptions } from '@/lib/auth'
5-
import type { Metadata } from 'next'
6-
import { getServerSession } from 'next-auth'
1+
import { ProfileForm } from "@/components/forms/profile-form";
2+
import type { Metadata } from "next";
73

84
export const metadata: Metadata = {
9-
title: 'Profile - Turbo'
10-
}
11-
12-
export default async function Profile() {
13-
const session = await getServerSession(authOptions)
14-
const apiClient = await getApiClient(session)
5+
title: "Profile - Turbo",
6+
};
157

16-
return (
17-
<ProfileForm
18-
currentUser={apiClient.users.usersMeRetrieve()}
19-
onSubmitHandler={profileAction}
20-
/>
21-
)
8+
export default function Profile() {
9+
return <ProfileForm />;
2210
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { registerAction } from '@/actions/register-action'
2-
import { RegisterForm } from '@/components/forms/register-form'
3-
import type { Metadata } from 'next'
1+
import { RegisterForm } from "@/components/forms/register-form";
2+
import type { Metadata } from "next";
43

54
export const metadata: Metadata = {
6-
title: 'Register - Turbo'
7-
}
5+
title: "Register - Turbo",
6+
};
87

98
export default function Register() {
10-
return <RegisterForm onSubmitHandler={registerAction} />
9+
return <RegisterForm />;
1110
}

0 commit comments

Comments
 (0)