Back to godoc.org

Package repository

v0.0.0-...-b033284
Latest Go to latest

The latest major version is .

Published: Apr 18, 2020 | License: Apache-2.0 | Module: github.com/calvinchengx/gin-go-pg

Index

type AccountRepo

type AccountRepo struct {
	Secret secret.Service
	// contains filtered or unexported fields
}

AccountRepo represents the client for the user table

func NewAccountRepo

func NewAccountRepo(db orm.DB, log *zap.Logger, secret secret.Service) *AccountRepo

NewAccountRepo returns an AccountRepo instance

func (*AccountRepo) ChangePassword

func (a *AccountRepo) ChangePassword(u *model.User) error

ChangePassword changes user's password

func (*AccountRepo) Create

func (a *AccountRepo) Create(u *model.User) (*model.User, error)

Create creates a new user in our database

func (*AccountRepo) CreateAndVerify

func (a *AccountRepo) CreateAndVerify(u *model.User) (*model.Verification, error)

CreateAndVerify creates a new user in our database, and generates a verification token. User active being false until after verification.

func (*AccountRepo) CreateWithMobile

func (a *AccountRepo) CreateWithMobile(u *model.User) error

CreateWithMobile creates a new user in our database with country code and mobile number

func (*AccountRepo) DeleteVerificationToken

func (a *AccountRepo) DeleteVerificationToken(v *model.Verification) error

DeleteVerificationToken sets deleted_at for an existing verification token

func (*AccountRepo) FindVerificationToken

func (a *AccountRepo) FindVerificationToken(token string) (*model.Verification, error)

FindVerificationToken retrieves an existing verification token

type RBACService

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

RBACService is RBAC application service

func NewRBACService

func NewRBACService(userRepo model.UserRepo) *RBACService

NewRBACService creates new RBAC service

func (*RBACService) AccountCreate

func (s *RBACService) AccountCreate(c *gin.Context, roleID, companyID, locationID int) bool

AccountCreate performs auth check when creating a new account Location admin cannot create accounts, needs to be fixed on EnforceLocation function

func (*RBACService) EnforceCompany

func (s *RBACService) EnforceCompany(c *gin.Context, ID int) bool

EnforceCompany checks whether the request to apply change to company data is done by the user belonging to the that company and that the user has role CompanyAdmin. If user has admin role, the check for company doesnt need to pass.

func (*RBACService) EnforceLocation

func (s *RBACService) EnforceLocation(c *gin.Context, ID int) bool

EnforceLocation checks whether the request to change location data is done by the user belonging to the requested location

func (*RBACService) EnforceRole

func (s *RBACService) EnforceRole(c *gin.Context, r model.AccessRole) bool

EnforceRole authorizes request by AccessRole

func (*RBACService) EnforceUser

func (s *RBACService) EnforceUser(c *gin.Context, ID int) bool

EnforceUser checks whether the request to change user data is done by the same user

func (*RBACService) IsLowerRole

func (s *RBACService) IsLowerRole(c *gin.Context, r model.AccessRole) bool

IsLowerRole checks whether the requesting user has higher role than the user it wants to change Used for account creation/deletion

type RoleRepo

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

RoleRepo represents the client for the role table

func NewRoleRepo

func NewRoleRepo(db *pg.DB, log *zap.Logger) *RoleRepo

NewRoleRepo returns a Role Repo instance

func (*RoleRepo) CreateRoles

func (r *RoleRepo) CreateRoles() error

CreateRoles creates role objects in our database

type UserRepo

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

UserRepo is the client for our user model

func NewUserRepo

func NewUserRepo(db orm.DB, log *zap.Logger) *UserRepo

NewUserRepo returns a new UserRepo instance

func (*UserRepo) Delete

func (u *UserRepo) Delete(user *model.User) error

Delete sets deleted_at for a user

func (*UserRepo) FindByEmail

func (u *UserRepo) FindByEmail(email string) (*model.User, error)

FindByEmail queries for a single user by email

func (*UserRepo) FindByMobile

func (u *UserRepo) FindByMobile(countryCode, mobile string) (*model.User, error)

FindByMobile queries for a single user by mobile (and country code)

func (*UserRepo) FindByToken

func (u *UserRepo) FindByToken(token string) (*model.User, error)

FindByToken queries for single user by token

func (*UserRepo) FindByUsername

func (u *UserRepo) FindByUsername(username string) (*model.User, error)

FindByUsername queries for a single user by username

func (*UserRepo) List

func (u *UserRepo) List(qp *model.ListQuery, p *model.Pagination) ([]model.User, error)

List returns list of all users retreivable for the current user, depending on role

func (*UserRepo) Update

func (u *UserRepo) Update(user *model.User) (*model.User, error)

Update updates user's contact info

func (*UserRepo) UpdateLogin

func (u *UserRepo) UpdateLogin(user *model.User) error

UpdateLogin updates last login and refresh token for user

func (*UserRepo) View

func (u *UserRepo) View(id int) (*model.User, error)

View returns single user by ID

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier