fix: move implementation to "internal" package
This commit was merged in pull request #138.
This commit is contained in:
89
internal/types/auth.go
Normal file
89
internal/types/auth.go
Normal file
@@ -0,0 +1,89 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user