🚀 Initial commit - PDIMaker v1.0.0
Sistema completo de gestão de PDI com: - Autenticação com email/senha e Google OAuth - Workspaces privados isolados - Sistema de convites com código único - Interface profissional com Next.js 14 - Backend NestJS com PostgreSQL - Docker com Nginx e SSL Desenvolvido por Sergio Correa
This commit is contained in:
41
frontend/lib/utils/invite-code.ts
Normal file
41
frontend/lib/utils/invite-code.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
// lib/utils/invite-code.ts
|
||||
import crypto from "crypto"
|
||||
|
||||
/**
|
||||
* Gera um código de convite único
|
||||
* Formato: cmhrtjzk6001jox4z9dzb5al
|
||||
*/
|
||||
export function generateInviteCode(): string {
|
||||
return crypto
|
||||
.randomBytes(16)
|
||||
.toString("base64")
|
||||
.replace(/[^a-z0-9]/gi, "")
|
||||
.toLowerCase()
|
||||
.substring(0, 24)
|
||||
}
|
||||
|
||||
/**
|
||||
* Valida formato do código de convite
|
||||
*/
|
||||
export function isValidInviteCode(code: string): boolean {
|
||||
return /^[a-z0-9]{24}$/.test(code)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gera slug único para workspace
|
||||
* Formato: employee-name-manager-name-xyz123
|
||||
*/
|
||||
export function generateWorkspaceSlug(employeeName: string, managerName: string): string {
|
||||
const slugify = (text: string) =>
|
||||
text
|
||||
.toLowerCase()
|
||||
.normalize("NFD")
|
||||
.replace(/[\u0300-\u036f]/g, "")
|
||||
.replace(/[^a-z0-9]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "")
|
||||
.substring(0, 20)
|
||||
|
||||
const random = crypto.randomBytes(3).toString("hex")
|
||||
return `${slugify(employeeName)}-${slugify(managerName)}-${random}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user