-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
优化了单例模式,数据库以及vite的读取环境变量分别作为单例,都使用饿汉模式,时项目更加简洁。优化了所有模块的代码,与之前对比有明显的差别
- Loading branch information
1 parent
10d4982
commit d174b3d
Showing
14 changed files
with
587 additions
and
486 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as dotenv from "dotenv"; | ||
|
||
dotenv.configDotenv(); | ||
|
||
export interface Config { | ||
secretKey : string; | ||
accessTokenExpiration : number; | ||
refreshTokenExpiration: number; | ||
systemEmail : string; | ||
systemEmailPassword : string; | ||
verificationCodeLen : number; | ||
verificationMaxCount : number; | ||
} | ||
|
||
export class ConfigService { | ||
private static config: Config; | ||
private constructor() { } | ||
public static getConfig() { | ||
if (!ConfigService.config) { | ||
ConfigService.config = { | ||
secretKey : process.env.SECRET_KEY || "", | ||
accessTokenExpiration : parseInt(process.env.ACCESS_TOKEN_EXPIRATION) || 0, | ||
refreshTokenExpiration: parseInt(process.env.REFRESH_TOKEN_EXPIRATION) || 0, | ||
systemEmail : process.env.SYSTEM_EMAIL || "", | ||
systemEmailPassword : process.env.SYSTEM_EMAIL_PASSWORD || "", | ||
verificationCodeLen : parseInt(process.env.VERIFICATION_CODE_LEN) || 4, | ||
verificationMaxCount : parseInt(process.env.VERIFICATION_MAX_COUNT) || 5, | ||
}; | ||
} | ||
return ConfigService.config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { UserInfo } from "../entity/UserInfo"; | ||
|
||
export async function findExistingUser(id: number = null, email: string = null, passwordHash: string = null): Promise<UserInfo | null> { | ||
if (id) { | ||
const userById = await this.UserInfoRepository.findOneBy({ id: id, activated: true }); | ||
if (userById) { | ||
return userById; | ||
} | ||
} else if (email) { | ||
const queryBuilder = this.UserInfoRepository | ||
.createQueryBuilder("user") | ||
.where("user.email = :email AND user.activated = 1", { email }); | ||
|
||
if (passwordHash) { | ||
queryBuilder.andWhere("user.passwordHash = :passwordHash", { passwordHash }); | ||
} | ||
|
||
const userByEmail = await queryBuilder.getOne(); | ||
return userByEmail; | ||
} | ||
return null; | ||
} |
Oops, something went wrong.