domain

package
v0.0.0-...-ae0e7a4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package domain contains the domain models and business logic for the application

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPasswordMaxLength error for password too long
	ErrPasswordMaxLength = errors.New("password too long")
	// ErrPasswordMinLength error for password too short
	ErrPasswordMinLength = errors.New("password too short")
	// ErrUniqueViolation postgres unique key violation
	ErrUniqueViolation = errors.New("unique key violation")
	// ErrForeignKeyViolation postgres foreign key violation
	ErrForeignKeyViolation = errors.New("foreign key violation")
	// ErrInvalidOldPassword invalid old password
	ErrInvalidOldPassword = errors.New("invalid old password")
	// ErrEntityNotFound entity not found
	ErrEntityNotFound = errors.New("entity not found")
	// ErrInvalidPassword invalid password
	ErrInvalidPassword = errors.New("invalid password")
	// ErrInvalidTOTPCode invalid totp code
	ErrInvalidTOTPCode = errors.New("invalid totp code")
)

Functions

This section is empty.

Types

type AuthService

type AuthService struct {
	// contains filtered or unexported fields
}

AuthService application layer logic for users

func NewAuthService

func NewAuthService(db *sql.DB, otp totp.ITOTP) *AuthService

NewAuthService create new user service instance

func (*AuthService) AssignRolePermission

func (as *AuthService) AssignRolePermission(ctx context.Context, roleID uuid.UUID, perm PermissionType) error

AssignRolePermission assign role permission

func (*AuthService) AssignUserRole

func (as *AuthService) AssignUserRole(ctx context.Context, userID uuid.UUID, roleID uuid.UUID) error

AssignUserRole assign user role

func (*AuthService) CreateRole

func (as *AuthService) CreateRole(ctx context.Context, newRole *NewRole) (*Role, error)

CreateRole create role

func (*AuthService) CreateUser

func (as *AuthService) CreateUser(ctx context.Context, newUser *NewUser) (*User, map[string]string, error)

CreateUser validate password, hash password and create user

func (*AuthService) CreateUserSession

func (as *AuthService) CreateUserSession(ctx context.Context, newSession *NewSession) (uuid.UUID, error)

CreateUserSession create session

func (*AuthService) DeleteUser

func (as *AuthService) DeleteUser(ctx context.Context, id uuid.UUID) error

DeleteUser delete user

func (*AuthService) DeleteUserSession

func (as *AuthService) DeleteUserSession(ctx context.Context, sessionUUID uuid.UUID) error

DeleteUserSession delete session

func (*AuthService) GetUserPermissions

func (as *AuthService) GetUserPermissions(ctx context.Context, userID uuid.UUID) (map[string]string, error)

GetUserPermissions get user permissions

func (*AuthService) ListSubscriptions

func (as *AuthService) ListSubscriptions(ctx context.Context) ([]string, error)

ListSubscriptions list service subscriptions

func (*AuthService) ListUserRoles

func (as *AuthService) ListUserRoles(ctx context.Context, userID uuid.UUID) ([]*Role, error)

ListUserRoles list user roles

func (*AuthService) PersistToken

func (as *AuthService) PersistToken(ctx context.Context, userID uuid.UUID, token string) error

PersistToken persist user refresh token

func (*AuthService) ReadUserByEmail

func (as *AuthService) ReadUserByEmail(ctx context.Context, email string) (*User, error)

ReadUserByEmail read user by email

func (*AuthService) ReadUserByID

func (as *AuthService) ReadUserByID(ctx context.Context, id uuid.UUID) (*User, error)

ReadUserByID read user by id

func (*AuthService) ReadUserSession

func (as *AuthService) ReadUserSession(ctx context.Context, sessionUUID uuid.UUID) (*Session, error)

ReadUserSession read session

func (*AuthService) RemoveRolePermission

func (as *AuthService) RemoveRolePermission(ctx context.Context, roleID uuid.UUID) error

RemoveRolePermission remove role permission

func (*AuthService) RemoveUserRole

func (as *AuthService) RemoveUserRole(ctx context.Context, userID uuid.UUID, roleID uuid.UUID) error

RemoveUserRole remove user role

func (*AuthService) UpdateUser

func (as *AuthService) UpdateUser(ctx context.Context, updateUser *UpdateUser) (*User, error)

UpdateUser update user

func (*AuthService) UpdateUserPassword

func (as *AuthService) UpdateUserPassword(ctx context.Context, updatePassword *UpdatePassword) error

UpdateUserPassword update user password

func (*AuthService) UserLogin

func (as *AuthService) UserLogin(ctx context.Context, login *UserLogin) (uuid.UUID, error)

UserLogin validate password, hash password and create session

func (*AuthService) VerifyOTP

func (as *AuthService) VerifyOTP(ctx context.Context, sessionID uuid.UUID, code string) error

VerifyOTP verify totp code

type NewRole

type NewRole struct {
	Name string
}

NewRole ...

type NewSession

type NewSession struct {
	UserID uuid.UUID
	IP     string
}

NewSession ...

type NewUser

type NewUser struct {
	Email     string
	FirstName string
	LastName  string
	Password  string
}

NewUser ...

type NewUserRole

type NewUserRole struct {
	UserID uuid.UUID
	RoleID uuid.UUID
}

NewUserRole ...

type Permission

type Permission struct {
	ID        uuid.UUID
	RoleID    uuid.UUID
	Perm      PermissionType
	CreatedAt time.Time
	UpdatedAt time.Time
}

Permission ...

type PermissionType

type PermissionType string

PermissionType role permission type

const (
	// PermissionTypeRead read only permission
	PermissionTypeRead PermissionType = "read"
	// PermissionTypeWrite write only permission
	PermissionTypeWrite PermissionType = "write"
	// PermissionTypeEdit edit permission
	PermissionTypeEdit PermissionType = "edit"
)

func (PermissionType) String

func (p PermissionType) String() string

String stringify permission type

type Role

type Role struct {
	ID        uuid.UUID
	Name      string
	CreatedAt time.Time
	UpdatedAt time.Time
}

Role ...

type Session

type Session struct {
	ID     uuid.UUID
	UserID uuid.UUID
}

Session ...

type UpdatePassword

type UpdatePassword struct {
	ID          uuid.UUID
	OldPassword string
	NewPassword string
}

UpdatePassword ...

type UpdateUser

type UpdateUser struct {
	ID        uuid.UUID
	Email     string
	FirstName string
	LastName  string
}

UpdateUser ...

type User

type User struct {
	ID        uuid.UUID
	Email     string
	FirstName string
	LastName  string
	Password  string
	CreatedAt time.Time
	UpdatedAt time.Time
}

User ...

type UserLogin

type UserLogin struct {
	Email    string
	Password string
	IP       string
}

UserLogin ...

type UserRole

type UserRole struct {
	RoleID uuid.UUID
	UserID uuid.UUID
}

UserRole ...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL