Documentation
¶
Overview ¶
Uploading avatar from file.
Sets UseGravatar to false.
Index ¶
- Constants
- Variables
- func AvatarPOST(c *gin.Context)
- func ErrUnauthorized(c *gin.Context, msg string)
- func GetClaimsFromJWT(c *gin.Context) (jwt.MapClaims, error)
- func ParseToken(c *gin.Context) (*jwt.Token, error)
- func Routes(r *gin.Engine)
- func SetLogger(logger *zap.Logger)
- func UploadAvatarEndpoint(c *gin.Context)
- func UserPatchEndpoint(c *gin.Context)
- func UserWebsocketEndpoint(c *gin.Context)
- type GetRolesOptions
- type Image
- type PlainPassword
- type PostgresStorage
- func (s *PostgresStorage) AddImage(img *Image) (*Image, error)
- func (s *PostgresStorage) Authenticate(email string, password string) (*User, error)
- func (s *PostgresStorage) CreateNewUser(email string) (*User, PlainPassword, error)
- func (s *PostgresStorage) GetRoles(u *User, options *GetRolesOptions) ([]*Role, error)
- func (s *PostgresStorage) GetUserByEmail(email string) (*User, error)
- func (s *PostgresStorage) GetUserById(id int64) (*User, error)
- func (s *PostgresStorage) Save(user *User) error
- func (s *PostgresStorage) SaveFields(user *User, fields ...string) error
- type Role
- type User
- func (u *User) CanRemoveTree(t *tree.Tree) bool
- func (u *User) GetGlobalRoles() []*Role
- func (u *User) GetPermissionsForTree(t *tree.Tree) []string
- func (u *User) GetRoles() []*Role
- func (u *User) GetRolesInTree(t *tree.Tree) []*Role
- func (u *User) HasPermission(permission string, args ...interface{}) (bool, error)
- func (user *User) ID62() string
- type UserStorage
Constants ¶
const ROLES_ALL = 1 // all Roles in all Trees
const ROLES_GLOBAL = 0 // only global Roles (default)
const ROLES_TREE = 1 // all user Roles in a specific Tree
Variables ¶
var ( IdentityKey = "user" SigningAlgorithm = "HS256" Timeout = time.Hour // This field allows clients to refresh their token until MaxRefresh has passed. // Note that clients can refresh their token in the last moment of MaxRefresh. // This means that the maximum validity timespan for a token is TokenTime + MaxRefresh. // Optional, defaults to 0 meaning not refreshable. MaxRefresh = time.Hour ErrMissingLoginValues = errors.New("no login values") ErrInvalidHash = errors.New("the encoded hash is not in the correct format") ErrIncompatibleVersion = errors.New("incompatible version of argon2") // ErrExpiredToken indicates JWT token has expired. Can't refresh. ErrExpiredToken = errors.New("token is expired") ErrEmptyCookieToken = errors.New("empty token") ErrInvalidSigningAlgorithm = errors.New("invalid alg") ErrFailedAuthentication = errors.New("failed auth") )
Functions ¶
func ErrUnauthorized ¶
func GetClaimsFromJWT ¶
func ParseToken ¶
ParseToken parse jwt token from gin context
func UserPatchEndpoint ¶
UserPatchEndpoint modifies fields of a User model.
func UserWebsocketEndpoint ¶
Types ¶
type GetRolesOptions ¶
type Image ¶
type Image struct { // Id int64 `json:"id,string"` // Id uuid.UUID `sql:",type:uuid" json:"-"` Id []byte // SHA-1 of the image (20 bytes) W int `sql:",notnull"` H int `sql:",notnull"` //ObjectHash []byte // SHA-1 takes 20 bytes (in binary form) OriginalId []byte // SHA-1 of the original image }
Image model was initially created for avatars. So given an Image we need to quickly get different sizes of that image.
If an original image was cropped current record will have W, H and ObjectHash of a cropped image and OriginalId pointing to an original one that was cropped.
type PlainPassword ¶
type PlainPassword = string
type PostgresStorage ¶
func (*PostgresStorage) Authenticate ¶
func (s *PostgresStorage) Authenticate(email string, password string) (*User, error)
This is the main function which checks user/password. Returns 2 values: (User object, error). One of them is nil.
func (*PostgresStorage) CreateNewUser ¶
func (s *PostgresStorage) CreateNewUser(email string) (*User, PlainPassword, error)
func (*PostgresStorage) GetRoles ¶
func (s *PostgresStorage) GetRoles(u *User, options *GetRolesOptions) ([]*Role, error)
select ur.user_id from roles role join user_roles ur on role.id=ur.role_id where ur.tree_id is NULL; func (s *PostgresStorage) GetUserGlobalRoles(u *User) ([]*Role, error)
func (*PostgresStorage) GetUserByEmail ¶
func (s *PostgresStorage) GetUserByEmail(email string) (*User, error)
func (*PostgresStorage) GetUserById ¶
func (s *PostgresStorage) GetUserById(id int64) (*User, error)
func (*PostgresStorage) Save ¶
func (s *PostgresStorage) Save(user *User) error
func (*PostgresStorage) SaveFields ¶
func (s *PostgresStorage) SaveFields(user *User, fields ...string) error
fields must be specified as they are in a database (case-sensitive)
type Role ¶
type Role struct { Id int64 `json:"Id,string"` // Tree int64 `json:"Tree,string"` Name string Superuser bool // Tree *tree.Tree `pg:"fk:tree_id"` TreeId int64 Tree tree.Tree Users []*User `pg:"many2many:user_roles" json:"-"` // many to many relation }
Trees can have a set of roles
func (*Role) IsSuperuser ¶
type User ¶
type User struct { Id int64 `json:"id,string"` FirstName string `json:"firstname"` LastName string `json:"lastname"` Email string `json:"email"` Password string `json:"-"` UseGravatar bool `sql:",notnull"` // AvatarId uuid.UUID `sql:",type:uuid" json:"-"` AvatarId []byte // `sql:"-"` // json:"-" Avatar *Image //`sql:"-"` Data map[string]string Lng string `json:"lng"` Roles []*Role `pg:"many2many:user_roles,joinFK:role_id" json:"-"` }
func FromGinContext ¶
FromGinContext creates a pseudo-user if a user is logged in. This user has only one parameter set - it's ID.
func GetUserByID62 ¶
func (*User) GetGlobalRoles ¶
func (*User) HasPermission ¶
type UserStorage ¶
type UserStorage interface { GetUserById(id int64) (*User, error) GetUserByEmail(email string) (*User, error) Authenticate(email string, password string) (*User, error) CreateNewUser(email string) (*User, PlainPassword, error) GetRoles(u *User, options *GetRolesOptions) ([]*Role, error) Save(u *User) error SaveFields(u *User, fields ...string) error AddImage(img *Image) (*Image, error) }
var (
Storage UserStorage
)