api

package
v0.0.0-...-9131a41 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2017 License: MIT Imports: 22 Imported by: 0

README

Botbox API

This service is responsible for the REST API that all botbox services can use to communicate with the database.

Usage

Ensure the following environment variables are defined on your host and the database service is running:

POSTGRES_DB_USER=botbox
POSTGRES_DB_NAME=botbox
POSTGRES_DB_PASSWORD=???
POSTGRES_DB_HOST=???

SMTP_IDENTITY=
SMTP_USERNAME=???
SMTP_PASSWORD=???
SMTP_HOST=???
SMTP_PORT=25

BOTBOX_DOMAIN_NAME=example.com

BOTBOX_RECAPTCHA_SECRET=???

$ cd server/

$ ./build.sh && ./run.sh

This will start up a docker container running a HTTP server listening on port 8081.

Making Requests

Requests to the API which require authentication must have the following HTTP headers set:

X-Request-ID: The session token given by the server when signing in with /session/auth

Date: The date the session was given in RFC 7231 format.

Authentication: The authentication header must be of the form "HMAC256 " where is created by hashing the concatenation of: date (the same as the header) + session token + request body using HMAC with the session token.

Documentation

Index

Constants

View Source
const AuthorizationHeader = "Authorization"
View Source
const AuthorizationPrefix = "Bearer"
View Source
const EmailSender = "mailbot"

EmailSender is the name that email is sent as.

View Source
const EmailSenderName = "Botbox"

EmailSenderName is appears in the "From" field in an email client.

View Source
const (
	MaxNameLen = 20
)
View Source
const MinPasswordLen = 6
View Source
const NotificationTypeVerify = "verify"

NotificationTypeVerify is type of notification for email verification.

View Source
const RecaptchaUrl = "https://www.google.com/recaptcha/api/siteverify"
View Source
const SaltLength = 4
View Source
const SecretLength = 32

Variables

View Source
var EmailDomainToken = []byte("{{domain}}")

EmailDomainToken is a string that gets replaced with the site domain in an HTML template (e.g. 'example.com').

View Source
var EmailNameToken = []byte("{{name}}")

EmailNameToken is a string that gets replaced with a user's name in an HTML email template.

View Source
var EmailSecretToken = []byte("{{secret}}")

EmailSecretToken is a string inside HTML templates that gets replaced with a secret token passed into the emailer interface.

View Source
var ErrBotDetected = &HttpError{"You are a bot.", 400}

ErrBotDetected is returned when a user fails the captcha test.

View Source
var ErrEmailInUse = &HttpError{"That email is already in use!", 400}

ErrEmailInUse is returned when an email is already being used.

View Source
var ErrEmailNotFound = &HttpError{"That email does not exist.", 404}

ErrEmailNotFound is returned when an email is not found in the database.

View Source
var ErrInvalidJson = &HttpError{"Invalid JSON.", 400}

ErrInvalidJson is returned when malformed JSON is received.

View Source
var ErrInvalidPassword = &HttpError{"The password you entered is incorrect.", 400}

ErrInvalidPassword is returned when a password was entered incorrectly.

View Source
var ErrInvalidSecret = &HttpError{"Invalid secret.", 400}

ErrInvalidSecret is returned when a bad secret is received.

View Source
var ErrLoginIncorrect = &HttpError{"Email or password was incorrect.", 400}

ErrLoginIncorrect is returned when a user provides a bad email/password combo.

View Source
var ErrMissingEmail = &HttpError{"Missing email.", 400}

ErrMissingEmail is returned when an input for email is empty.

View Source
var ErrMissingName = &HttpError{"Missing name.", 400}

ErrMissingName is returned when an input for name is empty.

View Source
var ErrMissingNotifications = &HttpError{"No notifications received.", 400}

ErrMissingNotifications is returned when updating no notifications

View Source
var ErrMissingParameter = &HttpError{"Missing parameter.", 400}

ErrMissingParameter is returned when a parameter is missing.

View Source
var ErrMissingPassword = &HttpError{"Missing password.", 400}

ErrMissingPassword is returned when an input for password is empty.

View Source
var ErrNameTooLong = &HttpError{"You name is too long.", 400}

ErrNameTooLong is returned when an input for name exceeds a valid length.

View Source
var ErrNotAnInteger = &HttpError{"Please provide an integer.", 400}

ErrNotAnInteger is returned when an integer is not received.

View Source
var ErrPasswordTooShort = &HttpError{"You password is too short.", 400}

ErrPasswordTooShort is returned when an input for a password is too short.

View Source
var ErrUnknown = &HttpError{"An unknown error occurred.", 500}

ErrUnknown is returned when an unknown server error is encountered. It should be logged for investigated, but not shown to the user.

View Source
var ErrUserNotFound = &HttpError{"Specified user was not found.", 404}

ErrUserNotFound is returned when a user is not found in the database.

Global password hasher using cryptographically secure random number generator

Global secret generator using cryptographically secure random number generator

Functions

func ParseAuthSecret

func ParseAuthSecret(header http.Header) string

Types

type App

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

func NewApp

func NewApp(db *sqlx.DB, recaptcha RecaptchaModel, emailer EmailerModel) *App

Build an app and return it.

func (*App) Attach

func (a *App) Attach(e *Endpoint)

Attach an endpoint to the router. Attaches the app to the context of the request.

func (*App) ServeHTTP

func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

Implements the http.Handler interface

type EmailGetModel

type EmailGetModel struct {
	Email string `json:'email'`
}

type EmailSelectProcessors

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

func (*EmailSelectProcessors) ValidateEmail

func (e *EmailSelectProcessors) ValidateEmail(i interface{}) (interface{}, *HttpError)

type EmailVerifyInsertProcessors

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

func (*EmailVerifyInsertProcessors) Begin

func (e *EmailVerifyInsertProcessors) Begin(i interface{}) (interface{}, *HttpError)

func (*EmailVerifyInsertProcessors) Commit

func (e *EmailVerifyInsertProcessors) Commit(i interface{}) (interface{}, *HttpError)

func (*EmailVerifyInsertProcessors) InsertNotification

func (e *EmailVerifyInsertProcessors) InsertNotification(i interface{}) (interface{}, *HttpError)

func (*EmailVerifyInsertProcessors) InsertVerification

func (e *EmailVerifyInsertProcessors) InsertVerification(i interface{}) (interface{}, *HttpError)

func (*EmailVerifyInsertProcessors) SendVerification

func (e *EmailVerifyInsertProcessors) SendVerification(i interface{}) (interface{}, *HttpError)

func (*EmailVerifyInsertProcessors) ValidateEmail

func (e *EmailVerifyInsertProcessors) ValidateEmail(i interface{}) (interface{}, *HttpError)

type EmailVerifyPostModel

type EmailVerifyPostModel struct {
	Email string `json:"email"`
}

type EmailVerifyPutModel

type EmailVerifyPutModel struct {
	Secret string `json:"secret"`
}

type EmailVerifyUpdateProcessors

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

func (*EmailVerifyUpdateProcessors) Begin

func (e *EmailVerifyUpdateProcessors) Begin(i interface{}) (interface{}, *HttpError)

func (*EmailVerifyUpdateProcessors) Commit

func (e *EmailVerifyUpdateProcessors) Commit(i interface{}) (interface{}, *HttpError)

func (*EmailVerifyUpdateProcessors) UpdateSecret

func (e *EmailVerifyUpdateProcessors) UpdateSecret(i interface{}) (interface{}, *HttpError)

func (*EmailVerifyUpdateProcessors) UpdateUser

func (e *EmailVerifyUpdateProcessors) UpdateUser(i interface{}) (interface{}, *HttpError)

func (*EmailVerifyUpdateProcessors) ValidateSecret

func (e *EmailVerifyUpdateProcessors) ValidateSecret(i interface{}) (interface{}, *HttpError)

type Emailer

type Emailer struct {
	Auth smtp.Auth

	// The SMTP server to use (with port)
	Server string

	// The service's domain name. E.g., 'example.com'
	Domain string

	// EmailVerificationTemplate may contain the following substrings:
	// '{{secret}}' -- replaced with the verification secret
	// '{{name}}' -- replaced with the user's name
	// '{{domain}}' -- replaced with the domain name
	EmailVerificationTemplate []byte

	// PasswordRecoveryTemplate may contain the following substrings:
	// '{{secret}}' -- replaced with the verification secret
	// '{{name}}' -- replaced with the user's name
	// '{{domain}}' -- replaced with the domain name
	PasswordRecoveryTemplate []byte
}

Emailer is a global implementation of EmailerModel which sends emails via SMTP.

func (*Emailer) BuildEmailVerification

func (e *Emailer) BuildEmailVerification(email string, name, secret []byte) []byte

BuildEmailVerification builds an email verification body to be send via SMTP to a user. It replaces {{name}} and {{secret}} in the HTML body with the user name and email verification secret.

func (*Emailer) BuildPasswordRecovery

func (e *Emailer) BuildPasswordRecovery(email string, name, secret []byte) []byte

BuildPasswordRecovery builds an email for recovering a password from the HTML template in the Emailer struct by replacing {{name}} and {{secret}} in the template with the user's name and password recovery secret.

func (*Emailer) SendEmail

func (e *Emailer) SendEmail(server, from, to string, auth smtp.Auth, msg []byte) error

SendEmail is a helper function for sending email with the given authentication method in the Emailer struct.

func (*Emailer) SendEmailVerification

func (e *Emailer) SendEmailVerification(email string, name, secret []byte) error

SendEmailVerification sends a verification email to the given user, filling in {{name}} and {{secret}} in the HTML template from the Emailer struct.

func (*Emailer) SendPasswordRecovery

func (e *Emailer) SendPasswordRecovery(email string, name, secret []byte) error

SendPasswordRecovery sends a password recovery email to the given email address, replacing {{name}} and {{secret}} in the HTML template from the Emailer struct.

type EmailerModel

type EmailerModel interface {
	// Send an email with a secret key to verify that the email exists and is
	// valid.
	SendEmailVerification(email string, name, secret []byte) error
	// Send a password recovery email to reset an account's password.
	SendPasswordRecovery(email string, name, secret []byte) error
}

EmailerModel is a generic interface for an emailer that sends emails to clients. Can be mocked for testing.

type Endpoint

type Endpoint struct {
	Path    string
	Methods []string
	// The handler is the function that turns the HTTP request into a struct or
	// other data type to be passed to the processors.
	Handler Handler
	// Processors are executed in sequence, passing the output of the one into
	// the input of the next one, starting with the output returned from the
	// handler. Processors can validate input, make database calls, etc.
	Processors []Processor
	// The writer takes the output of the last processor and turns it into a byte
	// array to return to the client.
	Writer Writer
}

An endpoint creates a handler for the given path with the given methods.

func NewEmailGetEndpoint

func NewEmailGetEndpoint(a *App) *Endpoint

@Title Get email @Description Check in an email is in use. @Accept json @Param email path string true "User email" @Success 200 plain @Failure 404 plain @Failure 500 plain @Resource /email @Router /email/{email} [get]

func NewEmailVerifyPostEndpoint

func NewEmailVerifyPostEndpoint(a *App) *Endpoint

@Title Send Email verification @Description send a verification email for a user @Accept json @Param Authorization header string true "Secret session token" @Param email query string true "User email" @Success 200 plain @Failure 400 plain @Failure 500 plain @Resource /email @Router /email/verify [post]

func NewEmailVerifyPutEndpoint

func NewEmailVerifyPutEndpoint(a *App) *Endpoint

@Title Verify Email @Description Validate a user's email verification secret @Accept json @Param secret query string true "Verification secret" @Success 200 plain @Failure 400 plain @Failure 500 plain @Resource /email @Router /email/verify [put]

func NewNotificationsGetEndpoint

func NewNotificationsGetEndpoint(a *App) *Endpoint

NewNotificationsGetEndpoint creates a new endpoint for getting the list of notifications for an authenticated user.

func NewNotificationsPutEndpoint

func NewNotificationsPutEndpoint(a *App) *Endpoint

NewNotificationsPutEndpoint creates a new endpoint for updating notifications for an authenticated user.

func NewPasswordPutEndpoint

func NewPasswordPutEndpoint(a *App) *Endpoint

@Title Change Password @Description Change the password of a logged-in user. @Accept json @Param Authorization header string true "Secret session token" @Param old query string true "Old password" @Param new query string true "New password" @Success 200 plain @Failure 400 plain @Failure 500 plain @Resource /password @Router /password [put]

func NewPasswordRecoverPostEndpoint

func NewPasswordRecoverPostEndpoint(a *App) *Endpoint

@Title Send Password Recovery @Description send a password recovery email for a user @Accept json @Param email query string true "User email" @Success 200 plain @Failure 400 plain @Failure 404 plain @Failure 500 plain @Resource /password @Router /password/recover [post]

func NewPasswordRecoverPutEndpoint

func NewPasswordRecoverPutEndpoint(a *App) *Endpoint

@Title Reset Password @Description Validate a user's email verification secret @Accept json @Param secret query string true "Recovery secret" @Param password query string true "New password" @Success 200 plain @Failure 400 plain @Failure 500 plain @Resource /password @Router /password/recover [put]

func NewSessionPostEndpoint

func NewSessionPostEndpoint(a *App) *Endpoint

@Title Create session token @Description create a session token for authenticating user API calls @Accept json @Param email query string true "User email" @Param password query string true "User password" @Success 200 plain SessionPostResponse "The session token for authenticating" @Failure 400 plain @Failure 500 plain @Resource /session @Router /session [post]

func NewSessionPutEndpoint

func NewSessionPutEndpoint(a *App) *Endpoint

@Title Renew session token @Description renew a session token for authenticating user API calls @Accept json @Param secret query string true "Secret session token" @Success 200 plain string "The new session token for authenticating" @Failure 400 plain @Failure 500 plain @Resource /session @Router /session [put]

func NewUserIdGetEndpoint

func NewUserIdGetEndpoint(a *App) *Endpoint

NewUserIdGetEndpoint creates a new endpoint for getting users by id.

func NewUserPostEndpoint

func NewUserPostEndpoint(a *App) *Endpoint

@Title insertUserWithPassword @Description register a user with a password @Accept json @Param name query string true "User display name" @Param password query string true "User password" @Param email query string true "User email" @Param captcha query string true "User reCaptcha response" @Success 200 plain @Failure 400 plain @Failure 500 plain @Resource /user @Router /user [post]

func (*Endpoint) Handle

func (e *Endpoint) Handle(w http.ResponseWriter, r *http.Request)

Satisfies the http.Handler type to be used as a handler function for an HTTP server.

type Handler

type Handler func(*http.Request) (interface{}, *HttpError)

type HttpError

type HttpError struct {
	Message string
	Status  int
}

HttpError is returned to a user if something goes wrong.

func ValidatePassword

func ValidatePassword(password string) *HttpError

Make sure a password is secure enough

func (*HttpError) Error

func (e *HttpError) Error() string

Error returns the error message of the HttpError.

func (*HttpError) StatusCode

func (e *HttpError) StatusCode() int

StatusCode returns the HTTP status code of the error.

type JsonHandler

type JsonHandler struct {
	// The target interface to fit JSON into. Pass in a factory function
	// which creates a new empty struct pointer to fill with values.
	Target func() interface{}
}

A basic handler that will stuff some Json into an interface.

func (*JsonHandler) Handle

func (h *JsonHandler) Handle(r *http.Request) (interface{}, *HttpError)

type JsonHandlerWithAuth

type JsonHandlerWithAuth struct {
	Target      func() interface{}
	User        int
	Permissions PermissionSet
	// contains filtered or unexported fields
}

A handler that also authenticates the user from the HTTP headers.

func (*JsonHandlerWithAuth) HandleWithId

func (h *JsonHandlerWithAuth) HandleWithId(r *http.Request) (interface{}, *HttpError)

Extract the user Id and insert into the User property

func (*JsonHandlerWithAuth) HandleWithPermissions

func (h *JsonHandlerWithAuth) HandleWithPermissions(r *http.Request) (interface{}, *HttpError)

Extract the user id and permissions

type NotificationModel

type NotificationModel struct {
	ID         int                 `json:"id" db:"id"`
	Issued     time.Time           `json:"issued" db:"issued"`
	Read       *NullTime           `json:"read" db:"read"`
	Dismissed  *NullTime           `json:"dismissed" db:"dismissed"`
	Type       string              `json:"type" db:"type"`
	Parameters *types.NullJSONText `json:"parameters" db:"parameters"`
}

NotificationModel holds information about a notification from the database.

type NotificationsGetModel

type NotificationsGetModel struct {
}

NotificationsGetModel stores information from the API request.

type NotificationsPutModel

type NotificationsPutModel struct {
	Notifications []int `json:"notifications"`
	Read          bool  `json:"read"`
	Dismissed     bool  `json:"dismissed"`
}

NotificationsPutModel stores information from the API request.

type NotificationsSelectProcessors

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

NotificationsSelectProcessors are a set of processors for processing the Get Notifications endpoint.

func (*NotificationsSelectProcessors) GetNotifications

func (e *NotificationsSelectProcessors) GetNotifications(i interface{}) (interface{}, *HttpError)

GetNotifications queries the database for notifications for the authenticated user.

func (*NotificationsSelectProcessors) WriteNotifications

func (e *NotificationsSelectProcessors) WriteNotifications(i interface{}) ([]byte, *HttpError)

WriteNotifications converts the list of notifications to JSON.

type NotificationsUpdateProcessors

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

NotificationsUpdateProcessors are a set of processors for processing the Get Notifications endpoint.

func (*NotificationsUpdateProcessors) UpdateNotifications

func (e *NotificationsUpdateProcessors) UpdateNotifications(i interface{}) (interface{}, *HttpError)

UpdateNotifications queries the database for notifications for the authenticated user.

type NullTime

type NullTime pq.NullTime

NullTime is a nullable database type that correctly serializes into JSON.

func (*NullTime) MarshalJSON

func (t *NullTime) MarshalJSON() ([]byte, error)

MarshalJSON converts a NullTime into null if it is null, or a marshalled time.Time if not null.

func (*NullTime) Scan

func (nt *NullTime) Scan(value interface{}) error

Scan implements the Scanner interface.

type Password

type Password struct {
	User   int    `db:"user"`
	Method string `db:"method"`
	Hash   string `db:"hash"`
	Salt   string `db:"salt"`
}

func (*Password) Matches

func (p *Password) Matches(other string) error

type PasswordHasher

type PasswordHasher struct {
	RandReader io.Reader
}

type PasswordPutModel

type PasswordPutModel struct {
	Old string `json:"old"`
	New string `json:"new"`
}

type PasswordRecoverInsertProcessers

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

func (*PasswordRecoverInsertProcessers) Begin

func (e *PasswordRecoverInsertProcessers) Begin(i interface{}) (interface{}, *HttpError)

func (*PasswordRecoverInsertProcessers) Commit

func (e *PasswordRecoverInsertProcessers) Commit(i interface{}) (interface{}, *HttpError)

func (*PasswordRecoverInsertProcessers) InsertRecovery

func (e *PasswordRecoverInsertProcessers) InsertRecovery(i interface{}) (interface{}, *HttpError)

func (*PasswordRecoverInsertProcessers) SendRecovery

func (e *PasswordRecoverInsertProcessers) SendRecovery(i interface{}) (interface{}, *HttpError)

func (*PasswordRecoverInsertProcessers) ValidateEmail

func (e *PasswordRecoverInsertProcessers) ValidateEmail(i interface{}) (interface{}, *HttpError)

type PasswordRecoverPostModel

type PasswordRecoverPostModel struct {
	Email string `json:"email"`
}

type PasswordRecoverPutModel

type PasswordRecoverPutModel struct {
	Secret   string `json:"secret"`
	Password string `json:"password"`
}

type PasswordRecoverUpdateProcessors

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

func (*PasswordRecoverUpdateProcessors) Begin

func (e *PasswordRecoverUpdateProcessors) Begin(i interface{}) (interface{}, *HttpError)

func (*PasswordRecoverUpdateProcessors) Commit

func (e *PasswordRecoverUpdateProcessors) Commit(i interface{}) (interface{}, *HttpError)

func (*PasswordRecoverUpdateProcessors) UpdatePassword

func (e *PasswordRecoverUpdateProcessors) UpdatePassword(i interface{}) (interface{}, *HttpError)

func (*PasswordRecoverUpdateProcessors) UpdateSecret

func (e *PasswordRecoverUpdateProcessors) UpdateSecret(i interface{}) (interface{}, *HttpError)

func (*PasswordRecoverUpdateProcessors) ValidatePassword

func (e *PasswordRecoverUpdateProcessors) ValidatePassword(i interface{}) (interface{}, *HttpError)

func (*PasswordRecoverUpdateProcessors) ValidateSecret

func (e *PasswordRecoverUpdateProcessors) ValidateSecret(i interface{}) (interface{}, *HttpError)

type PasswordUpdateProcessors

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

func (*PasswordUpdateProcessors) CheckPasswordMatch

func (e *PasswordUpdateProcessors) CheckPasswordMatch(i interface{}) (interface{}, *HttpError)

func (*PasswordUpdateProcessors) UpdatePassword

func (e *PasswordUpdateProcessors) UpdatePassword(i interface{}) (interface{}, *HttpError)

func (*PasswordUpdateProcessors) ValidatePassword

func (e *PasswordUpdateProcessors) ValidatePassword(i interface{}) (interface{}, *HttpError)

type PermissionSet

type PermissionSet []string

PermissionSet is a set of permissions that a user has.

func (PermissionSet) HasPermission

func (p PermissionSet) HasPermission(perm string) bool

HasPermission checks if a permission set contains the given permission.

type Processor

type Processor func(interface{}) (interface{}, *HttpError)

type Profile

type Profile struct {
	Id           int    `json:"-" `
	Bio          string `json:"bio" db:"bio"`
	Organization string `json:"organization" db:"organization"`
	Location     string `json:"location" db:"location"`
	Website      string `json:"website" db:"website"`
	Github       string `json:"github" db:"github"`
}

Profile is the public facing profile of a user.

type Recaptcha

type Recaptcha struct {
	RecaptchaUrl    string
	RecaptchaSecret string
}

func (*Recaptcha) Verify

func (m *Recaptcha) Verify(token string) (bool, error)

type RecaptchaModel

type RecaptchaModel interface {
	// Verify that the token sent from the user is valid with the app secret.
	Verify(token string) (bool, error)
}

type SecretGenerator

type SecretGenerator struct {
	RandReader io.Reader
}

func (*SecretGenerator) Generate

func (gen *SecretGenerator) Generate() (string, error)

Given a password, generate a salt and hash it and return the salt and hash and any error encountered.

type Session

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

A concrete implementation of SessionModel for a Postgres backend.

func (*Session) GetPermissions

func (s *Session) GetPermissions(secret string) (PermissionSet, error)

func (*Session) GetUserId

func (s *Session) GetUserId(secret string) (int, error)

type SessionInsertProcessors

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

SessionInsertProcessors contains data and actions about the session post process.

func (*SessionInsertProcessors) CreateSecret

func (e *SessionInsertProcessors) CreateSecret(i interface{}) (interface{}, *HttpError)

CreateSecret creates the session secret.

func (*SessionInsertProcessors) ValidateEmail

func (e *SessionInsertProcessors) ValidateEmail(i interface{}) (interface{}, *HttpError)

ValidateEmail validates the user email.

func (*SessionInsertProcessors) ValidatePassword

func (e *SessionInsertProcessors) ValidatePassword(i interface{}) (interface{}, *HttpError)

ValidatePassword validates the user's password.

func (*SessionInsertProcessors) Write

func (e *SessionInsertProcessors) Write(i interface{}) ([]byte, *HttpError)

type SessionModel

type SessionModel interface {
	GetUserId(string) (int, error)
	GetPermissions(string) (PermissionSet, error)
}

A generic interface for something that retrieves session data.

type SessionPostModel

type SessionPostModel struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

SessionPostModel is the JSON object that the user must provide.

type SessionPostResponse

type SessionPostResponse struct {
	User    int       `json:"user"`
	Secret  string    `json:"secret"`
	Expires time.Time `json:"expiration"`
}

SessionPostResponse is the JSON object that the endpoint returns.

type SessionPutModel

type SessionPutModel struct {
	Secret string `json:"secret"`
}

type SessionUpdateProcessors

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

func (*SessionUpdateProcessors) CreateSecret

func (e *SessionUpdateProcessors) CreateSecret(i interface{}) (interface{}, *HttpError)

func (*SessionUpdateProcessors) ValidateSecret

func (e *SessionUpdateProcessors) ValidateSecret(i interface{}) (interface{}, *HttpError)

func (*SessionUpdateProcessors) Write

func (e *SessionUpdateProcessors) Write(i interface{}) ([]byte, *HttpError)

type URLPathHandler

type URLPathHandler struct {
	// The target interface to fit URL parameters into. Pass in a factory function
	// which creates a new empty struct pointer to fill with values.
	Target func() interface{}
}

URLPathHandler takes URL parameters of the form /path/{var1}/{var2} extracted by a gorilla mux and converts them into JSON then unmarshals them into the target interface

func (*URLPathHandler) Handle

func (h *URLPathHandler) Handle(r *http.Request) (interface{}, *HttpError)

Handle takes the path and puts the URL parameters into the target interfaced given to the URLPathHandler struct.

type URLPathHandlerWithAuth

type URLPathHandlerWithAuth struct {
	Target      func() interface{}
	User        int
	Permissions PermissionSet
	// contains filtered or unexported fields
}

URLPathHandlerWithAuth takes URL parameters of the form /path/{var1}/{var2} extracted by a gorilla mux and converts them into JSON then unmarshals them into the target interface

func (*URLPathHandlerWithAuth) HandleWithId

func (h *URLPathHandlerWithAuth) HandleWithId(r *http.Request) (interface{}, *HttpError)

HandleWithId takes the path and puts the URL parameters into the target interfaced given to the URLPathHandler struct. It also gets the user id and puts it in the handler struct.

type User

type User struct {
	Id            int       `json:"id" db:"id"`
	Name          string    `json:"name" db:"name"`
	Email         string    `json:"-" db:"email"`
	Joined        time.Time `json:"joined" db:"joined"`
	PermissionSet string    `json:"permission_set" db:"permission_set"`

	Permissions PermissionSet `json:"permissions"`
	Profile     *Profile      `json:"profile"`
}

User is a struct containing information about a user.

func (*User) HasPermission

func (u *User) HasPermission(perm string) bool

HasPermission checks if a user has the given permission.

type UserIdGetProcessors

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

UserIdGetProcessors holds data about the processors handling the request.

func (*UserIdGetProcessors) GetPermissions

func (e *UserIdGetProcessors) GetPermissions(i interface{}) (interface{}, *HttpError)

GetPermissions queries the user permissions from the database.

func (*UserIdGetProcessors) GetUser

func (e *UserIdGetProcessors) GetUser(i interface{}) (interface{}, *HttpError)

GetUser gets the user from the database.

func (*UserIdGetProcessors) UserWriter

func (e *UserIdGetProcessors) UserWriter(i interface{}) ([]byte, *HttpError)

UserWriter returns the JSON output

type UserIdSelectModel

type UserIdSelectModel struct {
	Id string `json:'id'`
}

UserIdSelectModel holds the data from the user request.

type UserInsertProcessors

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

func (*UserInsertProcessors) Begin

func (e *UserInsertProcessors) Begin(i interface{}) (interface{}, *HttpError)

func (*UserInsertProcessors) Commit

func (e *UserInsertProcessors) Commit(i interface{}) (interface{}, *HttpError)

func (*UserInsertProcessors) InsertPassword

func (e *UserInsertProcessors) InsertPassword(i interface{}) (interface{}, *HttpError)

func (*UserInsertProcessors) InsertUser

func (e *UserInsertProcessors) InsertUser(i interface{}) (interface{}, *HttpError)

func (*UserInsertProcessors) ValidateCaptcha

func (e *UserInsertProcessors) ValidateCaptcha(i interface{}) (interface{}, *HttpError)

func (*UserInsertProcessors) ValidateEmail

func (e *UserInsertProcessors) ValidateEmail(i interface{}) (interface{}, *HttpError)

func (*UserInsertProcessors) ValidateName

func (e *UserInsertProcessors) ValidateName(i interface{}) (interface{}, *HttpError)

func (*UserInsertProcessors) ValidatePassword

func (e *UserInsertProcessors) ValidatePassword(i interface{}) (interface{}, *HttpError)

type UserPasswordPostModel

type UserPasswordPostModel struct {
	Name     string `json:'name'`
	Password string `json:'password'`
	Email    string `json:'email'`
	Captcha  string `json:'captcha'`
}

type Writer

type Writer func(interface{}) ([]byte, *HttpError)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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