Ingot.Auth.InviteCode (Ingot v0.1.0)

View Source

Generate and validate invite codes for external labelers.

Invite codes are used to grant access to specific queues without requiring organizational SSO accounts. Codes are alphanumeric strings that exclude ambiguous characters (0, O, I, L) for better readability.

Examples

# Generate a code
code = InviteCode.generate()
#=> "ABCD1234WXYZ"

# Format for display
InviteCode.format_for_display(code)
#=> "ABCD-1234-WXYZ"

# Normalize user input
InviteCode.normalize("abcd-1234-wxyz")
#=> "ABCD1234WXYZ"

# Validate format
InviteCode.valid_format?("ABCD1234WXYZ")
#=> true

Summary

Functions

Format code with dashes for display readability.

Generate a random invite code.

Normalize user input by removing dashes/spaces and uppercasing.

Validate invite code format.

Functions

format_for_display(code)

@spec format_for_display(String.t()) :: String.t()

Format code with dashes for display readability.

Inserts dashes every 4 characters.

Examples

iex> InviteCode.format_for_display("ABCD1234WXYZ")
"ABCD-1234-WXYZ"

iex> InviteCode.format_for_display("ABC123")
"ABC1-23"

generate(opts \\ [])

@spec generate(keyword()) :: String.t()

Generate a random invite code.

Options

  • :length - Code length (default: 12, min: 6, max: 32)

Examples

iex> code = InviteCode.generate()
iex> String.length(code)
12

iex> code = InviteCode.generate(length: 8)
iex> String.length(code)
8

normalize(code)

@spec normalize(String.t() | nil) :: String.t()

Normalize user input by removing dashes/spaces and uppercasing.

Examples

iex> InviteCode.normalize("abcd-1234-wxyz")
"ABCD1234WXYZ"

iex> InviteCode.normalize("ABCD 1234 WXYZ")
"ABCD1234WXYZ"

iex> InviteCode.normalize(nil)
""

valid_format?(code)

@spec valid_format?(String.t() | nil) :: boolean()

Validate invite code format.

Checks that the code:

  • Is not empty
  • Contains only valid characters (no ambiguous chars)
  • Is within acceptable length range

Examples

iex> InviteCode.valid_format?("ABCD1234WXYZ")
true

iex> InviteCode.valid_format?("ABCD-1234")
false

iex> InviteCode.valid_format?("ABCD0123")
false