users

package
v0.0.0-...-4382370 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateAcessToken

func ValidateAcessToken(accessToken string) (*jwt.Token, error)

ValidateAcessToken -> validate access token see https://pkg.go.dev/github.com/golang-jwt/jwt#example-Parse-Hmac

Types

type User

type User struct {
	mgm.DefaultModel `bson:",inline"`
	Email            string   `json:"email" bson:"email" validate:"required,email,lte=250,lowercase"`
	Password         string   `json:"password,omitempty" bson:"password" validate:"required,gte=6,lte=20"`
	Roles            []string `json:"roles" bson:"roles"`
	Active           bool     `json:"active" bson:"active"`
}

User -> represent a user

func FindByEmail

func FindByEmail(email string) (*User, error)

FindByEmail -> find by email

func FindByID

func FindByID(id string) (*User, error)

FindByID -> find by id

func (*User) CreateAccessToken

func (u *User) CreateAccessToken() (*UserAccessToken, error)

CreateAccessToken -> return jwk user token

func (*User) CryptPassword

func (u *User) CryptPassword() error

CryptPassword -> crypt password

func (*User) Remove

func (u *User) Remove() error

Remove -> delete model

func (*User) Save

func (u *User) Save() (primitive.ObjectID, error)

Save -> create or update model

func (*User) VerifyPassword

func (u *User) VerifyPassword(password string) bool

VerifyPassword -> check password

type UserAccessToken

type UserAccessToken struct {
	TokenType   string `json:"token_type"`
	AccessToken string `json:"access_token"`
	ExpiresAt   int64  `json:"expires_at"`
}

UserAccessToken -> represent a jwk user's personal token

type UserClaims

type UserClaims struct {
	*jwt.StandardClaims
	ID     string   `json:"id"`
	Email  string   `json:"email"`
	Roles  []string `json:"roles"`
	Active bool     `json:"active" bson:"active"`
}

UserClaims -> custom claims for golang-jwt

func (*UserClaims) GrantRole

func (u *UserClaims) GrantRole(role string)

GrantRole -> give a role to user

func (UserClaims) InRole

func (u UserClaims) InRole(role string) bool

InRole -> check user has a role

Jump to

Keyboard shortcuts

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