utils

package
v0.0.0-...-57241a5 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool
func ConstructVerificationLink(baseUrl, path, verificationToken string, email string) (string, error)

func CreateVerificationToken

func CreateVerificationToken() string

func HashPassword

func HashPassword(password string) (string, error)

func InitVerificationTokenExpiryIndex

func InitVerificationTokenExpiryIndex(collection *mongo.Collection) error

Types

type AccessDetails

type AccessDetails struct {
	ID         primitive.ObjectID `json:"id" bson:"_id,omitempty"`
	AccessUuid string             `json:"access_uuid" bson:"access_uuid"`
	UserId     primitive.ObjectID `json:"user_id" bson:"user_id"`
	ExpireAt   time.Time          `json:"expire_at" bson:"expire_at"`
}

type AccessTokenDetails

type AccessTokenDetails struct {
	AccessToken string `json:"access_token"`
	AcessUuid   string `json:"-"`
	AtExpires   int64  `json:"at_expires"`
}

type AccessTokenManager

type AccessTokenManager struct {
	// contains filtered or unexported fields
}

func NewTokenAccessManager

func NewTokenAccessManager(accessTokenSecret string, accessTokenValidityInHours int64, db db.IDatabase) *AccessTokenManager

func (*AccessTokenManager) DeleteAccessToken

func (atm *AccessTokenManager) DeleteAccessToken(filter interface{}) error

func (*AccessTokenManager) ExtractAccessTokenMetadata

func (atm *AccessTokenManager) ExtractAccessTokenMetadata(token *jwt.Token) (*AccessDetails, error)

func (*AccessTokenManager) FindAccessToken

func (atm *AccessTokenManager) FindAccessToken(uuid string) (*AccessDetails, error)

func (*AccessTokenManager) GenerateAccessToken

func (atm *AccessTokenManager) GenerateAccessToken(userId primitive.ObjectID) (*AccessTokenDetails, error)

func (*AccessTokenManager) SaveAccessToken

func (atm *AccessTokenManager) SaveAccessToken(userId primitive.ObjectID, atd *AccessTokenDetails) error

func (*AccessTokenManager) ValidateAccessToken

func (atm *AccessTokenManager) ValidateAccessToken(token string, secret string) (*jwt.Token, error)

type ApiResponse

type ApiResponse struct {
	Success bool        `json:"success"`
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
	Error   interface{} `json:"error,omitempty"`
}

func NewErrorResponse

func NewErrorResponse(err interface{}, message string) ApiResponse

func NewSuccessResponse

func NewSuccessResponse(data interface{}, message string) ApiResponse

type EmailManager

type EmailManager struct {
	SenderEmail string
	SenderName  string
	ApiKey      string
}

func NewEmailManager

func NewEmailManager(senderEmail, senderName, apiKey string) *EmailManager

func (*EmailManager) SendResetPasswordToken

func (eu *EmailManager) SendResetPasswordToken(email, firstname, tokenUrl string) error

func (*EmailManager) SendSignUpVerificationToken

func (eu *EmailManager) SendSignUpVerificationToken(email, firstname, tokenUrl string) error

type IAccessTokenManager

type IAccessTokenManager interface {
	SaveAccessToken(userId primitive.ObjectID, atd *AccessTokenDetails) error
	GenerateAccessToken(userId primitive.ObjectID) (*AccessTokenDetails, error)
	DeleteAccessToken(filter interface{}) error
}

type IEmailManager

type IEmailManager interface {
	SendSignUpVerificationToken(email, firstname, tokenUrl string) error
	SendResetPasswordToken(email, firstname, tokenUrl string) error
}

type IMiddlewareAccessTokenManager

type IMiddlewareAccessTokenManager interface {
	ExtractAccessTokenMetadata(token *jwt.Token) (*AccessDetails, error)
	ValidateAccessToken(token string, secret string) (*jwt.Token, error)
	FindAccessToken(uuid string) (*AccessDetails, error)
}

type IVerificationTokenManager

type IVerificationTokenManager interface {
	SaveVerificationToken(email string, verificationToken string) error
	ValidateVerificationToken(email string, verificationToken string) (bool, error)
}

type LoginReq

type LoginReq struct {
	Email    string `json:"email" binding:"required"`
	Password string `json:"password" binding:"required"`
}

type SignUpReq

type SignUpReq struct {
	Email     string `json:"email" binding:"required"`
	Password  string `json:"password" binding:"required"`
	FirstName string `json:"first_name" binding:"required"`
	LastName  string `json:"last_name" binding:"required"`
}

type StudentRegisteredTutorRes

type StudentRegisteredTutorRes struct {
	TutorId      primitive.ObjectID `json:"tutor_id"`
	Email        string             `json:"email"`
	FirstName    string             `json:"first_name"`
	LastName     string             `json:"last_name"`
	SubjectId    primitive.ObjectID `json:"subject_id"`
	RegisteredAt time.Time          `json:"registered_at"`
}

type VerificationToken

type VerificationToken struct {
	ID        primitive.ObjectID `json:"id" bson:"_id,omitempty"`
	Email     string             `json:"email" bson:"email"`
	Token     string             `json:"token" bson:"token"`
	ExpiresAt time.Time          `json:"expires_at" bson:"expires_at"`
	CreatedAt time.Time          `json:"created_at" bson:"created_at"`
}

type VerificationTokenManager

type VerificationTokenManager struct {
	SignUpTokenValidityInSecs         uint
	ForgotPasswordTokenValidityInSecs uint
	// contains filtered or unexported fields
}

func NewVerificationTokenManager

func NewVerificationTokenManager(db db.IDatabase, signUpTokenValidityInSecs uint, forgotPasswordTokenValidityInSecs uint) *VerificationTokenManager

func (*VerificationTokenManager) SaveVerificationToken

func (vtm *VerificationTokenManager) SaveVerificationToken(email string, verificationToken string) error

func (*VerificationTokenManager) ValidateVerificationToken

func (vtm *VerificationTokenManager) ValidateVerificationToken(email string, verificationToken string) (bool, error)

Jump to

Keyboard shortcuts

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