Documentation ¶
Index ¶
- func ComparePasswords(hashedpassword, password []byte) bool
- func HashPassword(password string) (string, error)
- func IsValidEmail(email string) bool
- func RefreshJWT(token *model.RefreshToken) (*model.Token, error)
- func ValidUserInput(input *model.RegisterInput) (bool, error)
- func ValidateAndPrepare(registerInput *model.RegisterInput) (*model.RegisterInput, error)
- type DB
- func (db *DB) AuthenticateUser(auth *model.Authenticate) (*model.Token, error)
- func (db *DB) FindByEmail(email string) (*model.User, error)
- func (db *DB) FindByUsername(username string) (*model.User, error)
- func (db *DB) FindUser(email string) (*UserModel, error)
- func (db *DB) RegisterUser(input *model.RegisterInput) (*model.Token, error)
- type UserModel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComparePasswords ¶
ComparePasswords to check if they are equivalent
func HashPassword ¶
HashPassword given password string. This function is a wrapper to the bcrypt GenerateFromPassword
func IsValidEmail ¶
IsValidEmail returns true if its a valid syntax email
code taken from: https://golangcode.com/validate-an-email-address/
func RefreshJWT ¶
func RefreshJWT(token *model.RefreshToken) (*model.Token, error)
RefreshJWT Provides a new token provided it has a least a minute left of lifetime
func ValidUserInput ¶
func ValidUserInput(input *model.RegisterInput) (bool, error)
ValidUserInput validates given passwords, email and username
func ValidateAndPrepare ¶
func ValidateAndPrepare(registerInput *model.RegisterInput) (*model.RegisterInput, error)
ValidateAndPrepare user input for insertion to database
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB wraps the mongo.Client object
func ConnectMongo ¶
func ConnectMongo() *DB
ConnectMongo to database and return a pointer to a DB object
func (*DB) AuthenticateUser ¶
AuthenticateUser and return a token
func (*DB) FindByEmail ¶
FindByEmail in database
func (*DB) FindByUsername ¶
FindByUsername utility function from the Mongo database
func (*DB) RegisterUser ¶
RegisterUser a new user into the database, this function asumes input validation has been performed
type UserModel ¶
type UserModel struct { ID primitive.ObjectID `bson:"_id" json:"_id,omitempty"` Fname string `json:"fname"` Lname string `json:"lname"` Email string `json:"email"` Username string `json:"username"` Password string `json:"password"` }
UserModel representation of data in database
func CreateUser ¶
func CreateUser(input *model.RegisterInput) *UserModel
CreateUser fills struct values for insertion in database