users

package
v0.0.0-...-f1c2737 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPassword

func CheckPassword(hash, password []byte) bool

func HashPassword

func HashPassword(pwd []byte, cost int) (hash []byte, err error)

func ParseJwt

func ParseJwt(tokenString string, publicKey *rsa.PublicKey) (t *jwt.Token, err error)

Types

type AuthConfig

type AuthConfig struct {
	PublicKey *rsa.PublicKey
}

AuthConfig is used as a reciever for auth-related filters in order to pass in state such as Public Keys that are typically pulled from env vars. In test they will likely be hardcoded.

func (AuthConfig) RequiresSuperAdminFilter

func (authConfig AuthConfig) RequiresSuperAdminFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

RequiresSuperAdminFilter ensures that the logged-in user has SuperAdmin permissions. You should add ValidJwtFilter before this one in the chain.

func (AuthConfig) ValidJwtFilter

func (authConfig AuthConfig) ValidJwtFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

ValidJwtFilter ensures that an API request is made with a valid, signed bearer token

type Claims

type Claims struct {
	jwt.StandardClaims
	Roles map[uint64][]RoleType `json:"orgs"`
}

func CreateJWT

func CreateJWT(user *User, expirationDuration time.Duration) *Claims

func DecodeJWT

func DecodeJWT(jwtRaw string, publicKey *rsa.PublicKey) *Claims

func GetRequestJWTClaims

func GetRequestJWTClaims(req *restful.Request) *Claims

type Role

type Role struct {
	Id       uint64   `json:"-" db:"id"`
	OrgId    uint64   `json:"org_id" db:"org_id"`
	UserId   uint64   `json:"-" db:"user_id"`
	UserGuid string   `json:"user_guid"`
	Role     RoleType `json:"name" db:"name"`
}

type RoleType

type RoleType int
const (
	SiteAdmin   RoleType = 0 // Administrative permissions for Volunteer-Savvy as a whole
	OrgAdmin    RoleType = 1 // Administrative permissions for a single Organization
	Volunteer   RoleType = 2 // User is able to sign up, log work.
	SiteManager RoleType = 3 // User is able to sign up as a Site Coordinator for sites, then manage those sites' settings.
	BackOffice  RoleType = 4 // User is able to log work, read and update suggestions, generate reports. Not able to modify Users or Site settings.
	Mobile      RoleType = 5 // User is interested in working at the Mobile sites. Enables the user to opt-in to notifications about mobile sites specifically.
)

type User

type User struct {
	Id           uint64 `json:"-" db:"id"`
	Guid         string `json:"user_guid" db:"user_guid"`
	Email        string `json:"email" db:"email"`
	PasswordHash string `json:"-" db:"password_digest"`

	Roles map[uint64][]Role `json:"roles"` // the map key is the organization ID
}

func FindUser

func FindUser(ctx context.Context, email string, db *sqlx.DB) (*User, error)

FindUser queries the database for the user and all other data needed to display their profile.

func GetUserForLogin

func GetUserForLogin(ctx context.Context, email string, db *sqlx.DB) (*User, error)

func ListUsersInSameOrgs

func ListUsersInSameOrgs(ctx context.Context, jwtClaims *Claims, db *sqlx.DB) ([]User, error)

func (*User) GetRoles

func (u *User) GetRoles(ctx context.Context, db *sqlx.DB) (map[uint64][]Role, error)

GetUserRoles fetches all permissions granted to the user, sorted by the Organization ID they are granted on. If an Organization ID is not found among the keys, the user does not have any access to that org.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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