auth

package
v1.0.70 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 8 Imported by: 3

Documentation

Overview

Package Auth

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Checklogin

func Checklogin(Lc LoginCheck, db *gorm.DB, secretkey string) (string, int, error)

Check UserName Password

func CreateToken

func CreateToken(userid, roleid int, secretkey string) (string, error)

CreateToken creates a token with the given claims

func Difference

func Difference(a, b []int) (diff []int)

Set Difference: A - B

func MigrationTable

func MigrationTable(db *gorm.DB)

func VerifyToken

func VerifyToken(token string, secret string) (userid, roleid int, err error)

verify token

func VerifyTokenWithExpiryTime added in v1.0.64

func VerifyTokenWithExpiryTime(token string, secret string, currentTime int64) (int, int, error)

Types

type Action

type Action string
const (
	Create Action = "Create"

	Read Action = "View"

	Update Action = "Update"

	Delete Action = "Delete"

	CRUD Action = "CRUD"
)

type Authorization

type Authorization struct {
	DB     *gorm.DB
	Token  string
	Secret string
}

func (Authorization) IsGranted

func (a Authorization) IsGranted(modulename string, permisison Action) (bool, error)

Check User Permission

type Authstruct

type Authstruct struct{}
var AS Authstruct

func (Authstruct) CheckPermissionIdExist

func (as Authstruct) CheckPermissionIdExist(roleperm *[]TblRolePermission, roleid int, permissionid []int, DB *gorm.DB) error

func (Authstruct) CheckPermissionIdNotExist

func (as Authstruct) CheckPermissionIdNotExist(roleperm *[]TblRolePermission, roleid int, permissionid []int, DB *gorm.DB) error

func (Authstruct) CheckRoleExists

func (as Authstruct) CheckRoleExists(role *TblRole, id int, name string, DB *gorm.DB) error

Check role

func (Authstruct) CreateModulePermission

func (as Authstruct) CreateModulePermission(modpermission *TblModulePermission, DB *gorm.DB) (modper *TblModulePermission, err error)

create json module permission

func (Authstruct) CreateRolePermission

func (as Authstruct) CreateRolePermission(roleper *[]TblRolePermission, DB *gorm.DB) error

bulk creation

func (Authstruct) CreateRolePermissionsingle

func (as Authstruct) CreateRolePermissionsingle(roleper *TblRolePermission, DB *gorm.DB) error

single creation

func (Authstruct) DeleteModulePermissioninEntries

func (as Authstruct) DeleteModulePermissioninEntries(tblmodper *TblModulePermission, id string, DB *gorm.DB) error

func (Authstruct) DeleteRolePermissionById

func (as Authstruct) DeleteRolePermissionById(roleper *[]TblRolePermission, roleid int, DB *gorm.DB) error

func (Authstruct) Deleterolepermission

func (as Authstruct) Deleterolepermission(TblRolePermission *TblRolePermission, id int, DB *gorm.DB) error

Delete Role Permission by id

func (Authstruct) GetAllModules

func (as Authstruct) GetAllModules(mod *[]TblModule, limit, offset, id int, filter Filter, DB *gorm.DB) (count int64)

This is for assign permission

func (Authstruct) GetAllParentModules1

func (as Authstruct) GetAllParentModules1(mod *[]TblModule, DB *gorm.DB) (err error)

func (Authstruct) GetAllRoles

func (as Authstruct) GetAllRoles(role *[]TblRole, limit, offset int, filter Filter, DB *gorm.DB) (rolecount int64, err error)

get all roles

func (Authstruct) GetAllSubModules

func (as Authstruct) GetAllSubModules(mod *[]TblModule, ids []int, DB *gorm.DB) (err error)

func (Authstruct) GetIdByRouteName

func (as Authstruct) GetIdByRouteName(tblmodper *TblModulePermission, id string, DB *gorm.DB) error

Get Id by RouteName

func (Authstruct) GetPermissionId

func (as Authstruct) GetPermissionId(perm *[]TblRolePermission, roleid int, DB *gorm.DB) error

Get PermissionId By RoleId

func (Authstruct) GetRoleById

func (as Authstruct) GetRoleById(role *TblRole, id int, DB *gorm.DB) error

Get role by id

func (Authstruct) GetRolesData

func (as Authstruct) GetRolesData(roles *[]TblRole, DB *gorm.DB) error

func (Authstruct) RoleCreate

func (as Authstruct) RoleCreate(role *TblRole, DB *gorm.DB) error

Roels Insert

func (Authstruct) RoleDelete

func (as Authstruct) RoleDelete(role *TblRole, id int, DB *gorm.DB) error

Delete the role data

func (Authstruct) RoleIsActive

func (as Authstruct) RoleIsActive(role *TblRole, id, val int, DB *gorm.DB) error

update role isactive

func (Authstruct) RoleUpdate

func (as Authstruct) RoleUpdate(role *TblRole, DB *gorm.DB) error

func (Authstruct) UpdateChannelNameInEntries

func (as Authstruct) UpdateChannelNameInEntries(modper *TblModulePermission, DB *gorm.DB) error

update channel entry permission

type Filter

type Filter struct {
	Keyword  string
	Category string
	Status   string
	FromDate string
	ToDate   string
}

type LoginCheck

type LoginCheck struct {
	Username string
	Password string
}

type MultiPermissin

type MultiPermissin struct {
	RoleId int
	Ids    []int
}

type Option

type Option struct {
	DB     *gorm.DB
	Token  string
	Secret string
}

type Permission

type Permission struct {
	ModuleName string
	Action     []string //create,View,update,delete

}

type PermissionAu

type PermissionAu struct {
	Auth Authorization
}

this struct holds dbconnection ,token

func (PermissionAu) CreatePermission

func (a PermissionAu) CreatePermission(Perm MultiPermissin) error

create permission

func (PermissionAu) CreateUpdatePermission

func (a PermissionAu) CreateUpdatePermission(Perm MultiPermissin) error

update permission

func (PermissionAu) GetPermissionDetailsById

func (a PermissionAu) GetPermissionDetailsById(roleid int) (rolepermissionid []int, err error)

permission List

func (PermissionAu) PermissionListRoleId

func (a PermissionAu) PermissionListRoleId(limit, offset, roleid int, filter Filter) (Module []TblModule, count int64, err error)

permission List

type Role

type Role struct {
	Auth Authorization
}

this struct holds dbconnection ,token

func (Role) CheckRoleAlreadyExists

func (a Role) CheckRoleAlreadyExists(roleid int, rolename string) (bool, error)

Check Role Already Exists

func (Role) CreateRole

func (a Role) CreateRole(rolec RoleCreation) (TblRole, error)

create role

func (Role) DeleteRole

func (a Role) DeleteRole(roleid int) (bool, error)

delete role

func (Role) GetAllRoleData

func (a Role) GetAllRoleData() (roles []TblRole, err error)

func (Role) GetRoleById

func (a Role) GetRoleById(roleid int) (tblrole TblRole, err error)

get role by id

func (Role) RoleList

func (a Role) RoleList(limit int, offset int, filter Filter) (roles []TblRole, rolecount int64, err error)

create role

func (Role) RoleStatus

func (a Role) RoleStatus(roleid int, status int) (err error)

change role status 0-inactive, 1-active

func (Role) UpdateRole

func (a Role) UpdateRole(rolec RoleCreation, roleid int) (role TblRole, err error)

update role

type RoleCreation

type RoleCreation struct {
	Name        string
	Description string
}

type TblModule

type TblModule struct {
	Id                  int `gorm:"primaryKey;auto_increment"`
	ModuleName          string
	IsActive            int
	CreatedBy           int
	CreatedOn           time.Time
	CreatedDate         string `gorm:"-:migration;<-:false"`
	DefaultModule       int
	ParentId            int
	IconPath            string
	TblModulePermission []TblModulePermission `gorm:"-:migration;<-:false; foreignKey:ModuleId"`
	Description         string
	OrderIndex          int
}

type TblModulePermission

type TblModulePermission struct {
	Id                   int `gorm:"primaryKey;auto_increment"`
	RouteName            string
	DisplayName          string
	SlugName             string
	Description          string
	ModuleId             int
	CreatedBy            int
	CreatedOn            time.Time
	CreatedDate          string    `gorm:"-"`
	ModifiedBy           int       `gorm:"DEFAULT:NULL"`
	ModifiedOn           time.Time `gorm:"DEFAULT:NULL"`
	ModuleName           string    `gorm:"-:migration;<-:false"`
	FullAccessPermission int
	ParentId             int
	AssignPermission     int
	BreadcrumbName       string
	TblRolePermission    []TblRolePermission `gorm:"-:migration;<-:false; foreignKey:PermissionId"`
	OrderIndex           int
}

type TblRole

type TblRole struct {
	Id          int `gorm:"primaryKey;auto_increment"`
	Name        string
	Description string
	Slug        string
	IsActive    int
	IsDeleted   int
	CreatedOn   time.Time
	CreatedBy   int
	ModifiedOn  time.Time `gorm:"DEFAULT:NULL"`
	ModifiedBy  int       `gorm:"DEFAULT:NULL"`
	CreatedDate string    `gorm:"-:migration;<-:false"`
	User        []TblUser `gorm:"-"`
}

type TblRolePermission

type TblRolePermission struct {
	Id           int `gorm:"primaryKey;auto_increment"`
	RoleId       int
	PermissionId int
	CreatedBy    int
	CreatedOn    time.Time
	CreatedDate  string `gorm:"-:migration;<-:false"`
}

type TblRoleUser

type TblRoleUser struct {
	Id           int `gorm:"primaryKey;auto_increment"`
	RoleId       int
	UserId       int
	CreatedBy    int
	CreatedOn    time.Time
	ModifiedBy   int       `gorm:"DEFAULT:NULL"`
	ModifiedOn   time.Time `gorm:"DEFAULT:NULL"`
	ModuleName   string    `gorm:"-"`
	RouteName    string    `gorm:"-:migration;<-:false"`
	DisplayName  string    `gorm:"-:migration;<-"`
	Description  string    `gorm:"-"`
	ModuleId     int       `gorm:"-:migration;<-"`
	PermissionId int       `gorm:"-"`
}

type TblUser

type TblUser struct {
	Id                   int `gorm:"primaryKey;auto_increment"`
	Uuid                 string
	FirstName            string
	LastName             string
	RoleId               int
	Email                string
	Username             string
	Password             string
	MobileNo             string
	IsActive             int
	ProfileImage         string
	ProfileImagePath     string
	DataAccess           int
	CreatedOn            time.Time
	CreatedBy            int
	ModifiedOn           time.Time `gorm:"DEFAULT:NULL"`
	ModifiedBy           int       `gorm:"DEFAULT:NULL"`
	LastLogin            time.Time `gorm:"DEFAULT:NULL"`
	IsDeleted            int
	DeletedOn            time.Time `gorm:"DEFAULT:NULL"`
	DeletedBy            int       `gorm:"DEFAULT:NULL"`
	ModuleName           string    `gorm:"-"`
	RouteName            string    `gorm:"-:migration;<-:false"`
	DisplayName          string    `gorm:"-:migration;<-:false"`
	Description          string    `gorm:"-"`
	ModuleId             int       `gorm:"-:migration;<-:false"`
	PermissionId         int       `gorm:"-"`
	FullAccessPermission int       `gorm:"-:migration;<-:false"`
	Roles                []TblRole `gorm:"-"`
}

Jump to

Keyboard shortcuts

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