90 lines
1.7 KiB
Go
90 lines
1.7 KiB
Go
package types
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type User struct {
|
|
Id uuid.UUID
|
|
Email string
|
|
EmailVerified bool
|
|
EmailVerifiedAt *time.Time
|
|
IsAdmin bool
|
|
Password []byte
|
|
Salt []byte
|
|
CreateAt time.Time
|
|
}
|
|
|
|
func NewUser(
|
|
id uuid.UUID,
|
|
email string,
|
|
emailVerified bool,
|
|
emailVerifiedAt *time.Time,
|
|
isAdmin bool,
|
|
password []byte,
|
|
salt []byte,
|
|
createAt time.Time) *User {
|
|
return &User{
|
|
Id: id,
|
|
Email: email,
|
|
EmailVerified: emailVerified,
|
|
EmailVerifiedAt: emailVerifiedAt,
|
|
IsAdmin: isAdmin,
|
|
Password: password,
|
|
Salt: salt,
|
|
CreateAt: createAt,
|
|
}
|
|
}
|
|
|
|
type Session struct {
|
|
Id string `db:"session_id"`
|
|
UserId uuid.UUID `db:"user_id"`
|
|
CreatedAt time.Time `db:"created_at"`
|
|
ExpiresAt time.Time `db:"expires_at"`
|
|
}
|
|
|
|
func NewSession(id string, userId uuid.UUID, createdAt time.Time, expiresAt time.Time) *Session {
|
|
return &Session{
|
|
Id: id,
|
|
UserId: userId,
|
|
CreatedAt: createdAt,
|
|
ExpiresAt: expiresAt,
|
|
}
|
|
}
|
|
|
|
type Token struct {
|
|
UserId uuid.UUID
|
|
SessionId string
|
|
Token string
|
|
Type TokenType
|
|
CreatedAt time.Time
|
|
ExpiresAt time.Time
|
|
}
|
|
|
|
type TokenType string
|
|
|
|
var (
|
|
TokenTypeEmailVerify TokenType = "email_verify"
|
|
TokenTypePasswordReset TokenType = "password_reset"
|
|
TokenTypeCsrf TokenType = "csrf"
|
|
)
|
|
|
|
func NewToken(
|
|
userId uuid.UUID,
|
|
sessionId string,
|
|
token string,
|
|
tokenType TokenType,
|
|
createdAt time.Time,
|
|
expiresAt time.Time) *Token {
|
|
return &Token{
|
|
UserId: userId,
|
|
SessionId: sessionId,
|
|
Token: token,
|
|
Type: tokenType,
|
|
CreatedAt: createdAt,
|
|
ExpiresAt: expiresAt,
|
|
}
|
|
}
|