feat: #337 unify types for auth module
This commit was merged in pull request #338.
This commit is contained in:
75
types/auth.go
Normal file
75
types/auth.go
Normal file
@@ -0,0 +1,75 @@
|
||||
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
|
||||
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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user