models

package
v0.0.0-...-a212db1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateAuth

func CreateAuth(userid string, td *TokenDetails) error

func DeleteAuth

func DeleteAuth(givenUuid string) (int64, error)

func DeleteTokens

func DeleteTokens(authD *AccessDetails) error

func ExtractToken

func ExtractToken(r *http.Request) string

func FetchAuth

func FetchAuth(authD *AccessDetails) (string, error)

func InitDb

func InitDb()

TODO: move database to common location db handler InitDb initializes a global database connection. An existing connection will be closed.

func VerifyToken

func VerifyToken(r *http.Request) (*jwt.Token, error)

Parse, validate, and return a token. keyFunc will receive the parsed token and should return the key for validating.

Types

type AccessDetails

type AccessDetails struct {
	AccessUuid string
	UserId     string
}

func ExtractTokenMetadata

func ExtractTokenMetadata(r *http.Request) (*AccessDetails, error)

type TokenDetails

type TokenDetails struct {
	AccessToken  string
	RefreshToken string
	AccessUuid   string
	RefreshUuid  string
	AtExpires    int64
	RtExpires    int64
}

func CreateToken

func CreateToken(userid string) (*TokenDetails, error)

type User

type User struct {
	UUID       string    `json:"-" db:"uuid"`
	Username   string    `json:"username" db:"username"`
	Password   string    `json:"password" db:"password"`
	Email      string    `json:"email" db:"email"`
	FirstName  string    `json:"first_name" db:"firstname"`
	LastName   string    `json:"last_name" db:"lastname"`
	IsDisabled bool      `json:"-" db:"isdisabled"`
	CreatedAt  time.Time `json:"-" db:"createdat"`
	UpdatedAt  time.Time `json:"-" db:"updatedat"`
}

func CreateUser

func CreateUser(username string, password string, email string, first_name string, last_name string) (*User, error)

func GetAccount

func GetAccount(uuid string) (*User, bool)

GetAccount returns an account with matching UUID Returns false if no account with such UUID exists

func GetAccountByCredential

func GetAccountByCredential(id string) (*User, bool)

GetAccountByCredential returns an active account (non disabled, no activation code, no reset password code) with matching username or email address. Returns false if no account with such username or email address exists.

func GetAccountByLogin

func GetAccountByLogin(login string) (*User, bool)

GetAccountByUsername returns an active account (non disabled, no activation code, no reset password code) with matching login. Returns false if no account with such login exists.

func ListAccounts

func ListAccounts() []User

ListAccounts returns all accounts stored in the database

func SearchAccounts

func SearchAccounts(search string) []User

SearchAccounts returns all accounts stored in the database where the account name (firstName, middleName, lastName or login) contains the search string.

func (*User) Save

func (acc *User) Save() error

Create stores the account as new Account in the database. If the UUID string is empty a new UUID will be generated.

func (*User) SetPassword

func (acc *User) SetPassword(plain string) error

SetPassword hashes the plain text password and sets PWHash to the new value.

func (*User) Validate

func (acc *User) Validate() bool

func (*User) VerifyPassword

func (acc *User) VerifyPassword(plain string) bool

VerifyPassword checks whether the stored hash matches the plain text password

Jump to

Keyboard shortcuts

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