utils

package
v0.0.0-...-5df9c1d Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CensorEmail

func CensorEmail(email string) string

CensorEmail censors the email address for the response converts testmail@gmail.com to tes*****@gmail.com

func CheckPassword

func CheckPassword(password string, hash string) bool

CheckPassword checks if a given password matches with the given hash (contains salt)

func ExtractHashtags

func ExtractHashtags(text string) []string

ExtractHashtags extracts all hashtags from a given text and returns them as a slice of strings

func FormatImageUrl

func FormatImageUrl(imageId string, extension string) string

FormatImageUrl formats the image url for the response adds the base url with image id and file extension

func GenerateAccessToken

func GenerateAccessToken(username string) (string, error)

GenerateAccessToken generates new access jwt token with user id claim for 3 hours validity

func GenerateImageMetadataDTOFromImage

func GenerateImageMetadataDTOFromImage(image *models.Image) *models.ImageMetadataDTO

GenerateImageMetadataDTOFromImage generates an ImageMetadataDTO from an Image and returns nil if the Image is nil

func GenerateLocationDTOFromLocation

func GenerateLocationDTOFromLocation(location *models.Location) *models.LocationDTO

GenerateLocationDTOFromLocation generates a LocationDTO from a Location and returns nil if the Location is nil

func GenerateRefreshToken

func GenerateRefreshToken(username string) (string, error)

GenerateRefreshToken generates new refresh jwt token with user id claim for one week validity

func GenerateSixDigitCode

func GenerateSixDigitCode() (int64, error)

GenerateSixDigitCode generates a code that is used for email verification

func GenerateUserDTOFromUser

func GenerateUserDTOFromUser(user *models.User) *models.UserDTO

GenerateUserDTOFromUser generates a UserDTO from a User and returns nil if the User is nil This function is used multiple times in the services to easily convert a User to a DTO with correct image wrapping

func GetActivationEmailBody

func GetActivationEmailBody(token string) string

GetActivationEmailBody returns the HTML body for an activation email sending the activation code

func GetPasswordResetEmailBody

func GetPasswordResetEmailBody(username string, resetToken string) string

GetPasswordResetEmailBody returns the HTML body for a password reset email

func GetWelcomeEmailBody

func GetWelcomeEmailBody(username string) string

GetWelcomeEmailBody returns the HTML body for a welcome email

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes a given password with a random salt and returns hash

func VerifyJWTToken

func VerifyJWTToken(tokenString string) (string, bool, error)

VerifyJWTToken verifies given token and returns username and true if token is refresh token

Types

type MockValidator

type MockValidator struct {
	mock.Mock
	Validator
}

func (*MockValidator) ValidateEmailExistance

func (m *MockValidator) ValidateEmailExistance(email string) bool

ValidateEmailExistance Only override ValidateEmailExistance function because it is the only function that needs to be mocked

type Validator

type Validator struct {
}

func NewValidator

func NewValidator() *Validator

func (*Validator) ValidateEmailExistance

func (v *Validator) ValidateEmailExistance(email string) bool

ValidateEmailExistance tries to reach out to email to see if it really exists

func (*Validator) ValidateEmailSyntax

func (v *Validator) ValidateEmailSyntax(email string) bool

ValidateEmailSyntax validates if an email meets specifications

func (*Validator) ValidateImage

func (v *Validator) ValidateImage(imageData []byte) (bool, string, int, int)

ValidateImage validates if an image is correct file type and can be "opened", additionally returns file format, width and height

func (*Validator) ValidateLatitude

func (v *Validator) ValidateLatitude(latitude float64) bool

ValidateLatitude validates if latitude is in valid range

func (*Validator) ValidateLongitude

func (v *Validator) ValidateLongitude(longitude float64) bool

ValidateLongitude validates if longitude is in valid range

func (*Validator) ValidateNickname

func (v *Validator) ValidateNickname(nickname string) bool

ValidateNickname validates if a nickname meets specifications

func (*Validator) ValidatePassword

func (v *Validator) ValidatePassword(password string) bool

ValidatePassword validates if a password meets specifications

func (*Validator) ValidateStatus

func (v *Validator) ValidateStatus(status string) bool

ValidateStatus validates if a status meets specifications

func (*Validator) ValidateUsername

func (v *Validator) ValidateUsername(username string) bool

ValidateUsername validates if a password meets specifications

type ValidatorInterface

type ValidatorInterface interface {
	ValidateUsername(username string) bool
	ValidateNickname(nickname string) bool
	ValidateEmailSyntax(email string) bool
	ValidateEmailExistance(email string) bool
	ValidatePassword(password string) bool
	ValidateStatus(status string) bool
	ValidateLatitude(latitude float64) bool
	ValidateLongitude(longitude float64) bool
	ValidateImage(imageData []byte) (bool, string, int, int)
}

Jump to

Keyboard shortcuts

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