vmod

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AccessConfig = middleware.JWTConfig{
	Claims:     &AccessToken{},
	ContextKey: "token",
	SigningKey: []byte(os.Getenv("JWT_SECRET")),
}

AccessConfig can with echo for middleware.JWTWithConfig(vmod.AccessConfig) to handling access controll The token is reachable with c.Get("token")

View Source
var RefreshConfig = middleware.JWTConfig{
	Claims:     &RefreshToken{},
	ContextKey: "token",
	SigningKey: []byte(os.Getenv("JWT_SECRET")),
}

RefreshConfig can with echo for middleware.JWTWithConfig(vmod.AccessConfig) to handling access controll The token is reachable with c.Get("token")

Functions

func RespCreateBase added in v0.1.1

func RespCreateBase(model string) (int, interface{})

RespCreateBase creates the created response without payload

func RespCreated added in v0.1.1

func RespCreated(i interface{}, model string) (int, interface{})

RespCreated creates the created response

func RespDeleted added in v0.1.12

func RespDeleted(model string) (int, interface{})

RespDeleted creates the updated response

func RespExecuted added in v0.1.1

func RespExecuted(model string) (int, interface{})

RespExecuted creates the execution response for handling for example sending emails.

func RespSelected added in v0.1.1

func RespSelected(i interface{}, model string) (int, interface{})

RespSelected creates the selected response

func RespUpdated added in v0.1.1

func RespUpdated(model string) (int, interface{})

RespUpdated creates the updated response

Types

type APIResponse added in v0.1.1

type APIResponse struct {
	Message string      `json:"message"`
	Model   string      `json:"model"`
	Payload interface{} `json:"payload,omitempty"`
}

APIResponse type that will response in success cases

type Access

type Access struct {
	Role    string `json:"role" bson:"role"`
	Created int64  `json:"created" bson:"created"`
}

Access represents access to an model.

type AccessList added in v0.1.0

type AccessList []Access

AccessList list of access model

func (AccessList) Map added in v0.1.0

func (a AccessList) Map() map[string]string

Map converts an access list into map

type AccessToken added in v0.1.0

type AccessToken struct {
	User User `json:"user"`
	jwt.StandardClaims
}

AccessToken represents the access token contained in JWTToken

type Avatar

type Avatar struct {
	URL     string `bson:"url" json:"url"`
	Type    string `bson:"type" json:"type"`
	Updated int64  `bson:"updated" json:"updated" validate:"required"`
	Created int64  `bson:"created" json:"created" validate:"required"`
}

Avatar represents the avatar for an User

type Campaign

type Campaign struct {
	ID          string   `bson:"_id" json:"id" validate:"required"`
	CiviID      int      `bson:"civi_id" json:"civi_id" validate:"required"`
	Name        string   `bson:"name" json:"name" validate:"required"`
	Description string   `bson:"name" json:"description" validate:"required"`
	Tags        []string `bson:"tags" json:"tags" validate:"required"`
	Type        string   `bson:"type" json:"type" validate:"required"`
	Modified    Modified `bson:"modified" json:"modified" validate:"required"`
}

Campaign represents a default campaign model

type CodeRequest added in v0.1.1

type CodeRequest struct {
	Code string `json:"code"`
	Case string `json:"case,omitempty"`
}

CodeRequest used for handling LinkToken code.

type ContentText added in v0.1.13

type ContentText map[string]string

type DisplayContent added in v0.1.13

type DisplayContent struct {
	Language    []string               `bson:"language" json:"language"`
	Keys        []string               `bson:"keys" json:"keys"`
	Translation map[string]ContentText `bson:"translation" json:"translation"`
	Default     string                 `bson:"default" json:"default"`
}

func (*DisplayContent) Validate added in v0.1.13

func (dc *DisplayContent) Validate() *DisplayContent

type JWTToken added in v0.1.0

type JWTToken struct {
	AccessToken  string `json:"access_token" bson:"access_token"`
	RefreshToken string `json:"refresh_token" bson:"refresh_token"`
	TokenType    string `json:"token_type" bson:"token_type"`
	ExpiresAt    int64  `json:"expires_at" bson:"expires_at"`
	Scope        string `json:"scope" bson:"scope"`
}

JWTToken represents the all access and refresh tokens

func NewJWTToken added in v0.1.0

func NewJWTToken(u *User, scope string) (*JWTToken, error)

NewJWTToken returns a new JWTToken model contains an access and an refresh token

type LinkToken added in v0.1.0

type LinkToken struct {
	ID      string `bson:"_id" json:"token_id"`
	Code    string `bson:"code" json:"code"`
	Tcase   string `json:"t_case"`
	Scope   string `json:"scope"`
	Expired int64  `json:"expired"`
	Created int64  `json:"created"`
	ModelID string `json:"model_id" bson:"model_id"`
}

LinkToken is used for handling link with token

func NewLinkToken added in v0.1.0

func NewLinkToken(ctx context.Context, tCase string, expired time.Duration, modelID string, scope string) (*LinkToken, error)

NewLinkToken initial a Token with a 32bit random string Base64 encoded for Web handling. Set expired time max 1 month.

func (*LinkToken) NewCode added in v0.1.1

func (l *LinkToken) NewCode(ctx context.Context, expired time.Duration) (*LinkToken, error)

NewCode generate a new code for LinkTokens

type MID added in v0.1.17

type MID struct {
	ID   string `bson:"id" json:"id"`
	Type string `bson:"type" json:"type"`
}

func NewMID added in v0.1.17

func NewMID(id string, t string) *MID

type MailBase added in v0.1.1

type MailBase struct {
	To       string `json:"to" bson:"to"`
	JobCase  string `json:"job_case"`
	JobScope string `json:"job_scope"`
	Country  string `json:"country"`
}

MailBase base model for request mail-backend via nats

type MailCode added in v0.1.1

type MailCode struct {
	MailBase
	UserName string `json:"user_name"`
	Code     string `json:"code"`
}

MailCode used for request mail-backend via nats

func NewMailCode added in v0.1.1

func NewMailCode(to string, jobCase string, jobScope string, userName string, code string) MailCode

NewMailCode initial new MailCode from given variables.

type MailContactAt added in v0.1.18

type MailContactAt struct {
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Comment   string `json:"comment"`
	Email     string `json:"email"`
	KnownFrom string `json:"known_from"`
}

type Modified

type Modified struct {
	Updated int64 `json:"updated" bson:"updated,omitempty"`
	Created int64 `json:"created" bson:"created,omitempty"`
}

Modified represents update and create timestamp for all models.

func NewModified added in v0.0.8

func NewModified() *Modified

NewModified initial Modified model, cTime is the current time Unix format.

func (*Modified) Update added in v0.1.0

func (modified *Modified) Update() *Modified

Update set new Updated

type MultiLang added in v0.1.13

type MultiLang struct {
	Language    []string          `bson:"language" json:"language"`
	Translation map[string]string `bson:"translation" json:"translation"`
}

func (*MultiLang) Insert added in v0.1.13

func (m *MultiLang) Insert() *MultiLang

type PValidate added in v0.1.0

type PValidate map[string][]string

PValidate used for controller permission handling

func (*PValidate) Restricted added in v0.1.0

func (pVal *PValidate) Restricted(next echo.HandlerFunc) echo.HandlerFunc

Restricted middleware function for handling Access

type Permission

type Permission map[string]AccessList

Permission represents role to an access

func NewPermission

func NewPermission(app string, role string) *Permission

NewPermission map role to []Access(modelID, created) and initial Permission.

func (*Permission) Add

func (p *Permission) Add(app string, role string) *Permission

Add Access(modelID created) to role.

func (*Permission) Delete

func (p *Permission) Delete(role string, modelID string) *Permission

Delete Access from role. If []Access is nil the role will remove form Permission.

func (*Permission) Validate added in v0.1.0

func (p *Permission) Validate(pValidate *PValidate) bool

Validate validates the permission for middleware functions

type Profile

type Profile struct {
	ID          string   `bson:"_id" json:"profile_id" validate:"required"`
	UserID      string   `bson:"user_id" json:"user_id" validate:"required"`
	FirstName   string   `bson:"first_name" json:"first_name" validate:"required"`
	LastName    string   `bson:"last_name" json:"last_name" validate:"required"`
	FullName    string   `bson:"full_name" json:"full_name"`
	DisplayName string   `bson:"display_name" json:"display_name"`
	Gender      string   `bson:"gender" json:"gender"`
	Country     string   `bson:"country" json:"country"`
	Avatar      Avatar   `bson:"avatar" json:"avatar"`
	Modified    Modified `json:"modified" bson:"modified" validation:"required"`
}

Profile represents user Profile

type RefreshToken added in v0.1.0

type RefreshToken struct {
	UserID string `json:"user_id"`
	jwt.StandardClaims
}

RefreshToken represents the refresh token contained in JWTToken

type SimpleID added in v0.1.10

type SimpleID struct {
	ID    string `bson:"id" json:"id"`
	Name  string `bson:"name" json:"name"`
	Model string `bson:"model" json:"model"`
}

type User

type User struct {
	ID            string     `json:"user_id" bson:"_id" validation:"required,uuid"`
	Email         string     `json:"email" bson:"email" validation:"required,email"`
	PrivacyPolicy string     `json:"policies" bson:"-"`
	Permission    Permission `json:"permission" bson:"permission" validation:"required"`
	Modified      Modified   `json:"modified" bson:"modified" validation:"required"`
	Country       string     `json:"country" bson:"country" validation:"required"`
	Profile       Profile    `json:"profile" bson:"-"`
}

User represents the root struct for user handling in viva-con-agua api.

func (*User) CrmDataBody added in v0.1.4

func (u *User) CrmDataBody(civiID int, activity string) *civi.CrmDataBody

CrmDataBody creates a crm data body from vmod.User

Jump to

Keyboard shortcuts

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