Skip to content

Commit

Permalink
🎈 Merge pull request #176 from ileostar/ui/update-homepage
Browse files Browse the repository at this point in the history
💄 update background
  • Loading branch information
ileostar authored Aug 24, 2024
2 parents 4448958 + 91a153e commit 967cb74
Show file tree
Hide file tree
Showing 54 changed files with 14,920 additions and 6,790 deletions.
6 changes: 4 additions & 2 deletions apps/server/src/modules/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ export class UserService {
async updateUserInfos(dto: UpdateUserDto) {
const old = await this.findUserByUserId(dto.userId);
if (!old) throw '用户ID不存在';
const tempUser = await this.findUserByUsername(dto.username);
if (dto.username && tempUser.userId !== dto.userId) throw '用户名已存在';
if (dto.username) {
const tempUser = await this.findUserByUsername(dto.username);
if (!!tempUser && tempUser.userId !== dto.userId) throw '用户名已存在';
}
await this.db.update(user).set(dto).where(eq(user.id, dto.userId));
return dto;
}
Expand Down
98 changes: 21 additions & 77 deletions apps/web/api/auth.ts
Original file line number Diff line number Diff line change
@@ -1,89 +1,33 @@
import http from "@/utils/http";
import { openCenteredOAuthPopup } from "@/utils/popup";
import { AxiosResponse } from "axios";
import io from "socket.io-client";

import { request } from "../utils/request";

interface CustomAxiosResponse<T> extends AxiosResponse<T> {
token?: string;
code?: 200 | -1;
msg?: string;
data: T;
}

interface GithubSignInResponse
extends CustomAxiosResponse<{
isSignUp: boolean;
userData: {
username: string;
[index: string]: unknown;
};
}> {}

/**
* sms短信登录
*/
export async function loginBySMS(phone: any, code: any) {
return request({
url: "/auth/phoneOtpLogin",
data: {
phone: phone,
otp: code,
},
method: "post",
});
}

/**
* 普通注册
*/
export function defaultSignUp(username: any, password: any, phone: any, otp: any) {
return request({
url: "/auth/signup",
data: {
username,
password,
phone,
otp,
},
method: "post",
});
import {
defaultSignInBody,
defaultSignInResponse,
defaultSignUpBody,
GithubSignInResponse,
loginBySMSBody,
loginBySMSResponse,
} from "./types/auth";
import { ResponseData } from "./types/common";

/** 普通登录 */
export function defaultSignIn(body: defaultSignInBody) {
return http.post<ResponseData<defaultSignInResponse>>("/auth/login", body);
}

/**
* 普通登录
*/
export function defaultSignIn(identifier: any, password: any) {
return request({
url: "/auth/login",
data: {
identifier,
password,
},
method: "post",
});
/** 短信登录 */
export function loginBySMS(body: loginBySMSBody) {
return http.post<ResponseData<loginBySMSResponse>>("/auth/phoneOtpLogin", body);
}

/**
* 谷歌登录
*/
export function googleSignIn() {
const socket = io("http://localhost:3001"); // 连接到你的NestJS WebSocket服务器

const authWindow = openCenteredOAuthPopup("http://127.0.0.1:3001/auth/google/callback", 600, 500);
socket.on("connect", () => {
console.log("Connected to the server!");
});
socket.on("messageToAll", (data: any) => {
console.log("Received message from server:", JSON.parse(data));
authWindow!.close();
socket.close();
});
/** 普通注册 */
export function defaultSignUp(body: defaultSignUpBody) {
return http.post<ResponseData<null>>("/auth/signup", body);
}

/**
* github登录
*/
/** github登录 */
export async function githubSignIn(): Promise<GithubSignInResponse> {
const socket = io("http://localhost:3001");

Expand Down
80 changes: 20 additions & 60 deletions apps/web/api/email.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,29 @@
import { AxiosResponse } from "axios";
import http from "@/utils/http";

import { request } from "../utils/request";
import { ResponseData } from "./types/common";
import {
bindEmailBody,
sendCodeByEmailBody,
updateEmailBody,
verifyEmailBody,
} from "./types/email";

interface CustomAxiosResponse<T = any> extends AxiosResponse<T> {
token?: any;
code?: any;
msg?: any;
/** 发送邮箱验证码 */
export function sendCodeByEmail(body: sendCodeByEmailBody) {
return http.post<ResponseData<null>>("/mail/sendCode", body);
}

//发送邮箱验证码
export function sendCodeByEmail(email: string): Promise<CustomAxiosResponse> {
return request({
url: "/mail/sendCode",
params: {
email: email,
},
method: "get",
});
/** 更换邮箱 */
export function updateEmail(body: updateEmailBody) {
return http.put<ResponseData<null>>("/mail", body);
}

//更换邮箱
export function updateEmail(
userId: string,
email: string,
otp: string,
): Promise<CustomAxiosResponse> {
return request({
url: "/mail",
data: {
email,
userId,
otp,
},
method: "put",
});
/** 绑定邮箱 */
export function bindEmail(body: bindEmailBody) {
return http.post<ResponseData<null>>("/mail/bind", body);
}

//绑定邮箱
export function bindEmail(
userId: string,
email: string,
otp: string,
): Promise<CustomAxiosResponse> {
return request({
url: "/mail/bind",
data: {
email,
userId,
otp,
},
method: "post",
});
}

//验证邮箱
export function verifyEmail(
email: string,
otp: string,
): Promise<CustomAxiosResponse> {
return request({
url: "/mail/verify",
data: {
email,
otp
},
method: "post",
});
/** 验证邮箱 */
export function verifyEmail(body: verifyEmailBody) {
return http.post<ResponseData<null>>("/mail/verify", body);
}
59 changes: 15 additions & 44 deletions apps/web/api/sms.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,19 @@
import { AxiosResponse } from "axios";
import { request } from "../utils/request";
import http from "@/utils/http";

interface CustomAxiosResponse<T = any> extends AxiosResponse<T> {
code?: any;
msg?: any;
}
import { ResponseData } from "./types/common";
import { sendBySMSBody, updatePhoneBody, verifyPhoneBody } from "./types/sms";

/**
* sms发送短信
*/
export function sendBySMS(phone: any) {
return request({
url: "/sms/sendCode",
data: {
phone: phone,
},
method: "post",
});
}
/** 发送短信 */
export function sendBySMS(body: sendBySMSBody) {
return http.post<ResponseData<null>>("/sms/sendCode", body);
}

/**
* 手机号验证
*/
export function verifyPhone(phone: any,otp:any): Promise<CustomAxiosResponse> {
return request({
url: "/sms/verify",
data: {
phone: phone,
otp:otp
},
method: "post",
});
}
/** 手机号验证 */
export function verifyPhone(body: verifyPhoneBody) {
return http.post<ResponseData<null>>("/sms/verify", body);
}

/**
* 更换手机号
*/
export function updatePhone(phone: any,otp:any): Promise<CustomAxiosResponse> {
return request({
url: "/sms",
data: {
phone: phone,
otp:otp
},
method: "put",
});
}
/** 更换手机号 */
export function updatePhone(body: updatePhoneBody) {
return http.put<ResponseData<null>>("/sms", body);
}
37 changes: 37 additions & 0 deletions apps/web/api/types/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ResponseData } from "./common";

export type defaultSignInBody = {
identifier: string;
password: string;
};

export type defaultSignInResponse = {
userId: string;
userName: string;
phone: string;
role: string;
email: string | null;
};

export type loginBySMSBody = {
phone: string;
otp: string;
};

export type loginBySMSResponse = defaultSignInResponse;

export type defaultSignUpBody = {
username: string;
password: string | null;
phone: string;
otp: string;
};

export interface GithubSignInResponse
extends ResponseData<{
isSignUp: boolean;
userData: {
username: string;
[index: string]: unknown;
};
}> {}
8 changes: 8 additions & 0 deletions apps/web/api/types/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { AxiosResponse } from "axios";

export interface ResponseData<T> {
code: number;
msg: string;
data: T;
token?: string;
}
16 changes: 16 additions & 0 deletions apps/web/api/types/email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export type sendCodeByEmailBody = {
email: string;
};

export type updateEmailBody = {
userId: string;
email: string;
otp: string;
};

export type bindEmailBody = updateEmailBody;

export type verifyEmailBody = {
email: string;
otp: string;
};
10 changes: 10 additions & 0 deletions apps/web/api/types/sms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type sendBySMSBody = {
phone: string;
};

export type verifyPhoneBody = {
phone: string;
otp: string;
};

export type updatePhoneBody = verifyPhoneBody;
7 changes: 7 additions & 0 deletions apps/web/api/types/upload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type uploadFileBody = {
file: string;
};

export type uploadFileResponse = {
url: string;
};
16 changes: 16 additions & 0 deletions apps/web/api/types/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export type getUserInfoResponse = {
avatar: string | null;
nickname: string | null;
username: string | null;
email: string | null;
phone: string;
role: string;
};

export type updateUserInfoBody = {
avatar?: string | undefined;
nickname?: string | undefined;
username?: string | undefined;
};

export type updateUserInfoResponse = updateUserInfoBody & { userId: string };
9 changes: 9 additions & 0 deletions apps/web/api/upload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import http from "@/utils/http";

import { ResponseData } from "./types/common";
import { uploadFileResponse } from "./types/upload";

/** 发送短信 */
export function uploadFile(body: any, headers?: any) {
return http.post<ResponseData<uploadFileResponse>>("/oss/upload", body, headers);
}
Loading

0 comments on commit 967cb74

Please sign in to comment.