utils

package
v0.0.0-...-4780336 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PASSWORD_MIN_LEN = 12
	PASSWORD_MAX_LEN = 512
)

Variables

View Source
var CurrentWeekdayStrategy = WeekDayStrategy{
	// contains filtered or unexported fields
}

Functions

func BlurEmailAddress

func BlurEmailAddress(email string) string

BlurEmailAddress transforms an email address to reduce exposed personal info

func CheckEmailFormat

func CheckEmailFormat(email string) bool

CheckEmailFormat to check if input string is a correct email address

func CheckLanguageCode

func CheckLanguageCode(code string) bool

CheckLanguageCode checks if a string can be considered as a language code

func CheckPasswordFormat

func CheckPasswordFormat(password string) bool

CheckPasswordFormat to check if password fulfills password rules

func GenerateOTPCode

func GenerateOTPCode(length int) (string, error)

GenerateOTPCode generates a random OTP code of the given length

func GenerateUniqueTokenString

func GenerateUniqueTokenString() (string, error)

func GetExpirationTime

func GetExpirationTime(validityPeriod time.Duration) time.Time

func GetMainAndOtherProfiles

func GetMainAndOtherProfiles(user userTypes.User) (mainProfileID string, otherProfileIDs []string)

GetMainAndOtherProfiles extract main profile ID and secondary profiles from a user account info

func HasMoreAttemptsRecently

func HasMoreAttemptsRecently(attempts []int64, moreThan int, intervalSeconds int64) bool

func InitNewEmailUser

func InitNewEmailUser(
	email string,
	password string,
	locale string,
) userTypes.User

func InitWeekdayAssignationStrategy

func InitWeekdayAssignationStrategy(
	weekdayAssignation map[string]int,
)

func InitWeekdayAssignationStrategyFromEnv

func InitWeekdayAssignationStrategyFromEnv(
	envWeekdayAssignation string,
)

func IsPasswordOnBlocklist

func IsPasswordOnBlocklist(password string) bool

func LoadBlockedPasswords

func LoadBlockedPasswords(filename string) error

func ParseWeeklyWeight

func ParseWeeklyWeight(str string) ([]int, error)

ParseWeeklyWeight parse a string attributing a weight for each day of the week Expected format is a comma separated assignation with [DayName]=Weight with DayName = Mon,Tue,Web,Thu,Frid,Sat,Sun (case insensitive) Weight is a positive integer value or Zero

func ReachedExpirationTime

func ReachedExpirationTime(t time.Time) bool

func RemoveAttemptsOlderThan

func RemoveAttemptsOlderThan(attempts []int64, olderThanSeconds int64) []int64

func SanitizeEmail

func SanitizeEmail(email string) string

func SanitizePhoneNumber

func SanitizePhoneNumber(phone string) string

Types

type Interval

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

type WeekDayStrategy

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

func CreateWeekdayDefaultStrategy

func CreateWeekdayDefaultStrategy() WeekDayStrategy

func CreateWeekdayWeightedStrategy

func CreateWeekdayWeightedStrategy(weights []int) WeekDayStrategy

func (*WeekDayStrategy) String

func (s *WeekDayStrategy) String() string

func (*WeekDayStrategy) Weekday

func (s *WeekDayStrategy) Weekday() int

Assign a new weekday using the assignation strategy

type Weight

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

Weekday assignation strategy

func CreateWeight

func CreateWeight(w []int) Weight

CreateWeight creates a weighted structure to handle the weighted assignation

func (*Weight) Lookup

func (w *Weight) Lookup(value int) int

Lookup computes the entry Value is expected from 0..total-1

func (*Weight) String

func (w *Weight) String() string

Jump to

Keyboard shortcuts

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