Skip to contents

Quick Start Guide

This guide gets you productive with artauth in minutes. We’ll cover the most common use cases with minimal explanation.

Setup

library(artauth)

# Configure database connection
Sys.setenv(
  ART_PGHOST_SITE = "your-host",
  ART_PGPORT_SITE = "25060",
  ART_PGUSER_SITE = "your-user",
  ART_PGPASS_SITE = "your-password",
  ART_PGDATA_SITE = "marketing"
)

# Test connection
cn <- artcore::dbc("artsite")
artcore::dbd(cn)

Artist Waiting List

Add an Artist

# Minimal signup
waitlist_id <- create_waitlist_entry(
  email = "artist@example.com",
  full_name = "Jane Artist"
)

# Full signup with optional fields
waitlist_id <- create_waitlist_entry(
  email = "artist@example.com",
  full_name = "Jane Artist",
  specialties = "Digital Photography, NFT Art",
  url_portfolio = "https://janeartist.com",
  source = "landing_page"
)

Review Applications

# Get pending applications
pending <- get_pending_waitlist()

# Look up specific entry
entry <- get_waitlist_entry(waitlist_id)

Update Status

# Typical workflow
update_waitlist_status(waitlist_id, status = "reviewing")
update_waitlist_status(waitlist_id, status = "invited")

# Convert to user account
user_id <- convert_waitlist_to_user(waitlist_id)

Whitepaper Tracking

Log a Download

# Basic download
download_id <- log_whitepaper_download(
  email = "investor@vc.com",
  user_type = "investor"
)

# From web request (Shiny)
download_id <- log_whitepaper_download(
  email = input$email,
  user_type = "investor",
  ip_address = session$request$REMOTE_ADDR,
  user_agent = session$request$HTTP_USER_AGENT
)

Check Download Status

# Has this email downloaded before?
if (has_downloaded_whitepaper("investor@vc.com")) {
  message("Returning visitor")
}

# Get download history
downloads <- get_downloads_by_email("investor@vc.com")

Get Recent Downloads

# Latest downloads
recent <- get_recent_downloads(limit = 20)

# Latest investor downloads
investors <- get_recent_downloads(
  limit = 50,
  user_type = "investor"
)

Analytics

# All-time stats
stats <- get_whitepaper_stats()
print(stats$total_downloads)
print(stats$by_user_type)

# Monthly stats
stats <- get_whitepaper_stats(
  start_date = as.Date("2024-11-01"),
  end_date = as.Date("2024-11-30")
)

Security Utilities

Token Generation

# Generate token for magic link
token <- generate_secure_token(32)  # 64 hex chars

# Hash for storage
hashed <- hash_token(token)

# Send token to user, store hash in database

Email Validation

# Validate before database insertion
if (!is_valid_email(input$email)) {
  stop("Invalid email format")
}

create_waitlist_entry(
  email = input$email,
  full_name = input$full_name
)

Shiny Integration

Waiting List Form

library(shiny)

ui <- fluidPage(
  titlePanel("Join Artist Pilot Program"),
  sidebarLayout(
    sidebarPanel(
      textInput("email", "Email *"),
      textInput("full_name", "Full Name *"),
      textInput("specialties", "Specialties"),
      textInput("url_portfolio", "Portfolio URL"),
      textAreaInput("message", "Why join?"),
      actionButton("submit", "Submit Application")
    ),
    mainPanel(
      uiOutput("result")
    )
  )
)

server <- function(input, output, session) {
  observeEvent(input$submit, {
    # Validate email
    if (!artauth::is_valid_email(input$email)) {
      showNotification("Invalid email", type = "error")
      return()
    }

    # Create entry
    tryCatch({
      waitlist_id <- artauth::create_waitlist_entry(
        email = input$email,
        full_name = input$full_name,
        specialties = input$specialties,
        url_portfolio = input$url_portfolio,
        message = input$message,
        source = "shiny_app"
      )

      output$result <- renderUI({
        tagList(
          h4("Success!"),
          p("Application submitted. We'll be in touch!")
        )
      })
    }, error = function(e) {
      if (grepl("already exists", e$message)) {
        showNotification("Email already registered", type = "warning")
      } else {
        showNotification("Error occurred", type = "error")
      }
    })
  })
}

shinyApp(ui, server)

Whitepaper Download Page

library(shiny)

ui <- fluidPage(
  titlePanel("Download Whitepaper"),
  sidebarLayout(
    sidebarPanel(
      textInput("email", "Email Address"),
      selectInput("user_type", "I am a(n):",
        choices = c(
          "Investor" = "investor",
          "Artist" = "artist",
          "Other" = "other"
        )
      ),
      actionButton("download", "Download")
    ),
    mainPanel(
      uiOutput("message")
    )
  )
)

server <- function(input, output, session) {
  observeEvent(input$download, {
    # Validate email
    if (!artauth::is_valid_email(input$email)) {
      showNotification("Invalid email", type = "error")
      return()
    }

    # Log download
    download_id <- artauth::log_whitepaper_download(
      email = input$email,
      user_type = input$user_type,
      ip_address = session$request$REMOTE_ADDR,
      user_agent = session$request$HTTP_USER_AGENT
    )

    # Provide download link
    output$message <- renderUI({
      tagList(
        h4("Thank you!"),
        p("Your download will begin shortly."),
        downloadButton("pdf", "Download Whitepaper")
      )
    })
  })

  output$pdf <- downloadHandler(
    filename = "artalytics-whitepaper.pdf",
    content = function(file) {
      file.copy("path/to/whitepaper.pdf", file)
    }
  )
}

shinyApp(ui, server)

Batch Operations

Process Multiple Applications

# Use shared connection for efficiency
cn <- artcore::dbc("artsite")

tryCatch({
  # Get pending applications
  pending <- get_pending_waitlist(status = "pending", cn = cn)

  # Invite approved artists
  for (i in seq_len(nrow(pending))) {
    entry <- pending[i, ]

    # Your approval logic here
    if (should_approve(entry)) {
      update_waitlist_status(
        entry$id,
        status = "invited",
        cn = cn
      )
    }
  }
}, finally = {
  artcore::dbd(cn)
})

Common Patterns

Duplicate Email Check

# create_waitlist_entry handles duplicates automatically
waitlist_id <- create_waitlist_entry(
  email = "existing@example.com",
  full_name = "Test User"
)
# Returns existing ID with warning if email exists

Status Transitions

# Linear workflow
update_waitlist_status(id, status = "pending")     # Initial
update_waitlist_status(id, status = "reviewing")   # Under review
update_waitlist_status(id, status = "invited")     # Approved
user_id <- convert_waitlist_to_user(id)            # Converted

# Or reject
update_waitlist_status(id, status = "rejected")

Download Analytics

# Get all investor leads this month
start <- as.Date("2024-12-01")
end <- Sys.Date()

stats <- get_whitepaper_stats(start, end)
investor_count <- stats$by_user_type$count[
  stats$by_user_type$user_type == "investor"
]

print(paste("Investor downloads this month:", investor_count))

Next Steps