Documentation
¶
Index ¶
- Constants
- func ErrEmailOrPasswordIsNotValid() *oops.Error
- func ErrNotHavePermissionLogin() *oops.Error
- func ErrOTPTokenInvalid() *oops.Error
- func ErrTokenIsNotValid() *oops.Error
- func ErrUserBlockedTemporarily() *oops.Error
- func ErrUserExists() *oops.Error
- func ErrUserNotExists() *oops.Error
- type ActivateAccount
- type CreateAccount
- type Flag
- type IAuth
- type IOTP
- type IRole
- type ISession
- type IUser
- type Level
- type Login
- type QRCode
- type Session
- type Steps
- type User
Constants ¶
const ( // CostHashPasswordProduction is the cost of hashing password in production CostHashPasswordProduction int = 14 // CostHashPasswordDevelopment is the cost of hashing the password in development mode CostHashPasswordDevelopment int = 1 )
Variables ¶
This section is empty.
Functions ¶
func ErrEmailOrPasswordIsNotValid ¶
ErrEmailOrPasswordIsNotValid creates and returns an error when the email or password is not valid
func ErrNotHavePermissionLogin ¶
ErrNotHavePermissionLogin creates and returns an error when the user does not have permission to login
func ErrOTPTokenInvalid ¶
ErrOTPTokenInvalid creates and returns an error when validate token OTP
func ErrTokenIsNotValid ¶
ErrTokenIsNotValid creates and returns an error when the token is not valid
func ErrUserBlockedTemporarily ¶
ErrUserBlockedTemporarily creates and returns an error when the user is blocked temporarily
func ErrUserExists ¶
ErrUserExists creates and returns an error when the user already exists
func ErrUserNotExists ¶
ErrUserNotExists creates and returns an error when the user does not exists
Types ¶
type ActivateAccount ¶
type ActivateAccount struct {
ID *uuid.UUID `sql:"id"`
UserID *uuid.UUID `sql:"user_id"`
Used *bool `sql:"used"`
Valid *bool
ExpiresAt *time.Time `sql:"expires_at"`
CreatedAt *time.Time `sql:"created_at"`
}
ActivateAccount model the data to activate user account
func (*ActivateAccount) IsValid ¶
func (a *ActivateAccount) IsValid() bool
IsValid check if the token is valid
type CreateAccount ¶
type CreateAccount struct {
FirstName *string `sql:"first_name" json:"first_name"`
LastName *string `sql:"last_name" json:"last_name"`
Email *string `sql:"email" json:"email"`
Password *string `sql:"password" json:"password"`
Key *string `sql:"key" json:"-"`
}
CreateAccount models the data to create an account
func (*CreateAccount) GeneratePassword ¶
func (rr *CreateAccount) GeneratePassword() error
GeneratePassword hash user password with bcrypt
func (*CreateAccount) Prepare ¶
func (rr *CreateAccount) Prepare() (err error)
Prepare prepare data for registration
func (*CreateAccount) RefreshTokenKey ¶
func (rr *CreateAccount) RefreshTokenKey()
RefreshTokenKey generates and sets new random token key. >> invalidate previously issued tokens
func (*CreateAccount) SanitizePassword ¶
func (rr *CreateAccount) SanitizePassword()
SanitizePassword sanitize user password
type IAuth ¶
type IAuth interface {
CreateAccount(*CreateAccount) (userID *uuid.UUID, err error)
SendMailActivationAccount(email *string, token *uuid.UUID) error
GetActivateAccountToken(data *ActivateAccount) error
CreateAccessToken(userID *uuid.UUID) (*uuid.UUID, error)
MarkTokenAsUsed(token *uuid.UUID) error
AddAttempts(userID *uuid.UUID) error
LoginSteps(email *string) (*Steps, error)
}
IAuth define an interface for data layer access methods
type IOTP ¶
type IOTP interface {
GetToken(userID *uuid.UUID) (*string, *string, error)
Configure(userID *uuid.UUID, secret *string) error
Unconfigure(userID *uuid.UUID) error
}
IOTP define an interface for data layer access methods
type ISession ¶
type ISession interface {
Create(userID *uuid.UUID, clientIP, userAgent *string) (*uuid.UUID, error)
Delete(sessionID *uuid.UUID) error
}
ISession define an interface for data layer access methods
type IUser ¶
type IUser interface {
Get(user *User) error
Exist(email *string) error
Disable(userUUID *uuid.UUID) error
}
IUser define an interface for data layer access methods
type Login ¶
type Login struct {
Email *string `json:"email" binding:"required,lte=60,email"`
Password *string `json:"password" binding:"required,gte=6"`
OTP *string `json:"otp,omitempty"`
ClientIP *string `json:"-"`
UserAgent *string `json:"-"`
}
Login models the data for the user to log in with their account
func (*Login) ComparePasswords ¶
ComparePasswords compare user password and payload
func (*Login) SanitizePassword ¶
func (l *Login) SanitizePassword()
SanitizePassword sanitize user password
type QRCode ¶
type QRCode struct {
Url *string `json:"url,omitempty"`
}
QRCode wraps the data to return the qr code url
type Session ¶
type Session struct {
SessionID *uuid.UUID `json:"session_id,omitempty"`
UserID *uuid.UUID `json:"user_id,omitempty"`
Email *string `json:"email,omitempty"`
FirstName *string `json:"first_name,omitempty"`
LastName *string `json:"last_name,omitempty"`
Level *Level `json:"level,omitempty"`
Token *string `json:"token,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
RawData map[string]any `json:"data,omitempty"`
}
Session models the data of a user session
type User ¶
type User struct {
ID *uuid.UUID
Email *string
Password *string `json:"-"`
FirstName *string
LastName *string
Flag *Flag
Level *Level
Blocked *bool
Key *string
Active *bool
OTPToken *string
OTPEnable *bool
OTPSetUp *bool
CreatedBy *uuid.UUID
CreatedAt *time.Time
LastLogin *time.Time
}