-
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.
- Loading branch information
Showing
6 changed files
with
50 additions
and
13,850 deletions.
There are no files selected for viewing
This file was deleted.
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 |
---|---|---|
@@ -1,14 +1,23 @@ | ||
import mongoose from "mongoose"; | ||
import { z } from "zod"; | ||
|
||
export const SponsorSchema = new mongoose.Schema({ | ||
export const SponsorAuthSchema = new mongoose.Schema({ | ||
email: { type: String, required: true, unique: true }, | ||
hashedVerificationCode: { type: String, required: true }, | ||
expTime: { type: Number, required: true }, | ||
}); | ||
|
||
export const SponsorValidator = z.object({ | ||
export const SponsorAuthValidator = z.object({ | ||
email: z.string().email(), | ||
hashedVerificationCode: z.string(), | ||
expTime: z.number().int(), | ||
}); | ||
|
||
export const AuthSponsorLoginValidator = z.object({ | ||
email: z.string().email(), | ||
}); | ||
|
||
export const AuthSponsorVerifyValidator = z.object({ | ||
email: z.string().email(), | ||
sixDigitCode: z.string().length(6) | ||
}); | ||
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,23 @@ | ||
import * as bcrypt from "bcrypt"; | ||
|
||
|
||
export function createSixDigitCode() { | ||
let result = ""; | ||
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | ||
for (let i = 0; i < 6; i++) { | ||
result += chars.charAt(Math.floor(Math.random() * chars.length)); | ||
} | ||
return result; | ||
} | ||
|
||
export function encryptSixDigitCode(sixDigitCode: string): string { | ||
const saltRounds = 10; | ||
|
||
try { | ||
const hash = bcrypt.hashSync(sixDigitCode, saltRounds); | ||
return hash; | ||
} catch (err) { | ||
console.error("Error encrypting the code:", err); | ||
throw err; | ||
} | ||
} |