ui

package
v0.0.0-...-acaa9d6 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2017 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// configuration
	SESSION_WORDS    = 6 // it's a magic number
	SESSION_DURATION = 30 * time.Minute
	MESSAGE_DURATION = 30 * 24 * time.Hour

	// Errors and alerts
	DISABLED        = "This email address and all of its public keys has been disabled"
	UNKNOWN         = "This email address does not have any public keys associated with it (you can <a href=\"/upload\">add one here</a>)"
	NO_KEYS         = "You need at least one public key associated with your email address (go <a href=\"/upload\">here to upload it</a>)"
	NO_EMAIL        = "You need to provide an email address"
	INVALID_EMAIL   = "That email address is not valid"
	INVALID_SESSION = "This session is no longer valid (go <a href=\"/session\">here to create a new one</a>)"
	INVALID_PK      = "We could not process your public key (please make sure it is in the correct format)"
	OTHER_ERROR     = "There was an internal problem"

	// site/domain specific
	CONTACT_SENDER = "noreply@teamwork.io"
	KEY_SOURCE     = "TeamWork.io"

	// user interface
	POSTS_PER_PAGE = 20

	// page titles
	TITLE_POSTS           = "Latest Posts"
	TITLE_CREATE_SESSION  = "New Session"
	TITLE_CONFIRM_SESSION = "Confirm Session"
	TITLE_ADD_POST        = "New Post"
	TITLE_ADD_KEY         = "New Public Key"
	TITLE_INDEX           = "Welcome to " + KEY_SOURCE
	TITLE_HELP            = "Help"
	TITLE_DONATE          = "Donate to " + KEY_SOURCE
)
View Source
const NO_SUCH_MESSAGE = "There is no such message among the list of available posts"

Variables

View Source
var (
	TEMPLATE_LIST = func(templatesFolder string, templateFiles []string) []string {
		t := make([]string, 0)
		for _, f := range templateFiles {
			t = append(t, path.Join(templatesFolder, f))
		}
		return t
	}

	// static pages
	UNSUPPORTED_TEMPLATE_FILE = "browser_not_supported.html"

	INDEX_TEMPLATE_FILES = []string{"index.html", "head.html", "navigation.html", "scripts.html"}
	INDEX_TEMPLATE       *template.Template

	HELP_TEMPLATE_FILES = []string{"help.html", "head.html", "navigation.html", "scripts.html"}
	HELP_TEMPLATE       *template.Template

	// dynamically-generated pages
	NEW_POST_TEMPLATE_FILES = []string{"new-post.html", "head.html", "modal.html", "alert.html", "navigation.html", "scripts.html"}
	NEW_POST_TEMPLATE       *template.Template

	ALL_POSTS_TEMPLATE_FILES = []string{"posts.html", "head.html", "alert.html", "navigation.html", "scripts.html"}
	ALL_POSTS_TEMPLATE       *template.Template

	CREATE_SESSION_TEMPLATE_FILES = []string{"create-session.html", "head.html", "alert.html", "navigation.html", "scripts.html"}
	CREATE_SESSION_TEMPLATE       *template.Template

	CONFIRM_SESSION_TEMPLATE_FILES = []string{"confirm-session.html", "head.html", "alert.html", "navigation.html", "scripts.html"}
	CONFIRM_SESSION_TEMPLATE       *template.Template

	NEW_KEY_TEMPLATE_FILES = []string{"new-key.html", "head.html", "alert.html", "navigation.html", "scripts.html"}
	NEW_KEY_TEMPLATE       *template.Template


	EMAIL_TEMPLATE_FILES = []string{"email.txt"}
	EMAIL_TEMPLATE       *template.Template

	HTML_EMAIL_TEMPLATE_FILES = []string{"email.html"}
	HTML_EMAIL_TEMPLATE       *template.Template

	TEMPLATES_INITIALIZED = false
)

Functions

func AddPublicKey

func AddPublicKey(person *database.PERSON, keyData, keySource, keyNickname string, pkInsert *sql.Stmt) error

Generate a new public key, and associate it with this person

func ConfirmSession

func ConfirmSession(w http.ResponseWriter, r *http.Request, db database.DBConnection, opts ...interface{})

func ConfirmSessionCode

func ConfirmSessionCode(code string, cleanup, lookup *sql.Stmt) (*database.SESSION, error)

Wipe any expired sessions, and then confirm this code, returning the session object

func CreateNewSession

func CreateNewSession(person *database.PERSON, keys []*database.PUBLIC_KEY, sessionInsert *sql.Stmt) error

Create a new session for this Person and email them the corresponding session code to decrypt

func CreateSession

func CreateSession(w http.ResponseWriter, r *http.Request, db database.DBConnection, opts ...interface{})

func DisplayPosts

func DisplayPosts(w http.ResponseWriter, r *http.Request, db database.DBConnection, opts ...interface{})

func DownloadMessage

func DownloadMessage(w http.ResponseWriter, r *http.Request, db database.DBConnection, opts ...interface{})

Lookup and stream the given message back to the client

func GenerateStaticFiles

func GenerateStaticFiles(templatesFolder string, outputFolder string)

func InitializeTemplates

func InitializeTemplates(folder string)

InitializeTemplates confirms the given folder string leads to the html template files, otherwise templates.Must() will complain

func MakeHTMLHandler

func MakeHTMLHandler(fn func(http.ResponseWriter, *http.Request, database.DBConnection, ...interface{}), db database.DBConnection, opts ...interface{}) http.HandlerFunc

Respond to requests using HTML templates and the standard Content-Type (i.e., "text/html")

func PostMessage

func PostMessage(w http.ResponseWriter, r *http.Request, db database.DBConnection, opts ...interface{})

func ProcessDonation

func ProcessDonation(w http.ResponseWriter, r *http.Request, db database.DBConnection, opts ...interface{})

func Redirect

func Redirect(target string) http.HandlerFunc

Use this to redirect one request to another target (string)

func StaticFolder

func StaticFolder(folder string, templatesFolder string) http.Handler

handlers for static resources

func UnsupportedBrowserHandler

func UnsupportedBrowserHandler(templatesFolder string) http.HandlerFunc

Show the static template for unsupported browsers

func UploadKey

func UploadKey(w http.ResponseWriter, r *http.Request, db database.DBConnection, opts ...interface{})

Types

type Alert

type Alert struct {
	AlertType string
	Icon      string
	Message   template.HTML
}

func (*Alert) AsError

func (a *Alert) AsError(msg string)

A helper function to set an error Alert with a custom message

func (*Alert) Update

func (a *Alert) Update(typ string, icon string, msg string)

A helper function to update multiple Alert properties

type ConfirmSessionPage

type ConfirmSessionPage struct {
	Title   string
	Alert   *Alert
	Session *database.SESSION
	Person  *database.PERSON
}

type CreateSessionPage

type CreateSessionPage struct {
	Title   string
	Alert   *Alert
	Session *database.SESSION
	Person  *database.PERSON
}

type DisplayPostsPage

type DisplayPostsPage struct {
	Title   string
	Alert   *Alert
	Session *database.SESSION
	Person  *database.PERSON
	Posts   []*database.MESSAGE_DIGEST
}

type DonationPage

type DonationPage struct {
	Title    string
	Alert    *Alert
	Session  *database.SESSION
	Person   *database.PERSON
	StripePK string
}

type EmailMessage

type EmailMessage struct {
	Subject string
	Heading string
	Message []string
}

type NewKeyPage

type NewKeyPage struct {
	Title   string
	Alert   *Alert
	Session *database.SESSION
	Person  *database.PERSON
}

type NewPostPage

type NewPostPage struct {
	Title      string
	Alert      *Alert
	Session    *database.SESSION
	Person     *database.PERSON
	Keys       []*database.PUBLIC_KEY
	Recipients []*Recipient
}

type Recipient

type Recipient struct {
	Person *database.PERSON
	Keys   []*database.PUBLIC_KEY
}

type StaticPage

type StaticPage struct {
	Title   string
	Session *database.SESSION
	Person  *database.PERSON
}

static file rendering

Jump to

Keyboard shortcuts

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