muxi feng commited on
Commit
77cd7c5
·
1 Parent(s): 1e59d48

修改注册逻辑

Browse files
app/api/user/loginadmin/route.ts ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { NextRequest } from "next/server";
2
+
3
+ export async function POST(req: NextRequest) {
4
+ try {
5
+ const admin=process.env.ADMIN
6
+ const key=process.env.LOGIN_KEY
7
+ const password=process.env.PASSWORD
8
+ const formData = new FormData();
9
+ formData.append("user",String(admin))
10
+ formData.append("key",String(key))
11
+ formData.append("password",String(password))
12
+ let res=await fetch("https://dujiaoka.dwzynj.top/main/user/login.php?", {
13
+ method: "POST",
14
+ body:formData
15
+ })
16
+ let msg=await res.json()
17
+ // console.log(msg)
18
+ return new Response(JSON.stringify(msg))
19
+ } catch (e) {
20
+ console.error("[shuixian] ", e);
21
+ return new Response(JSON.stringify(e));
22
+ }
23
+ }
app/api/user/register/route.ts CHANGED
@@ -3,7 +3,7 @@ import { NextRequest } from "next/server";
3
  export async function POST(req: NextRequest) {
4
  try {
5
  const admin=process.env.ADMIN
6
- const token=process.env.SHUI_XIAN_TOKEN
7
  const user=req.nextUrl.searchParams.get("user")
8
  const password=req.nextUrl.searchParams.get("password")
9
  const name=req.nextUrl.searchParams.get("name")
 
3
  export async function POST(req: NextRequest) {
4
  try {
5
  const admin=process.env.ADMIN
6
+ const token=req.nextUrl.searchParams.get("token")
7
  const user=req.nextUrl.searchParams.get("user")
8
  const password=req.nextUrl.searchParams.get("password")
9
  const name=req.nextUrl.searchParams.get("name")
app/store/user.ts CHANGED
@@ -157,26 +157,35 @@ export const useUserStore = create<UserStore>()(
157
  }
158
  },
159
  async register(user, password, name, mail, code) {
160
- let res = await fetch(
161
- "/api/user/register?user=" +
162
- user +
163
- "&password=" +
164
- password +
165
- "&name=" +
166
- name,
167
- {
168
  method: "POST",
169
  },
170
  );
171
- let response = (await res.json()) as shuixianRes;
172
- console.log(response);
173
- if (response.code == 1) {
174
- showToast(response.msg);
175
- setTimeout(() => {
176
- window.location.href = "/#/login";
177
- }, 1000);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  } else {
179
- showToast(response.msg);
180
  }
181
  },
182
  async getMailCode(user: string, mail: string) {
 
157
  }
158
  },
159
  async register(user, password, name, mail, code) {
160
+ let login = await fetch("/api/user/loginadmin",{
 
 
 
 
 
 
 
161
  method: "POST",
162
  },
163
  );
164
+ let response1 = (await login.json()) as shuixianRes;
165
+ if (response1.code == 1) {
166
+ let res = await fetch(
167
+ "/api/user/register?user=" +
168
+ user +
169
+ "&password=" +
170
+ password +
171
+ "&name=" +
172
+ name+"&token="+response1.token,
173
+ {
174
+ method: "POST",
175
+ },
176
+ );
177
+ let response = (await res.json()) as shuixianRes;
178
+ console.log(response);
179
+ if (response.code == 1) {
180
+ showToast("注册成功");
181
+ setTimeout(() => {
182
+ window.location.href = "/#/login";
183
+ }, 1000);
184
+ } else {
185
+ showToast(response.msg);
186
+ }
187
  } else {
188
+ showToast("注册异常");
189
  }
190
  },
191
  async getMailCode(user: string, mail: string) {