gum

package module
v0.0.0-...-f98d395 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 7 Imported by: 0

README

GUM (WIP)

Do not use!!! Lib in development.

GoUserManager: A Golang library for seamless user management and authentication

A reusable, databse agnostic library to handle repeatative functions like user record management, authentication and all other related tasks, like passoword reset.

Requirements

  • Mockable
  • Testable
  • Database agnostic

ToDo

functions

  • lib main struct and init function
  • CRUD user
  • change password (with active password or otp)
  • generate otp
  • get/list/create/update/delete roles
  • get/list/create/update/delete permissions
  • add/remove permissions to/from roles
  • assign/unassign roles to/from users
  • get user by id
  • get user by email
  • authenticate
  • 2fa function
  • database abstraction using repository pattern
  • postgress support

Project sturcture

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GetPasswordRequest

type GetPasswordRequest struct {
	ID     string `json:"id"`
	UserID string `json:"userId"`
}

GetPasswordRequest is request body for getting a password. Either ID or UserID is required.

type GetUserRequest

type GetUserRequest struct {
	ID    string `json:"id"`
	Email string `json:"email"`
}

GetUserRequest is request body for getting a user. Either ID or Email is required.

type Gum

type Gum struct {
	User     UserRepository     // User repository
	Password PasswordRepository // Password repository
}

Gum is the main struct that implements the Gum interface

func New

func New() *Gum

New returns a new Gum instance

type NewPassword

type NewPassword struct {
	UserID   string `json:"userId"`   // ID of the user (required)
	Password string `json:"password"` // plain text password (required)
}

NewPassword is request body for creating a new password.

type NewUser

type NewUser struct {
	Email    string `json:"email"`    // Email address of the user (required)
	Password string `json:"password"` // Password of the user (required)

	FirstName string `json:"first_name"` // First name of the user (optional)
	LastName  string `json:"last_name"`  // Last name of the user (optional)
}

NewUser is request body for creating a new user.

type PasswordRepository

type PasswordRepository interface {
	Create(req *NewPassword) (*models.Password, error)
	Get(req *GetPasswordRequest) (*models.Password, error)
}

PasswordRepository represents a repository for managing passwords.

type PasswordService

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

func (*PasswordService) Create

func (s *PasswordService) Create(req *NewPassword) (*models.Password, error)

Create implements PasswordRepository.Create method using bcrypt to hash the password.

func (*PasswordService) Get

Get implements PasswordRepository.Get method by getting the password from the database for the given user ID or password ID.

type User

type User struct {
	ID        string `json:"id"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Email     string `json:"email"`

	CreatedAt int64 `json:"created_at"`
	UpdatedAt int64 `json:"updated_at"`
}

User represents a single user in the system.

type UserRepository

type UserRepository interface {
	Create(req *NewUser) (*User, error)
	Update(req *User) error
	Get(req *GetUserRequest) (*User, error)
}

UserRepository represents a repository for managing users.

type UserService

type UserService struct {
	Password PasswordRepository
}

UserService implements UserRepository interface.

func (*UserService) Create

func (s *UserService) Create(req *NewUser) (*User, error)

Create creates a new user.

func (*UserService) Get

func (s *UserService) Get(req *GetUserRequest) (*User, error)

func (*UserService) Update

func (s *UserService) Update(req *User) error

Update updates an existing user.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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