Documentation ¶
Index ¶
- Constants
- Variables
- func ComparePassword(hash string, password string) bool
- func CreateTokenTypeResetPasswordExtra(email string) (string, error)
- func GetMillis() int64
- func HashPassword(password string) string
- func IsLower(s string) bool
- func IsValidEmail(email string) bool
- func IsValidPassword(password string) bool
- func NewID() string
- func NewRandomNumber(length int) string
- func NewRandomString(length int) string
- type APIError
- type Client
- func (c *Client) BuildURL(urlPath string, args ...interface{}) string
- func (c *Client) ForgotPassword(request *ForgotPasswordRequest) error
- func (c *Client) GetMe() (*User, error)
- func (c *Client) Headers() map[string]string
- func (c *Client) Login(request *LoginRequest) (*User, error)
- func (c *Client) Logout() error
- func (c *Client) ResetPassword(request *ResetPasswordRequest) error
- func (c *Client) SignUp(request *SignUpRequest) (*SignUpResponse, error)
- func (c *Client) UpdateMe(user *User) (*User, error)
- func (c *Client) UpdatePassword(request *UpdatePasswordRequest) error
- func (c *Client) VerifyEmailComplete(request *VerifyEmailRequest) error
- func (c *Client) VerifyEmailStart() error
- type ForgotPasswordRequest
- type LoginRequest
- type OAuthState
- type ResetPasswordRequest
- type Role
- type Session
- type SignUpRequest
- type SignUpResponse
- type Token
- type TokenExtraEmail
- type UpdatePasswordRequest
- type User
- type UserAuthInfo
- type UserFacingError
- type UserRole
- type VerifyEmailRequest
Constants ¶
const ( UserRoleName = "user" AdminRoleName = "admin" )
const ( // SessionCookieToken is the cookie key for the authorization token. SessionCookieToken = "DASHBOARDAUTHTOKEN" // SessionCookieCSRF is the cookie key for the CSRF token. SessionCookieCSRF = "DASHBOARDCSRF" // SessionCookieUser is the cookie key for the logged in user. SessionCookieUser = "DASHBOARDUSERID" // SessionHeader is the header key for a session. SessionHeader = "Token" // SessionLengthMilliseconds is the session length in milliseconds. SessionLengthMilliseconds = 1000 * 60 * 60 * 24 * 15 // 15 days // HeaderRequestedWith is the HTTP header X-Requested-With. HeaderRequestedWith = "X-Requested-With" // HeaderRequestedWithXML is the HTTP header value XMLHttpRequest. HeaderRequestedWithXML = "XMLHttpRequest" // HeaderForwardedProto is the HTTP header X-Forwarded-Proto. HeaderForwardedProto = "X-Forwarded-Proto" // HeaderRequestID is the custom header to track request ID. HeaderRequestID = "X-Request-ID" // HeaderAuthorization is the HTTP header Authorization. HeaderAuthorization = "Authorization" // HeaderApiKey is the HTTP header containing API key. HeaderApiKey = "X-CTRL-Api-Key" // HeaderCSRFToken is the HTTP header for holding the CSRF token. HeaderCSRFToken = "X-CSRF-Token" // AuthorizationBearer is the bearer HTTP authorization type. AuthorizationBearer = "BEARER" )
const ( // TokenSize is the size of the random value of a token. TokenSize = 64 // TokenSizeDigits is the size of the smaller token used during signup. TokenSizeDigits = 6 // TokenTypeVerifyEmail is the token type used for user email verification. TokenTypeVerifyEmail = "verify_email" // TokenTypeResetPassword the token type used for resetting user passwords. TokenTypeResetPassword = "reset_password" // TokenDefaultExpiryTime is the default time for tokens to expire. TokenDefaultExpiryTime = 1000 * 60 * 60 * 24 // 24 hour )
const ( // UserStateActive means the user is fully active and no restrictions exist UserStateActive = "active" // UserStateLocked means the user should not be able to access the dashboard UserStateLocked = "locked" )
const DefaultHTTPTimeout = time.Minute
DefaultHTTPTimeout is the default timeout for HTTP requests made by Client
const (
// DefaultTokenTTL is the OAuth state expiry duration in milliseconds
DefaultTokenTTL = 10 * 60
)
const (
EventTypeSendAdminWelcomeEmail = "send-admin-welcome-email"
)
Variables ¶
var ( CurrentVersion string = versions[0] BuildNumber string BuildTime string BuildHash string )
Functions ¶
func ComparePassword ¶
ComparePassword compares the hash to the password.
func CreateTokenTypeResetPasswordExtra ¶
CreateTokenTypeResetPasswordExtra returns the correct extra values for a token of type TokenTypeResetPassword.
func GetMillis ¶
func GetMillis() int64
GetMillis is a convenience method to get milliseconds since epoch.
func HashPassword ¶
HashPassword generates a hash using the bcrypt.GenerateFromPassword
func IsValidEmail ¶
IsValidEmail will perform some minimal validations on whether the provided string is a valid email address.
func IsValidPassword ¶
IsValidPassword will perform some minimal validations on whether the provided password meets our requirements.
func NewID ¶
func NewID() string
NewID is a globally unique identifier. It is a [A-Z0-9] string 26 characters long. It is a UUID version 4 Guid that is zbased32 encoded with the padding stripped off.
func NewRandomNumber ¶
NewRandomNumber returns a random string of the given length, built from digits
func NewRandomString ¶
NewRandomString returns a random string of the given length. The resulting entropy will be (5 * length) bits.
Types ¶
type APIError ¶
type APIError struct {
Message string `json:"message"`
}
APIError is the error struct returned by REST API endpoints.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the programmatic interface to the server API.
func NewClientWithHeaders ¶
NewClientWithHeaders creates a client to the server at the given address and uses the provided headers.
func (*Client) ForgotPassword ¶
func (c *Client) ForgotPassword(request *ForgotPasswordRequest) error
ForgotPassword starts the forgot-password flow for a user
func (*Client) Headers ¶
Headers will return a copy of the HTTP headers that the client sends with all requests.
func (*Client) Login ¶
func (c *Client) Login(request *LoginRequest) (*User, error)
Login will log a user in.
func (*Client) ResetPassword ¶
func (c *Client) ResetPassword(request *ResetPasswordRequest) error
ResetPassword finishes the forgot-password flow for a user
func (*Client) SignUp ¶
func (c *Client) SignUp(request *SignUpRequest) (*SignUpResponse, error)
SignUp creates a user.
func (*Client) UpdatePassword ¶
func (c *Client) UpdatePassword(request *UpdatePasswordRequest) error
UpdatePassword updates a user's password.
func (*Client) VerifyEmailComplete ¶
func (c *Client) VerifyEmailComplete(request *VerifyEmailRequest) error
VerifyEmailComplete finishes the verify email flow for the user
func (*Client) VerifyEmailStart ¶
VerifyEmailStart starts the verify email flow for the user
type ForgotPasswordRequest ¶
type ForgotPasswordRequest struct {
Email string `json:"email"`
}
ForgotPasswordRequest specifies the forgot password parameters.
type LoginRequest ¶
LoginRequest specifies the login parameters.
type OAuthState ¶
type OAuthState struct { ID string `json:"id"` Token string `json:"token"` CreateAt int64 `json:"create_at" db:"create_at"` ExpiresAt int64 `json:"expires_at" db:"expires_at"` }
func (*OAuthState) IsExpired ¶
func (o *OAuthState) IsExpired() bool
IsExpired returns true if the OAuth state is expired.
func (*OAuthState) PreSave ¶
func (o *OAuthState) PreSave()
PreSave will set the ID, Token, ExpiresAt and CreateAt for the OAuth state.
type ResetPasswordRequest ¶
ResetPasswordRequest specifies the reset password parameters.
type Role ¶
type Role struct { ID string `json:"id"` Name string `json:"name"` CreateAt int64 `json:"create_at" db:"create_at"` UpdateAt int64 `json:"update_at" db:"update_at"` }
func (*Role) CreatePreSave ¶
func (r *Role) CreatePreSave()
CreatePreSave will set the correct values for a new role that is about to be saved.
type Session ¶
type Session struct { ID string `json:"id"` Token string `json:"token"` CreateAt int64 `json:"create_at" db:"create_at"` ExpiresAt int64 `json:"expires_at" db:"expires_at"` UserID string `json:"user_id" db:"user_id"` CSRFToken string `json:"csrf_token" db:"csrf_token"` }
Session is an authentication session for a user.
type SignUpRequest ¶
type SignUpRequest struct { Email string `json:"email"` FirstName string `json:"first_name"` LastName string `json:"last_name"` Password string `json:"password"` }
SignUpRequest contains the fields for a request to the sign-up API.
type SignUpResponse ¶
type SignUpResponse struct {
User *User `json:"user"`
}
SignUpResponse contains the user.
func SignUpResponseFromReader ¶
func SignUpResponseFromReader(reader io.Reader) (*SignUpResponse, error)
SignUpResponseFromReader decodes a json-encoded sign-up API response from the given io.Reader.
type Token ¶
type Token struct { Token string `json:"token"` CreateAt int64 `json:"create_at" db:"create_at"` Type string `json:"type"` Extra string `json:"extra"` }
Token is a one-time-use expiring object used in place of passwords or other authentication values.
func (*Token) GetExtraEmail ¶
GetExtraEmail returns the correct extra values for a token of type TokenTypeChangePassword.
type TokenExtraEmail ¶
type TokenExtraEmail struct {
Email string `json:"email"`
}
TokenExtraEmail is a token extra field containing an email value.
type UpdatePasswordRequest ¶
type UpdatePasswordRequest struct { NewPassword string `json:"new_password"` CurrentPassword string `json:"current_password"` }
UpdatePasswordRequest specifies the update password parameters.
type User ¶
type User struct { ID string `json:"id"` CreateAt int64 `json:"create_at" db:"create_at"` UpdateAt int64 `json:"update_at" db:"update_at"` Email string `json:"email"` EmailVerified bool `json:"email_verified" db:"email_verified"` Password string `json:"password,omitempty"` FirstName string `json:"first_name,omitempty" db:"first_name"` LastName string `json:"last_name,omitempty" db:"last_name"` State string `json:"state"` IsAdmin bool `json:"is_admin" db:"is_admin"` }
TODO: cleanup User model represents a user on the system.
func UserFromReader ¶
UserFromReader decodes a json-encoded user from the given io.Reader.
func (*User) CreatePreSave ¶
func (u *User) CreatePreSave()
CreatePreSave will set the correct values for a new user that is about to be saved.
func (*User) GetUserEmailDomain ¶
func (*User) IsValidPassword ¶
IsValidPassword returns an error if the user's password is not valid.
type UserAuthInfo ¶
type UserAuthInfo struct { UserID string `json:"user_id"` OAuthProvider string `json:"oauth_provider"` Token oauth2.Token `json:"token"` Username string `json:"username"` Email string `json:"email,omitempty"` Name string `json:"name,omitempty"` AvatarURL string `json:"avatar_url"` CreateAt int64 `json:"create_at" db:"create_at"` UpdateAt int64 `json:"update_at" db:"update_at"` DeleteAt int64 `json:"update_at" db:"delete_at"` }
func (*UserAuthInfo) PreSave ¶
func (u *UserAuthInfo) PreSave()
PreSave will set the ID and CreateAt for the UserAuthInfo.
type UserFacingError ¶
type UserFacingError struct {
// contains filtered or unexported fields
}
UserFacingError is an error type meant to be read by end users.
func NewUserFacingError ¶
func NewUserFacingError(messageForUser, internalDetails string) *UserFacingError
NewUserFacingError creates a new error including a user facing message.
func (*UserFacingError) Error ¶
func (u *UserFacingError) Error() string
func (*UserFacingError) ErrorForUser ¶
func (u *UserFacingError) ErrorForUser() string
ErrorForUser returns the error message meant for the end user.
type VerifyEmailRequest ¶
type VerifyEmailRequest struct {
Token string `json:"token"`
}
VerifyEmailRequest specifies the verify-email parameters.