Documentation
¶
Index ¶
- Constants
- Variables
- func ParseAuthSecret(header http.Header) string
- type App
- type EmailGetModel
- type EmailSelectProcessors
- type EmailVerifyInsertProcessors
- func (e *EmailVerifyInsertProcessors) Begin(i interface{}) (interface{}, *HttpError)
- func (e *EmailVerifyInsertProcessors) Commit(i interface{}) (interface{}, *HttpError)
- func (e *EmailVerifyInsertProcessors) InsertNotification(i interface{}) (interface{}, *HttpError)
- func (e *EmailVerifyInsertProcessors) InsertVerification(i interface{}) (interface{}, *HttpError)
- func (e *EmailVerifyInsertProcessors) SendVerification(i interface{}) (interface{}, *HttpError)
- func (e *EmailVerifyInsertProcessors) ValidateEmail(i interface{}) (interface{}, *HttpError)
- type EmailVerifyPostModel
- type EmailVerifyPutModel
- type EmailVerifyUpdateProcessors
- func (e *EmailVerifyUpdateProcessors) Begin(i interface{}) (interface{}, *HttpError)
- func (e *EmailVerifyUpdateProcessors) Commit(i interface{}) (interface{}, *HttpError)
- func (e *EmailVerifyUpdateProcessors) UpdateSecret(i interface{}) (interface{}, *HttpError)
- func (e *EmailVerifyUpdateProcessors) UpdateUser(i interface{}) (interface{}, *HttpError)
- func (e *EmailVerifyUpdateProcessors) ValidateSecret(i interface{}) (interface{}, *HttpError)
- type Emailer
- func (e *Emailer) BuildEmailVerification(email string, name, secret []byte) []byte
- func (e *Emailer) BuildPasswordRecovery(email string, name, secret []byte) []byte
- func (e *Emailer) SendEmail(server, from, to string, auth smtp.Auth, msg []byte) error
- func (e *Emailer) SendEmailVerification(email string, name, secret []byte) error
- func (e *Emailer) SendPasswordRecovery(email string, name, secret []byte) error
- type EmailerModel
- type Endpoint
- func NewEmailGetEndpoint(a *App) *Endpoint
- func NewEmailVerifyPostEndpoint(a *App) *Endpoint
- func NewEmailVerifyPutEndpoint(a *App) *Endpoint
- func NewNotificationsGetEndpoint(a *App) *Endpoint
- func NewNotificationsPutEndpoint(a *App) *Endpoint
- func NewPasswordPutEndpoint(a *App) *Endpoint
- func NewPasswordRecoverPostEndpoint(a *App) *Endpoint
- func NewPasswordRecoverPutEndpoint(a *App) *Endpoint
- func NewSessionPostEndpoint(a *App) *Endpoint
- func NewSessionPutEndpoint(a *App) *Endpoint
- func NewUserIdGetEndpoint(a *App) *Endpoint
- func NewUserPostEndpoint(a *App) *Endpoint
- type Handler
- type HttpError
- type JsonHandler
- type JsonHandlerWithAuth
- type NotificationModel
- type NotificationsGetModel
- type NotificationsPutModel
- type NotificationsSelectProcessors
- type NotificationsUpdateProcessors
- type NullTime
- type Password
- type PasswordHasher
- type PasswordPutModel
- type PasswordRecoverInsertProcessers
- func (e *PasswordRecoverInsertProcessers) Begin(i interface{}) (interface{}, *HttpError)
- func (e *PasswordRecoverInsertProcessers) Commit(i interface{}) (interface{}, *HttpError)
- func (e *PasswordRecoverInsertProcessers) InsertRecovery(i interface{}) (interface{}, *HttpError)
- func (e *PasswordRecoverInsertProcessers) SendRecovery(i interface{}) (interface{}, *HttpError)
- func (e *PasswordRecoverInsertProcessers) ValidateEmail(i interface{}) (interface{}, *HttpError)
- type PasswordRecoverPostModel
- type PasswordRecoverPutModel
- type PasswordRecoverUpdateProcessors
- func (e *PasswordRecoverUpdateProcessors) Begin(i interface{}) (interface{}, *HttpError)
- func (e *PasswordRecoverUpdateProcessors) Commit(i interface{}) (interface{}, *HttpError)
- func (e *PasswordRecoverUpdateProcessors) UpdatePassword(i interface{}) (interface{}, *HttpError)
- func (e *PasswordRecoverUpdateProcessors) UpdateSecret(i interface{}) (interface{}, *HttpError)
- func (e *PasswordRecoverUpdateProcessors) ValidatePassword(i interface{}) (interface{}, *HttpError)
- func (e *PasswordRecoverUpdateProcessors) ValidateSecret(i interface{}) (interface{}, *HttpError)
- type PasswordUpdateProcessors
- type PermissionSet
- type Processor
- type Profile
- type Recaptcha
- type RecaptchaModel
- type SecretGenerator
- type Session
- type SessionInsertProcessors
- func (e *SessionInsertProcessors) CreateSecret(i interface{}) (interface{}, *HttpError)
- func (e *SessionInsertProcessors) ValidateEmail(i interface{}) (interface{}, *HttpError)
- func (e *SessionInsertProcessors) ValidatePassword(i interface{}) (interface{}, *HttpError)
- func (e *SessionInsertProcessors) Write(i interface{}) ([]byte, *HttpError)
- type SessionModel
- type SessionPostModel
- type SessionPostResponse
- type SessionPutModel
- type SessionUpdateProcessors
- type URLPathHandler
- type URLPathHandlerWithAuth
- type User
- type UserIdGetProcessors
- type UserIdSelectModel
- type UserInsertProcessors
- func (e *UserInsertProcessors) Begin(i interface{}) (interface{}, *HttpError)
- func (e *UserInsertProcessors) Commit(i interface{}) (interface{}, *HttpError)
- func (e *UserInsertProcessors) InsertPassword(i interface{}) (interface{}, *HttpError)
- func (e *UserInsertProcessors) InsertUser(i interface{}) (interface{}, *HttpError)
- func (e *UserInsertProcessors) ValidateCaptcha(i interface{}) (interface{}, *HttpError)
- func (e *UserInsertProcessors) ValidateEmail(i interface{}) (interface{}, *HttpError)
- func (e *UserInsertProcessors) ValidateName(i interface{}) (interface{}, *HttpError)
- func (e *UserInsertProcessors) ValidatePassword(i interface{}) (interface{}, *HttpError)
- type UserPasswordPostModel
- type Writer
Constants ¶
const AuthorizationHeader = "Authorization"
const AuthorizationPrefix = "Bearer"
const EmailSender = "mailbot"
EmailSender is the name that email is sent as.
const EmailSenderName = "Botbox"
EmailSenderName is appears in the "From" field in an email client.
const (
MaxNameLen = 20
)
const MinPasswordLen = 6
const NotificationTypeVerify = "verify"
NotificationTypeVerify is type of notification for email verification.
const RecaptchaUrl = "https://www.google.com/recaptcha/api/siteverify"
const SaltLength = 4
const SecretLength = 32
Variables ¶
var EmailDomainToken = []byte("{{domain}}")
EmailDomainToken is a string that gets replaced with the site domain in an HTML template (e.g. 'example.com').
var EmailNameToken = []byte("{{name}}")
EmailNameToken is a string that gets replaced with a user's name in an HTML email template.
var EmailSecretToken = []byte("{{secret}}")
EmailSecretToken is a string inside HTML templates that gets replaced with a secret token passed into the emailer interface.
var ErrBotDetected = &HttpError{"You are a bot.", 400}
ErrBotDetected is returned when a user fails the captcha test.
var ErrEmailInUse = &HttpError{"That email is already in use!", 400}
ErrEmailInUse is returned when an email is already being used.
var ErrEmailNotFound = &HttpError{"That email does not exist.", 404}
ErrEmailNotFound is returned when an email is not found in the database.
var ErrInvalidJson = &HttpError{"Invalid JSON.", 400}
ErrInvalidJson is returned when malformed JSON is received.
var ErrInvalidPassword = &HttpError{"The password you entered is incorrect.", 400}
ErrInvalidPassword is returned when a password was entered incorrectly.
var ErrInvalidSecret = &HttpError{"Invalid secret.", 400}
ErrInvalidSecret is returned when a bad secret is received.
var ErrLoginIncorrect = &HttpError{"Email or password was incorrect.", 400}
ErrLoginIncorrect is returned when a user provides a bad email/password combo.
var ErrMissingEmail = &HttpError{"Missing email.", 400}
ErrMissingEmail is returned when an input for email is empty.
var ErrMissingName = &HttpError{"Missing name.", 400}
ErrMissingName is returned when an input for name is empty.
var ErrMissingNotifications = &HttpError{"No notifications received.", 400}
ErrMissingNotifications is returned when updating no notifications
var ErrMissingParameter = &HttpError{"Missing parameter.", 400}
ErrMissingParameter is returned when a parameter is missing.
var ErrMissingPassword = &HttpError{"Missing password.", 400}
ErrMissingPassword is returned when an input for password is empty.
var ErrNameTooLong = &HttpError{"You name is too long.", 400}
ErrNameTooLong is returned when an input for name exceeds a valid length.
var ErrNotAnInteger = &HttpError{"Please provide an integer.", 400}
ErrNotAnInteger is returned when an integer is not received.
var ErrPasswordTooShort = &HttpError{"You password is too short.", 400}
ErrPasswordTooShort is returned when an input for a password is too short.
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.
var ErrUserNotFound = &HttpError{"Specified user was not found.", 404}
ErrUserNotFound is returned when a user is not found in the database.
var Hasher = &PasswordHasher{rand.Reader}
Global password hasher using cryptographically secure random number generator
var Secret = &SecretGenerator{rand.Reader}
Global secret generator using cryptographically secure random number generator
Functions ¶
func ParseAuthSecret ¶
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.
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 ¶
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 ¶
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 ¶
SendEmail is a helper function for sending email with the given authentication method in the Emailer struct.
func (*Emailer) SendEmailVerification ¶
SendEmailVerification sends a verification email to the given user, filling in {{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 ¶
@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 ¶
@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 ¶
@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 ¶
NewNotificationsGetEndpoint creates a new endpoint for getting the list of notifications for an authenticated user.
func NewNotificationsPutEndpoint ¶
NewNotificationsPutEndpoint creates a new endpoint for updating notifications for an authenticated user.
func NewPasswordPutEndpoint ¶
@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 ¶
@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 ¶
@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 ¶
@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 ¶
@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 ¶
NewUserIdGetEndpoint creates a new endpoint for getting users by id.
func NewUserPostEndpoint ¶
@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]
type HttpError ¶
HttpError is returned to a user if something goes wrong.
func ValidatePassword ¶
Make sure a password is secure enough
func (*HttpError) StatusCode ¶
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.
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 ¶
NullTime is a nullable database type that correctly serializes into JSON.
func (*NullTime) MarshalJSON ¶
MarshalJSON converts a NullTime into null if it is null, or a marshalled time.Time if not null.
type Password ¶
type PasswordHasher ¶
type PasswordPutModel ¶
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 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 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 RecaptchaModel ¶
type SecretGenerator ¶
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)
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 ¶
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
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 ¶
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 ¶
Source Files
¶
- app.go
- endpoint_get_email.go
- endpoint_get_notifications.go
- endpoint_get_user.go
- endpoint_post_email_verify.go
- endpoint_post_password_recover.go
- endpoint_post_session.go
- endpoint_post_user.go
- endpoint_put_email_verify.go
- endpoint_put_notifications.go
- endpoint_put_password.go
- endpoint_put_password_recover.go
- endpoint_put_session.go
- model_email.go
- model_errors.go
- model_notifications.go
- model_password.go
- model_recaptcha.go
- model_secret.go
- model_session.go
- model_user.go
- util_handlers.go
- util_parse_auth.go
- util_types.go