user

package
v1.15.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownUsername = errors.New("unknown username")
	ErrWrongPassword   = errors.New("wrong password")
)

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

func DeleteUser(name string) error

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

func HasAnyAdmins

func HasAnyAdmins() bool

func HasUsername

func HasUsername(username string) bool

HasUsername checks whether the desired user exists

func InitUserDatabase

func InitUserDatabase()

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

func IsValidUsername

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

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

func SaveUserDatabase() error

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

func TelegramAuthParamsAreValid

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

TelegramAuthParamsAreValid is true if the given params are ok.

func UsersInGroups

func UsersInGroups() (admins []string, moderators []string, editors []string, readers []string)

func ValidGroup

func ValidGroup(group string) bool

ValidGroup checks whether provided user group name exists.

func ValidSource

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

func ByName(username string) *User

ByName finds a user by one's username

func ByToken

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

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) ChangePassword

func (user *User) ChangePassword(password string) error

Sets a new password for the user.

func (*User) ShowLockMaybe

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