users

package
v0.0.0-...-0953be8 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(u *User, plainPassword string) bool

CheckPasswordHash checks a given password string against the user's hashed password

func CheckUser

func CheckUser() gin.HandlerFunc

CheckUser checks whether a user is present in the current context

func Count

func Count() int

Count returns the total number of users

func CountAdmins

func CountAdmins() int

CountAdmins returns the total number of users with the admin flag set to true

func Delete

func Delete(key string) error

Delete removes a user by its Id

func DeleteSession

func DeleteSession(sess *UserSession) error

DeleteSession removes an existing session and causes the user to be logged out

func DeleteToken

func DeleteToken(token string) error

DeleteToken removes the association of the given token with its user

func ExtractUser

func ExtractUser() gin.HandlerFunc

ExtractUser extracts the user information associated with the current request and attaches the user object and its related session to the context

func FlushCaches

func FlushCaches()

FlushCaches invalidates all user-related caches

func GetToken

func GetToken(token string) (string, error)

GetToken returns the user Id related to the given token

func HashPassword

func HashPassword(u *User) error

HashPassword hashes the given user's plain text password in-place

func Init

func Init(store *bolthold.Store, eventBus *hub.Hub)

Init initializes the user store

func Insert

func Insert(user *User, upsert bool) error

Insert adds a new user or updates an existing one

func InsertSession

func InsertSession(sess *UserSession, upsert bool) error

InsertSession starts a new session

func InsertToken

func InsertToken(token, userID string) error

InsertToken associates the given user Id with the given token

func NewSessionValidator

func NewSessionValidator(cfg *config.Config, resolveUser userResolver) userSessionValidator

NewSessionValidator instantiates a new user credentials validator

func NewUserCredentialsValidator

func NewUserCredentialsValidator(cfg *config.Config, checkPw bool) userCredentialsValidator

NewUserCredentialsValidator instantiates a new user credentials validator

func NewUserValidator

func NewUserValidator(cfg *config.Config, checkPw bool) userValidator

NewUserValidator instantiates a new user validator

func RegisterAPIRoutes

func RegisterAPIRoutes(router *gin.Engine, group *gin.RouterGroup)

RegisterAPIRoutes registers all API routes with the given router instance

func RegisterRoutes

func RegisterRoutes(router *gin.Engine, group *gin.RouterGroup)

RegisterRoutes registers all public routes with the given router instance

func Reindex

func Reindex()

Reindex rebuilds all indices in the users bucket

func SendConfirmationMail

func SendConfirmationMail(u *User, activationCode string) error

SendConfirmationMail sends a user registration confirmation mail with the given activation code for the given user

func ValidateRecaptcha

func ValidateRecaptcha(token, ip string) bool

ValidateRecaptcha is used to validate a given reCaptcha token

Types

type Login

type Login struct {
	UserId   string `form:"user" binding:"required"`
	Password string `form:"password" binding:"required"`
}

Login represents the user's credentials sent during login

type User

type User struct {
	Id        string    `form:"user" binding:"required" boltholdIndex:"Id"`
	Password  string    `form:"password" binding:"required"`
	Active    bool      `form:"" boltholdIndex:"Active"`
	Admin     bool      `form:""`
	Gender    string    `form:"gender" binding:"required"`
	Major     string    `form:"major" binding:"required"`
	Degree    string    `form:"degree" binding:"required"`
	CreatedAt time.Time `form:""`
}

User represents a registered user in this application

func DeletedUser

func DeletedUser() *User

DeletedUser returns an empty, placeholder user object

func Find

func Find(query *UserQuery) ([]*User, error)

Find retrieves a list of users matching the given query

func Get

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

Get retrieves a user by its Id

func GetAll

func GetAll() ([]*User, error)

GetAll retrieves all available users

func (*User) HasValidCredentials

func (s *User) HasValidCredentials(validator userCredentialsValidator) bool

HasValidCredentials checks whether the user has valid credentials according to a given validation function

func (*User) IsValid

func (s *User) IsValid(validator userValidator) bool

IsValid checks whether the user is valid according to a given validation function

type UserQuery

type UserQuery struct {
	ActiveEq bool
	GenderEq string
	MajorEq  string
	DegreeEq string
}

UserQuery is used to specify filter queries for users

type UserSession

type UserSession struct {
	Token     string
	UserId    string
	CreatedAt time.Time
	LastSeen  time.Time
}

UserSession represents a user's login session

func GetAllSessions

func GetAllSessions() ([]*UserSession, error)

GetAllSessions returns all registered user sessions for debugging purposes

func GetSession

func GetSession(token string) (*UserSession, error)

GetSession retrieves an existing session by its used token

func (*UserSession) IsValid

func (s *UserSession) IsValid(validator userSessionValidator) bool

IsValid checks whether the session is valid according to a given validation function

Jump to

Keyboard shortcuts

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