user

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSession

func AddSession(username string) (string, error)

AddSession saves a session for `username` and returns a token to use.

func CanProceed

func CanProceed(rq *http.Request, route string) bool

CanProceed returns `true` if the user in `rq` has enough rights to access `route`.

func Count

func Count() (i uint64)

Count returns total users count

func CredentialsOK

func CredentialsOK(username, password string) bool

CredentialsOK checks whether a correct user-password pair is provided

func DeleteUser added in v1.3.0

func DeleteUser(name string) error

DeleteUser removes a user by one's name and saves user database.

func HasUsername

func HasUsername(username string) bool

HasUsername checks whether the desired user exists

func InitUserDatabase added in v1.1.0

func InitUserDatabase()

InitUserDatabase loads users, if necessary. Call it during initialization.

func IsValidUsername added in v1.6.0

func IsValidUsername(username string) bool

IsValidUsername checks if the given username is valid.

func ListUsersWithGroup

func ListUsersWithGroup(group string) []string

ListUsersWithGroup returns a slice with users of desired group.

func LoginDataHTTP

func LoginDataHTTP(w http.ResponseWriter, username, password string) error

LoginDataHTTP logs such user in and returns string representation of an error if there is any.

The HTTP parameters are used for setting header status (bad request, if it is bad) and saving a cookie.

func LogoutFromRequest

func LogoutFromRequest(w http.ResponseWriter, rq *http.Request)

LogoutFromRequest logs the user in `rq` out and rewrites the cookie in `w`.

func ReadUsersFromFilesystem

func ReadUsersFromFilesystem()

ReadUsersFromFilesystem reads all user information from filesystem and stores it internally.

func Register added in v1.1.0

func Register(username, password, group, source string, force bool) error

Register registers the given user. If it fails, a non-nil error is returned.

func SaveUserDatabase added in v1.2.0

func SaveUserDatabase() error

SaveUserDatabase stores current user credentials into JSON file by configured path.

func TelegramAuthParamsAreValid added in v1.3.0

func TelegramAuthParamsAreValid(params map[string][]string) bool

TelegramAuthParamsAreValid is true if the given params are ok.

func ValidGroup added in v1.2.0

func ValidGroup(group string) bool

ValidGroup checks whether provided user group name exists.

func ValidSource added in v1.3.0

func ValidSource(source string) bool

ValidSource checks whether provided user source name exists.

func YieldUsers

func YieldUsers() chan *User

YieldUsers creates a channel which iterates existing users.

Types

type User

type User struct {
	// Name is a username. It must follow hypha naming rules.
	Name         string    `json:"name"`
	Group        string    `json:"group"`
	Password     string    `json:"hashed_password"`
	RegisteredAt time.Time `json:"registered_on"`
	// Source is where the user from. Valid values: local, telegram.
	Source string `json:"source"`
	sync.RWMutex
}

User contains information about a given user required for identification.

func ByName added in v1.6.0

func ByName(username string) *User

ByName finds a user by one's username

func ByToken added in v1.6.0

func ByToken(token string) *User

ByToken finds a user by provided session token

func EmptyUser

func EmptyUser() *User

EmptyUser constructs an anonymous user.

func FromRequest

func FromRequest(rq *http.Request) *User

FromRequest returns user from `rq`. If there is no user, an anon user is returned instead.

func WikimindUser added in v1.8.0

func WikimindUser() *User

WikimindUser constructs the wikimind user, which is to be used for automated wiki edits and has admin privileges.

func (*User) CanProceed

func (user *User) CanProceed(route string) bool

CanProceed checks whether user has rights to visit the provided path (and perform an action).

func (*User) ShowLockMaybe added in v1.3.0

func (user *User) ShowLockMaybe(w http.ResponseWriter, rq *http.Request) bool

ShowLockMaybe redirects to the lock page if the user is anon and the wiki has been configured to use the lock. It returns true if the user was redirected.

Jump to

Keyboard shortcuts

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