Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyUpdates(original interface{}, updates interface{}) error
- func CheckNotFound(err error) error
- func CheckUpdated(res sql.Result, err error) error
- func Debug(in ...interface{})
- func ErrInvalid(messages ...string) error
- func GetDb(o DbOpts) (*sql.DB, error)
- func GetRows(db *sql.DB, query string, lp *ListArgs, args ...interface{}) (*sql.Rows, error)
- func LogErr(err error)
- func Milliseconds(t time.Time) int64
- func RandStringBytesMask(n int64) string
- func RandStringBytesMaskImprSrc(n int64) string
- func Seed(db *sql.DB, xtraSeedSql ...string) error
- func TestStr(input string, rgx ...*regexp.Regexp) bool
- func Tx(db *sql.DB, txFunc func(*sql.Tx) error) (err error)
- func ValidatePassword(in string) bool
- type AssignRoleParams
- type ChangePasswordParams
- type Claims
- type CreateOrgParams
- type CustomValidator
- type DbOpts
- type ExistsParams
- type ListArgs
- type ListOrgsParams
- type ListUsersParams
- type NotAuthenticatedError
- type NotFoundError
- type Org
- type OrgFilters
- type OrgListResponse
- type OrgType
- type Orgs
- type PasswordGen
- type RateLimitExceededError
- type ResetPasswordParams
- type Role
- type SignInParams
- type SignUpParams
- type SortDir
- type Suspender
- type UpdateOrgParams
- type UpdateUserParams
- type User
- type UserFilters
- type UserListResponse
- type UserOpts
- type UserWithClaims
- type UserWithToken
- type Users
- func (us *Users) AssignRole(p AssignRoleParams) error
- func (us *Users) ChangePassword(p ChangePasswordParams) error
- func (us *Users) Delete(id int64) error
- func (us *Users) Exists(p ExistsParams) (bool, error)
- func (us *Users) Get(id int64) (*User, error)
- func (us *Users) GetByUsername(username string) (*UserWithClaims, string, error)
- func (us *Users) List(p ListUsersParams) (*UserListResponse, error)
- func (us *Users) ResetPassword(p ResetPasswordParams) (string, error)
- func (us *Users) SignIn(p SignInParams) (*UserWithClaims, error)
- func (us *Users) SignUp(p SignUpParams) (*User, string, error)
- func (us *Users) Update(p UpdateUserParams) error
- type ValidationError
- type Validator
Constants ¶
const SeedMySql = `` /* 1421-byte string literal not displayed */
const SeedSqlLite = `` /* 1160-byte string literal not displayed */
Variables ¶
var ( ErrNotAuth = &NotAuthenticatedError{} ErrNotFound = &NotFoundError{} ErrCantDeleteSelf = ErrInvalid("You can't delete yourself.") ErrCantSuspendSelf = ErrInvalid("You can't suspend yourself.") ErrTokenExpired = ErrInvalid("That access token has expired.") )
var ( ErrEmailTaken = ErrInvalid("That email is taken.") ErrUsernameTaken = ErrInvalid("That username is taken.") ErrEmailInvalid = ErrInvalid("'email' invalid.") ErrEmailRequired = ErrInvalid("'email' required.") ErrUsernameRequired = ErrInvalid("'username' required.") ErrUsernameOrEmailRequired = ErrInvalid("'username' or 'email' required.") ErrPasswordRequired = ErrInvalid("'password' required.") ErrInvalidResetToken = ErrInvalid("Invalid reset token.") ErrPasswordInvalid = ErrInvalid( "'new_password' must contain: 1 Upper, 1 Lower, 1 Number, 1 Special and 8 Chars", "OR any alphanumeric with a minimum of 15 chars.") )
var ( Rgx_ValidPasswordChars = regexp.MustCompile("[a-z0-9A-Z\" !#$%&'()*+,\\-.\\/:;<=>?@\\[\\]^_\\`{\\|}~\\\\]+") Rgx_OneLower = regexp.MustCompile(`[a-z]+`) Rgx_OneUpper = regexp.MustCompile(`[A-Z]+`) Rgx_OneSpecial = regexp.MustCompile("[\" !#$%&'()*+,\\-.\\/:;<=>?@\\[\\]^_\\`{\\|}~\\\\]+") Rgx_OneNumeric = regexp.MustCompile(`\d+`) Rgx_PasswordLength = regexp.MustCompile(`^.{8,30}$`) )
var DebugLogger = log.New(os.Stdout, "GUS: ", log.Ldate|log.Lmicroseconds|log.Lshortfile)
var (
ErrNameRequired error = ErrInvalid("'name' required.")
)
var ErrorLogger = log.New(os.Stderr, "GUS ERR: ", log.Ldate|log.Lmicroseconds|log.Lshortfile)
Functions ¶
func ApplyUpdates ¶
func ApplyUpdates(original interface{}, updates interface{}) error
ApplyUpdates will apply updates to an 'original' struct and update fields based on an 'updates' struct The 'updates' struct should have point fields and should also serialize to and from json the same as the Intended destination fields.
func CheckNotFound ¶
func ErrInvalid ¶
func GetDb ¶
Gets the sql database handle for the database specified in the DriverName options parameter.
func GetRows ¶
GetRows returns a *sql.Rows iterator after adding limit and offset, results are sorted by default 'updated' desc. Sql added sample: + ' ORDER by updated DESC LIMIT 20 OFFSET 1'
func Milliseconds ¶
func RandStringBytesMask ¶
RandStringBytesMask use only for dev purposes to create predictable rand passwords since the source is constant.
func ValidatePassword ¶
Types ¶
type AssignRoleParams ¶
type AssignRoleParams struct { Id *int64 `json:"id"` Role *Role `json:"role"` CustomValidator `json:"-"` }
func (*AssignRoleParams) Validate ¶
func (va *AssignRoleParams) Validate() error
type ChangePasswordParams ¶
type ChangePasswordParams struct { Email string `json:"email"` ExistingPassword string `json:"existing_password"` NewPassword string `json:"new_password"` ResetToken string `json:"reset_token"` CustomValidator `json:"-"` }
func (*ChangePasswordParams) Validate ¶
func (va *ChangePasswordParams) Validate() error
type CreateOrgParams ¶
type CreateOrgParams struct { Name string `json:"name"` Type OrgType `json:"type"` Street string `json:"street"` Suburb string `json:"suburb"` Town string `json:"town"` Postcode string `json:"postcode"` Country string `json:"country"` CustomValidator `json:"-"` }
func (CreateOrgParams) Validate ¶
func (va CreateOrgParams) Validate() error
type CustomValidator ¶
type CustomValidator func() error
CustomValidator should be embedded in any struct which implements Validator, this allows consumers to override the validation.
func (CustomValidator) Validate ¶
func (f CustomValidator) Validate() error
type ExistsParams ¶
type ListArgs ¶
type ListArgs struct { Size int `json:"size"` // Page size Page int `json:"page"` // Zero-indexed page OrderBy string `json:"sort_by"` // Order by comma separated columns Direction SortDir `json:"direction"` // ASC or DESC Deleted bool `json:"deleted"` // Include deleted in results }
func (*ListArgs) ApplyDefaults ¶
func (p *ListArgs) ApplyDefaults()
type ListOrgsParams ¶
type ListOrgsParams struct { ListArgs CustomValidator `json:"-"` OrgFilters }
func (*ListOrgsParams) Validate ¶
func (va *ListOrgsParams) Validate() error
type ListUsersParams ¶
type ListUsersParams struct { ListArgs CustomValidator `json:"-"` UserFilters }
func (*ListUsersParams) Validate ¶
func (va *ListUsersParams) Validate() error
type NotAuthenticatedError ¶
type NotAuthenticatedError struct { }
func (*NotAuthenticatedError) Error ¶
func (n *NotAuthenticatedError) Error() string
type NotFoundError ¶
type NotFoundError struct { }
func (*NotFoundError) Error ¶
func (n *NotFoundError) Error() string
type Org ¶
type Org struct { Id int64 `json:"id"` Name string `json:"name"` Type OrgType `json:"type"` Street string `json:"street"` Suburb string `json:"suburb"` Town string `json:"town"` Postcode string `json:"postcode"` Country string `json:"country"` Updated int64 `json:"updated"` Created int64 `json:"created"` Suspended bool `json:"suspended"` }
type OrgFilters ¶
type OrgListResponse ¶
type Orgs ¶
type Orgs struct { *Suspender // contains filtered or unexported fields }
func (*Orgs) List ¶
func (us *Orgs) List(p ListOrgsParams) (*OrgListResponse, error)
func (*Orgs) Update ¶
func (us *Orgs) Update(p UpdateOrgParams) error
type PasswordGen ¶
type RateLimitExceededError ¶
type RateLimitExceededError struct {
Messages []string `json:"messages"`
}
func (*RateLimitExceededError) Error ¶
func (rl *RateLimitExceededError) Error() string
type ResetPasswordParams ¶
type ResetPasswordParams struct { Email string `json:"email"` CustomValidator `json:"-"` }
func (*ResetPasswordParams) Validate ¶
func (va *ResetPasswordParams) Validate() error
type SignInParams ¶
type SignInParams struct { Email string `json:"email"` Username string `json:"username"` Password string `json:"password"` CustomValidator `json:"-"` }
func (*SignInParams) Validate ¶
func (va *SignInParams) Validate() error
type SignUpParams ¶
type SignUpParams struct { Username string `json:"username"` InviteCode string `json:"invite_code"` Password string `json:"password"` Email string `json:"email"` FirstName string `json:"first_name"` LastName string `json:"last_name"` Phone string `json:"phone"` OrgId int64 `json:"org_id"` Role Role `json:"role"` Passive bool `json:"passive"` CustomValidator `json:"-"` }
func (*SignUpParams) Validate ¶
func (va *SignUpParams) Validate() error
type UpdateOrgParams ¶
type UpdateOrgParams struct { Id *int64 `json:"id"` Name *string `json:"name"` Street *string `json:"street"` Suburb *string `json:"suburb"` Town *string `json:"town"` Postcode *string `json:"postcode"` Country *string `json:"country"` CustomValidator `json:"-"` }
func (*UpdateOrgParams) Validate ¶
func (va *UpdateOrgParams) Validate() error
type UpdateUserParams ¶
type UpdateUserParams struct { Id *int64 `json:"id"` FirstName *string `json:"first_name"` LastName *string `json:"last_name"` Email *string `json:"email"` Phone *string `json:"phone"` CustomValidator `json:"-"` }
func (*UpdateUserParams) Validate ¶
func (va *UpdateUserParams) Validate() error
type User ¶
type User struct { Id int64 `json:"id"` Uid string `json:"uid"` // A universally unique id such as a uuid Username string `json:"username"` // Same as email?? If not supplied. Email string `json:"email"` FirstName string `json:"first_name"` LastName string `json:"last_name"` Phone string `json:"phone"` OrgId int64 `json:"org_id"` OrgName string `json:"org_name"` Updated int64 `json:"updated"` Created int64 `json:"created"` Role Role `json:"role"` Passive bool `json:"passive"` Suspended bool `json:"suspended"` }
type UserFilters ¶
type UserListResponse ¶
type UserOpts ¶
type UserOpts struct { AuthAttempts int64 // Maximum amount of times a user can attempt to login with a given username. AuthLockDuration int64 // Seconds which the user will be locked out if MaxAuthAttempts has been exceeded. PassGen PasswordGen // A function used to generate passwords and reset tokens // (as opposed to registered) this is the length of the generated password length. UsernameIsEmail *bool // When true (default) the username is the email address. When false the username can be specified independently. In either scenario both can be used to sign in with the password. ResetTokenExpiry int64 // ResetTokenExpiry Seconds before token expired. }
type UserWithClaims ¶
type UserWithToken ¶
type Users ¶
func (*Users) AssignRole ¶
func (us *Users) AssignRole(p AssignRoleParams) error
func (*Users) ChangePassword ¶
func (us *Users) ChangePassword(p ChangePasswordParams) error
func (*Users) Exists ¶
func (us *Users) Exists(p ExistsParams) (bool, error)
Exists returns true only if we know for certain that the email and username don't exists, otherwise we assume they might exist or they definitely exists if the error indicates as such.
func (*Users) GetByUsername ¶
func (us *Users) GetByUsername(username string) (*UserWithClaims, string, error)
GetByUsername returns a user by username (or email) as well as a password hash.
func (*Users) List ¶
func (us *Users) List(p ListUsersParams) (*UserListResponse, error)
func (*Users) ResetPassword ¶
func (us *Users) ResetPassword(p ResetPasswordParams) (string, error)
func (*Users) SignIn ¶
func (us *Users) SignIn(p SignInParams) (*UserWithClaims, error)
func (*Users) SignUp ¶
func (us *Users) SignUp(p SignUpParams) (*User, string, error)
SignUp returns a user, random password and [error]
func (*Users) Update ¶
func (us *Users) Update(p UpdateUserParams) error
type ValidationError ¶
type ValidationError struct {
Messages []string `json:"messages"`
}
func (*ValidationError) Error ¶
func (v *ValidationError) Error() string