Documentation ¶
Index ¶
- Constants
- func CheckUserPassword(user *User, password string) error
- func ConfirmEmail(c *EmailConfirm) (err error)
- func DisableTOTP(user *User) (err error)
- func EnableTOTP(passcode *TOTPPasscode) (err error)
- func GetTOTPQrCodeForUser(user *User) (qrcode image.Image, err error)
- func GetTables() []interface{}
- func InitDB() (err error)
- func InitTests()
- func IsErrCouldNotGetUserID(err error) bool
- func IsErrEmailNotConfirmed(err error) bool
- func IsErrEmptyNewPassword(err error) bool
- func IsErrEmptyOldPassword(err error) bool
- func IsErrInvalidEmailConfirmToken(err error) bool
- func IsErrInvalidPasswordResetToken(err error) bool
- func IsErrInvalidTOTPPasscode(err error) bool
- func IsErrNoUsernamePassword(err error) bool
- func IsErrTOTPAlreadyEnabled(err error) bool
- func IsErrTOTPNotEnabled(err error) bool
- func IsErrUserDoesNotExist(err error) bool
- func IsErrUserEmailExists(err error) bool
- func IsErrUsernameExists(err error) bool
- func IsErrWrongUsernameOrPassword(err error) bool
- func RequestUserPasswordResetToken(tr *PasswordTokenRequest) (err error)
- func ResetPassword(reset *PasswordReset) (err error)
- func TOTPEnabledForUser(user *User) (bool, error)
- func UpdateEmail(update *EmailUpdate) (err error)
- func UpdateUserPassword(user *User, newPassword string) (err error)
- type APIUserPassword
- type EmailConfirm
- type EmailUpdate
- type ErrCouldNotGetUserID
- type ErrEmailNotConfirmed
- type ErrEmptyNewPassword
- type ErrEmptyOldPassword
- type ErrInvalidEmailConfirmToken
- type ErrInvalidPasswordResetToken
- type ErrInvalidTOTPPasscode
- type ErrNoPasswordResetToken
- type ErrNoUsernamePassword
- type ErrTOTPAlreadyEnabled
- type ErrTOTPNotEnabled
- type ErrUserDoesNotExist
- type ErrUserEmailExists
- type ErrUsernameExists
- type ErrWrongUsernameOrPassword
- type Login
- type PasswordReset
- type PasswordTokenRequest
- type TOTP
- type TOTPPasscode
- type User
- func CheckUserCredentials(u *Login) (*User, error)
- func CreateUser(user *User) (newUser *User, err error)
- func GetCurrentUser(c echo.Context) (user *User, err error)
- func GetFromAuth(a web.Auth) (*User, error)
- func GetUser(user *User) (userOut *User, err error)
- func GetUserByID(id int64) (user *User, err error)
- func GetUserByUsername(username string) (user *User, err error)
- func GetUserFromClaims(claims jwt.MapClaims) (user *User, err error)
- func GetUserWithEmail(user *User) (userOut *User, err error)
- func ListUsers(searchterm string) (users []User, err error)
- func UpdateUser(user *User) (updatedUser *User, err error)
Constants ¶
const ErrCodeCouldNotGetUserID = 1006
ErrCodeCouldNotGetUserID holds the unique world-error code of this error
const ErrCodeEmailNotConfirmed = 1012
ErrCodeEmailNotConfirmed holds the unique world-error code of this error
const ErrCodeEmptyNewPassword = 1013
ErrCodeEmptyNewPassword holds the unique world-error code of this error
const ErrCodeEmptyOldPassword = 1014
ErrCodeEmptyOldPassword holds the unique world-error code of this error
const ErrCodeInvalidEmailConfirmToken = 1010
ErrCodeInvalidEmailConfirmToken holds the unique world-error code of this error
const ErrCodeInvalidPasswordResetToken = 1009
ErrCodeInvalidPasswordResetToken holds the unique world-error code of this error
const ErrCodeInvalidTOTPPasscode = 1017
ErrCodeInvalidTOTPPasscode holds the unique world-error code of this error
const ErrCodeNoPasswordResetToken = 1008
ErrCodeNoPasswordResetToken holds the unique world-error code of this error
const ErrCodeNoUsernamePassword = 1004
ErrCodeNoUsernamePassword holds the unique world-error code of this error
const ErrCodeTOTPAlreadyEnabled = 1015
ErrCodeTOTPAlreadyEnabled holds the unique world-error code of this error
const ErrCodeTOTPNotEnabled = 1016
ErrCodeTOTPNotEnabled holds the unique world-error code of this error
const ErrCodeUserDoesNotExist = 1005
ErrCodeUserDoesNotExist holds the unique world-error code of this error
const ErrCodeWrongUsernameOrPassword = 1011
ErrCodeWrongUsernameOrPassword holds the unique world-error code of this error
const ErrorCodeUserEmailExists = 1002
ErrorCodeUserEmailExists holds the unique world-error code of this error
const ErrorCodeUsernameExists = 1001
ErrorCodeUsernameExists holds the unique world-error code of this error
Variables ¶
This section is empty.
Functions ¶
func CheckUserPassword ¶
CheckUserPassword checks and verifies a user's password. The user object needs to contain the hashed password from the database.
func ConfirmEmail ¶
func ConfirmEmail(c *EmailConfirm) (err error)
ConfirmEmail handles the confirmation of an email address
func DisableTOTP ¶
DisableTOTP removes all totp settings for a user.
func EnableTOTP ¶
func EnableTOTP(passcode *TOTPPasscode) (err error)
EnableTOTP enables totp for a user. The provided passcode is used to verify the user has a working totp setup.
func GetTOTPQrCodeForUser ¶
GetTOTPQrCodeForUser returns a qrcode for a user's totp setting
func GetTables ¶
func GetTables() []interface{}
GetTables returns all structs which are also a table.
func InitDB ¶
func InitDB() (err error)
InitDB sets up the database connection to use in this module
func IsErrCouldNotGetUserID ¶
IsErrCouldNotGetUserID checks if an error is a ErrCouldNotGetUserID.
func IsErrEmailNotConfirmed ¶
IsErrEmailNotConfirmed checks if an error is a IsErrEmailNotConfirmed.
func IsErrEmptyNewPassword ¶
IsErrEmptyNewPassword checks if an error is a ErrEmptyNewPassword.
func IsErrEmptyOldPassword ¶
IsErrEmptyOldPassword checks if an error is a ErrEmptyOldPassword.
func IsErrInvalidEmailConfirmToken ¶
IsErrInvalidEmailConfirmToken checks if an error is a ErrInvalidEmailConfirmToken.
func IsErrInvalidPasswordResetToken ¶
IsErrInvalidPasswordResetToken checks if an error is a ErrInvalidPasswordResetToken.
func IsErrInvalidTOTPPasscode ¶
IsErrInvalidTOTPPasscode checks if an error is a ErrInvalidTOTPPasscode.
func IsErrNoUsernamePassword ¶
IsErrNoUsernamePassword checks if an error is a ErrNoUsernamePassword.
func IsErrTOTPAlreadyEnabled ¶
IsErrTOTPAlreadyEnabled checks if an error is a ErrTOTPAlreadyEnabled.
func IsErrTOTPNotEnabled ¶
IsErrTOTPNotEnabled checks if an error is a ErrTOTPNotEnabled.
func IsErrUserDoesNotExist ¶
IsErrUserDoesNotExist checks if an error is a ErrUserDoesNotExist.
func IsErrUserEmailExists ¶
IsErrUserEmailExists checks if an error is a ErrUserEmailExists.
func IsErrUsernameExists ¶
IsErrUsernameExists checks if an error is a ErrUsernameExists.
func IsErrWrongUsernameOrPassword ¶
IsErrWrongUsernameOrPassword checks if an error is a IsErrEmailNotConfirmed.
func RequestUserPasswordResetToken ¶
func RequestUserPasswordResetToken(tr *PasswordTokenRequest) (err error)
RequestUserPasswordResetToken inserts a random token to reset a users password into the databsse
func ResetPassword ¶
func ResetPassword(reset *PasswordReset) (err error)
ResetPassword resets a users password
func TOTPEnabledForUser ¶
TOTPEnabledForUser checks if totp is enabled for a user - not if it is activated, use GetTOTPForUser to check that.
func UpdateEmail ¶
func UpdateEmail(update *EmailUpdate) (err error)
UpdateEmail lets a user update their email address
func UpdateUserPassword ¶
UpdateUserPassword updates the password of a user
Types ¶
type APIUserPassword ¶
type APIUserPassword struct { // The unique, numeric id of this user. ID int64 `json:"id"` // The username of the username. Is always unique. Username string `json:"username" valid:"length(3|250)" minLength:"3" maxLength:"250"` // The user's password in clear text. Only used when registering the user. Password string `json:"password" valid:"length(8|250)" minLength:"8" maxLength:"250"` // The user's email address Email string `json:"email" valid:"email,length(0|250)" maxLength:"250"` }
APIUserPassword represents a user object without timestamps and a json password field.
func (*APIUserPassword) APIFormat ¶
func (apiUser *APIUserPassword) APIFormat() *User
APIFormat formats an API User into a normal user struct
type EmailConfirm ¶
type EmailConfirm struct { // The email confirm token sent via email. Token string `json:"token"` }
EmailConfirm holds the token to confirm a mail address
type EmailUpdate ¶
type EmailUpdate struct { User *User `json:"-"` // The new email address. Needs to be a valid email address. NewEmail string `json:"new_email" valid:"email,length(0|250),required"` // The password of the user for confirmation. Password string `json:"password"` }
EmailUpdate is the data structure to update a user's email address
type ErrCouldNotGetUserID ¶
type ErrCouldNotGetUserID struct{}
ErrCouldNotGetUserID represents a "ErrCouldNotGetuser_id" kind of error.
func (ErrCouldNotGetUserID) Error ¶
func (err ErrCouldNotGetUserID) Error() string
func (ErrCouldNotGetUserID) HTTPError ¶
func (err ErrCouldNotGetUserID) HTTPError() web.HTTPError
HTTPError holds the http error description
type ErrEmailNotConfirmed ¶
type ErrEmailNotConfirmed struct {
UserID int64
}
ErrEmailNotConfirmed is an error where the email was not confirmed
func (ErrEmailNotConfirmed) Error ¶
func (err ErrEmailNotConfirmed) Error() string
func (ErrEmailNotConfirmed) HTTPError ¶
func (err ErrEmailNotConfirmed) HTTPError() web.HTTPError
HTTPError holds the http error description
type ErrEmptyNewPassword ¶
type ErrEmptyNewPassword struct{}
ErrEmptyNewPassword represents a "EmptyNewPassword" kind of error.
func (ErrEmptyNewPassword) Error ¶
func (err ErrEmptyNewPassword) Error() string
func (ErrEmptyNewPassword) HTTPError ¶
func (err ErrEmptyNewPassword) HTTPError() web.HTTPError
HTTPError holds the http error description
type ErrEmptyOldPassword ¶
type ErrEmptyOldPassword struct{}
ErrEmptyOldPassword represents a "EmptyOldPassword" kind of error.
func (ErrEmptyOldPassword) Error ¶
func (err ErrEmptyOldPassword) Error() string
func (ErrEmptyOldPassword) HTTPError ¶
func (err ErrEmptyOldPassword) HTTPError() web.HTTPError
HTTPError holds the http error description
type ErrInvalidEmailConfirmToken ¶
type ErrInvalidEmailConfirmToken struct {
Token string
}
ErrInvalidEmailConfirmToken is an error where the email confirm token is invalid
func (ErrInvalidEmailConfirmToken) Error ¶
func (err ErrInvalidEmailConfirmToken) Error() string
func (ErrInvalidEmailConfirmToken) HTTPError ¶
func (err ErrInvalidEmailConfirmToken) HTTPError() web.HTTPError
HTTPError holds the http error description
type ErrInvalidPasswordResetToken ¶
type ErrInvalidPasswordResetToken struct {
Token string
}
ErrInvalidPasswordResetToken is an error where the password reset token is invalid
func (ErrInvalidPasswordResetToken) Error ¶
func (err ErrInvalidPasswordResetToken) Error() string
func (ErrInvalidPasswordResetToken) HTTPError ¶
func (err ErrInvalidPasswordResetToken) HTTPError() web.HTTPError
HTTPError holds the http error description
type ErrInvalidTOTPPasscode ¶
type ErrInvalidTOTPPasscode struct {
Passcode string
}
ErrInvalidTOTPPasscode represents a "InvalidTOTPPasscode" kind of error.
func (ErrInvalidTOTPPasscode) Error ¶
func (err ErrInvalidTOTPPasscode) Error() string
func (ErrInvalidTOTPPasscode) HTTPError ¶
func (err ErrInvalidTOTPPasscode) HTTPError() web.HTTPError
HTTPError holds the http error description
type ErrNoPasswordResetToken ¶
type ErrNoPasswordResetToken struct {
UserID int64
}
ErrNoPasswordResetToken represents an error where no password reset token exists for that user
func (ErrNoPasswordResetToken) Error ¶
func (err ErrNoPasswordResetToken) Error() string
func (ErrNoPasswordResetToken) HTTPError ¶
func (err ErrNoPasswordResetToken) HTTPError() web.HTTPError
HTTPError holds the http error description
type ErrNoUsernamePassword ¶
type ErrNoUsernamePassword struct{}
ErrNoUsernamePassword represents a "NoUsernamePassword" kind of error.
func (ErrNoUsernamePassword) Error ¶
func (err ErrNoUsernamePassword) Error() string
func (ErrNoUsernamePassword) HTTPError ¶
func (err ErrNoUsernamePassword) HTTPError() web.HTTPError
HTTPError holds the http error description
type ErrTOTPAlreadyEnabled ¶
type ErrTOTPAlreadyEnabled struct{}
ErrTOTPAlreadyEnabled represents a "TOTPAlreadyEnabled" kind of error.
func (ErrTOTPAlreadyEnabled) Error ¶
func (err ErrTOTPAlreadyEnabled) Error() string
func (ErrTOTPAlreadyEnabled) HTTPError ¶
func (err ErrTOTPAlreadyEnabled) HTTPError() web.HTTPError
HTTPError holds the http error description
type ErrTOTPNotEnabled ¶
type ErrTOTPNotEnabled struct{}
ErrTOTPNotEnabled represents a "TOTPNotEnabled" kind of error.
func (ErrTOTPNotEnabled) Error ¶
func (err ErrTOTPNotEnabled) Error() string
func (ErrTOTPNotEnabled) HTTPError ¶
func (err ErrTOTPNotEnabled) HTTPError() web.HTTPError
HTTPError holds the http error description
type ErrUserDoesNotExist ¶
type ErrUserDoesNotExist struct {
UserID int64
}
ErrUserDoesNotExist represents a "UserDoesNotExist" kind of error.
func (ErrUserDoesNotExist) Error ¶
func (err ErrUserDoesNotExist) Error() string
func (ErrUserDoesNotExist) HTTPError ¶
func (err ErrUserDoesNotExist) HTTPError() web.HTTPError
HTTPError holds the http error description
type ErrUserEmailExists ¶
ErrUserEmailExists represents a "UserEmailExists" kind of error.
func (ErrUserEmailExists) Error ¶
func (err ErrUserEmailExists) Error() string
func (ErrUserEmailExists) HTTPError ¶
func (err ErrUserEmailExists) HTTPError() web.HTTPError
HTTPError holds the http error description
type ErrUsernameExists ¶
ErrUsernameExists represents a "UsernameAlreadyExists" kind of error.
func (ErrUsernameExists) Error ¶
func (err ErrUsernameExists) Error() string
func (ErrUsernameExists) HTTPError ¶
func (err ErrUsernameExists) HTTPError() web.HTTPError
HTTPError holds the http error description
type ErrWrongUsernameOrPassword ¶
type ErrWrongUsernameOrPassword struct { }
ErrWrongUsernameOrPassword is an error where the email was not confirmed
func (ErrWrongUsernameOrPassword) Error ¶
func (err ErrWrongUsernameOrPassword) Error() string
func (ErrWrongUsernameOrPassword) HTTPError ¶
func (err ErrWrongUsernameOrPassword) HTTPError() web.HTTPError
HTTPError holds the http error description
type Login ¶
type Login struct { // The username used to log in. Username string `json:"username"` // The password for the user. Password string `json:"password"` // The totp passcode of a user. Only needs to be provided when enabled. TOTPPasscode string `json:"totp_passcode"` }
Login Object to recive user credentials in JSON format
type PasswordReset ¶
type PasswordReset struct { // The previously issued reset token. Token string `json:"token"` // The new password for this user. NewPassword string `json:"new_password"` }
PasswordReset holds the data to reset a password
type PasswordTokenRequest ¶
type PasswordTokenRequest struct {
Email string `json:"email" valid:"email,length(0|250)" maxLength:"250"`
}
PasswordTokenRequest defines the request format for password reset resqest
type TOTP ¶
type TOTP struct { ID int64 `xorm:"int(11) autoincr not null unique pk" json:"-"` UserID int64 `xorm:"int(11) not null" json:"-"` Secret string `xorm:"text not null" json:"secret"` // The totp entry will only be enabled after the user verified they have a working totp setup. Enabled bool `xorm:"null" json:"enabled"` // The totp url used to be able to enroll the user later URL string `xorm:"text null" json:"url"` }
TOTP holds a user's totp setting in the database.
func EnrollTOTP ¶
EnrollTOTP creates a new TOTP entry for the user - it does not enable it yet.
func GetTOTPForUser ¶
GetTOTPForUser returns the current state of totp settings for the user.
func ValidateTOTPPasscode ¶
func ValidateTOTPPasscode(passcode *TOTPPasscode) (t *TOTP, err error)
ValidateTOTPPasscode validated totp codes of users.
type TOTPPasscode ¶
TOTPPasscode is used to validate a users totp passcode
type User ¶
type User struct { // The unique, numeric id of this user. ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"` // The username of the user. Is always unique. Username string `xorm:"varchar(250) not null unique" json:"username" valid:"length(1|250)" minLength:"3" maxLength:"250"` Password string `xorm:"varchar(250) not null" json:"-"` // The user's email address. Email string `xorm:"varchar(250) null" json:"email,omitempty" valid:"email,length(0|250)" maxLength:"250"` IsActive bool `xorm:"null" json:"-"` PasswordResetToken string `xorm:"varchar(450) null" json:"-"` EmailConfirmToken string `xorm:"varchar(450) null" json:"-"` // A timestamp when this task was created. You cannot change this value. Created time.Time `xorm:"created not null" json:"created"` // A timestamp when this task was last updated. You cannot change this value. Updated time.Time `xorm:"updated not null" json:"updated"` web.Auth `xorm:"-" json:"-"` }
User holds information about an user
func CheckUserCredentials ¶
CheckUserCredentials checks user credentials
func CreateUser ¶
CreateUser creates a new user and inserts it into the database
func GetCurrentUser ¶
GetCurrentUser returns the current user based on its jwt token
func GetFromAuth ¶
GetFromAuth returns a user object from a web.Auth object and returns an error if the underlying type is not a user object
func GetUserByID ¶
GetUserByID gets informations about a user by its ID
func GetUserByUsername ¶
GetUserByUsername gets a user from its user name. This is an extra function to be able to add an extra error check.
func GetUserFromClaims ¶
GetUserFromClaims Returns a new user from jwt claims
func GetUserWithEmail ¶
GetUserWithEmail returns a user object with email
func UpdateUser ¶
UpdateUser updates a user