Documentation ¶
Index ¶
- Constants
- Variables
- func CalculateAge(birthday time.Time) int
- func CalculateDistance(startPoint geodist.Coord, destination geodist.Coord) (float64, error)
- func CalculateNextAllowedLoginTime(hour, minute, second time.Duration) time.Time
- func CheckIfCurrentDBIsLocal() bool
- func ComparePIN(rawPwd string, salt string, encodedPwd string, options *Options) bool
- func ConvertJSONStringToMap(jsonString string) (map[string]interface{}, error)
- func ConvertTimeToScalarDate(t time.Time) (scalarutils.Date, error)
- func EncryptPIN(rawPwd string, options *Options) (string, string)
- func FormatFilterParamsHelper(a map[string]interface{}) map[string]interface{}
- func GenerateOTP() (string, error)
- func GenerateTempPIN(ctx context.Context) (string, error)
- func GetLoggedInUserID(ctx context.Context) *string
- func GetValueFromContext(ctx context.Context, key firebasetools.ContextKey) (string, error)
- func InterfaceToFloat64(n interface{}) float64
- func InterfaceToInt(n interface{}) int
- func InterfaceToString(n interface{}) string
- func LoadScreeningTools() ([]*dto.ScreeningToolInput, error)
- func NextAllowedLoginTime(loginAttempts int) time.Time
- func ParseChoice[T any](choices []T, choice string) (*T, error)
- func ParseFacilitiesFromCSV(path string) ([]*dto.FacilityInput, error)
- func ReadCSVFile(path string) (*csv.Reader, error)
- func ReadFile(path string) ([]byte, error)
- func ShuffleSecurityQuestionResponses(slice []*domain.SecurityQuestionResponse) ([]*domain.SecurityQuestionResponse, error)
- func TruncateMatrixUserID(userID string) string
- func ValidatePIN(pin string) error
- func ValidatePINDigits(pin string) error
- func ValidatePINLength(pin string) error
- type Options
Constants ¶
const ( // BackOffWaitTime is the base value used for exponential backoff i.e 3**i where i is // number of failed login counts BackOffWaitTime = 3 // OrganisationContextKey is used to add/retrieve the organisation ID in the context OrganisationContextKey = firebasetools.ContextKey("OrganisationID") // ProgramContextKey is used to add/retrieve the program ID that is passed around in the context ProgramContextKey = firebasetools.ContextKey("ProgramID") )
const ( // DefaultSaltLen is the length of generated salt for the user is 256 DefaultSaltLen = 256 // DefaultKeyLen is the length of encoded key in PBKDF2 function is 512 DefaultKeyLen = 512 )
const FeedbackNotificationEmail = `` /* 3068-byte string literal not displayed */
FeedbackNotificationEmail if the supports feedback email template for feedback
Variables ¶
var DefaultHashFunction = sha512.New
DefaultHashFunction ...
Functions ¶
func CalculateAge ¶
CalculateAge calculates the age of a community member
func CalculateDistance ¶
CalculateDistance is used to calculate the distance between two points on the earth give the starting point coordinates and destination point coordinates
func CalculateNextAllowedLoginTime ¶
CalculateNextAllowedLoginTime will be used to calculate the next allowed login time in cases where a login failure occurs. If the failed login count is 1, then the next allowed login time will be after 3 seconds due to exponential backoff.
func CheckIfCurrentDBIsLocal ¶
func CheckIfCurrentDBIsLocal() bool
CheckIfCurrentDBIsLocal checks whether the database used to run the test is a test/local database. If not, the setup exits
func ComparePIN ¶
ComparePIN takes four arguments, the raw password, its generated salt, the encoded password, and a pointer to the Options struct, and returns a boolean value determining whether the password is the correct one or not. Passing `nil` as the last argument resorts to default options.
func ConvertJSONStringToMap ¶
ConvertJSONStringToMap converts a json string to a map of string interface{}
func ConvertTimeToScalarDate ¶
func ConvertTimeToScalarDate(t time.Time) (scalarutils.Date, error)
ConvertTimeToScalarDate converts a time to a scalar date
func EncryptPIN ¶
EncryptPIN takes two arguments, a raw pin, and a pointer to an Options struct. In order to use default options, pass `nil` as the second argument. It returns the generated salt and encoded key for the user.
func FormatFilterParamsHelper ¶
FormatFilterParamsHelper is a helper function that formats the filter params from getstream
func GenerateOTP ¶
GenerateOTP is used to generate a one time password
func GenerateTempPIN ¶
GenerateTempPIN generates a temporary One Time PIN for a user The PIN will have 4 digits formatted as a string
func GetLoggedInUserID ¶
func GetValueFromContext ¶
func GetValueFromContext(ctx context.Context, key firebasetools.ContextKey) (string, error)
GetValueFromContext retrieves a value from the supplied context
func InterfaceToFloat64 ¶
func InterfaceToFloat64(n interface{}) float64
InterfaceToFloat64 converts an interface to float64
func InterfaceToInt ¶
func InterfaceToInt(n interface{}) int
InterfaceToInt converts an interface to an int
func InterfaceToString ¶
func InterfaceToString(n interface{}) string
InterfaceToString converts an interface to a string
func LoadScreeningTools ¶
func LoadScreeningTools() ([]*dto.ScreeningToolInput, error)
LoadScreeningTools is a helper function that loads the given screening tools when a program is created TODO: temporary solution. this should be removed after implementing screening tool creation in the frontend
func NextAllowedLoginTime ¶
NextAllowedLoginTime calculates the user's next allowed login time. This implements an exponential backoff that will help to mitigate brute force attacks. Each incorrect PIN entry will add a delay, hence increasing the time to the next allowed login
func ParseChoice ¶
ParseChoice validates a choice is in the range of a choices
func ParseFacilitiesFromCSV ¶
func ParseFacilitiesFromCSV(path string) ([]*dto.FacilityInput, error)
ParseFacilitiesFromCSV maps the values of the csv file to the Facilities object
func ReadCSVFile ¶
ReadCSVFile reads the content of a csv file
func ShuffleSecurityQuestionResponses ¶
func ShuffleSecurityQuestionResponses(slice []*domain.SecurityQuestionResponse) ([]*domain.SecurityQuestionResponse, error)
ShuffleSecurityQuestionResponses is used to randomize users security questions. It uses crypto/rand package which makes use of a shuffling algorithm that provides higher level of randomness and security.
func TruncateMatrixUserID ¶
TruncateMatrixUserID truncates the Matrix's user ID and returns the name
func ValidatePIN ¶
ValidatePIN is used to check for the validity of the PIN provided.
func ValidatePINDigits ¶
ValidatePINDigits validates user pin to ensure a PIN only contains digits