auth

package
v0.0.0-...-7b7735e Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	SUPERADMIN = "SuperAdmin"
	ADMIN      = "Admin"
	USER       = "User"
	// Regular expression for matching email addresses
	EMAILREGEX = `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`
)

Variables

This section is empty.

Functions

func AuthRoutes

func AuthRoutes(e *echo.Echo, config echojwt.Config, db *gorm.DB, secret string, sender EmailSender)

func CreateUser

func CreateUser(db *gorm.DB, user *User) error

func SendEmail

func SendEmail(sender EmailSender, to []string, msg []byte) error

Types

type EmailSender

type EmailSender struct {
	Email    string
	Password string
}

email verifications sender email and password

type JwtCustomClaims

type JwtCustomClaims struct {
	UserID   string `json:"userId"`
	Role     string `json:"role"`
	IsActive bool   `json:"isActive"`
	jwt.RegisteredClaims
}

type Login

type Login struct {
	Email    string `json:"email" form:"email" validate:"required"`
	Password string `json:"password" form:"password" validate:"required"`
}

type User

type User struct {
	ID        string    `gorm:"primary_key" json:"id"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
	Email     string    `gorm:"not null;index;unique" json:"email" form:"email"`
	Password  string    `gorm:"not null" json:"-" form:"password"`
	Role      string    `gorm:"not null" json:"role" form:"role"`
	IsActive  bool      `gorm:"not null;default:true" json:"isActive" form:"isActive"`
}

user model in database

func (*User) HashPassword

func (u *User) HashPassword(password string) error

HashPassword securely hashes the provided password and sets it in the Password field.

func (*User) VerifyActivity

func (u *User) VerifyActivity(isActive bool) bool

Verify Activity.

func (*User) VerifyPassword

func (u *User) VerifyPassword(password string) error

Verify Password.

type UserCreate

type UserCreate struct {
	Email    string `json:"email" form:"email" validate:"required"`
	Password string `json:"password" form:"password" validate:"required"`
}

func (*UserCreate) Serialize

func (u *UserCreate) Serialize() *User

serializes user creations from UserCreate form to insert to database

Jump to

Keyboard shortcuts

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