Some checks failed
Build Docker Image / Build-Docker-Image (push) Failing after 3m23s
77 lines
1.6 KiB
Go
77 lines
1.6 KiB
Go
package types
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type User struct {
|
|
Id uuid.UUID
|
|
GroupId 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
|
|
UserId uuid.UUID
|
|
CreatedAt time.Time
|
|
ExpiresAt time.Time
|
|
}
|
|
|
|
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,
|
|
}
|
|
}
|