auth

package
v0.0.0-...-ecac287 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComparePasswords

func ComparePasswords(hashedpassword, password []byte) bool

ComparePasswords to check if they are equivalent

func HashPassword

func HashPassword(password string) (string, error)

HashPassword given password string. This function is a wrapper to the bcrypt GenerateFromPassword

func IsValidEmail

func IsValidEmail(email string) bool

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

func (db *DB) AuthenticateUser(auth *model.Authenticate) (*model.Token, error)

AuthenticateUser and return a token

func (*DB) FindByEmail

func (db *DB) FindByEmail(email string) (*model.User, error)

FindByEmail in database

func (*DB) FindByUsername

func (db *DB) FindByUsername(username string) (*model.User, error)

FindByUsername utility function from the Mongo database

func (*DB) FindUser

func (db *DB) FindUser(email string) (*UserModel, error)

FindUser from database and return

func (*DB) RegisterUser

func (db *DB) RegisterUser(input *model.RegisterInput) (*model.Token, error)

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

Jump to

Keyboard shortcuts

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