Documentation ¶
Index ¶
- Constants
- Variables
- func ValidateEmail(v *validator.Validator, email string)
- func ValidatePasswordPlainText(v *validator.Validator, password string)
- func ValidateTokenPlaintext(v *validator.Validator, tokenPlaintext string)
- func ValidateUser(v *validator.Validator, user *User)
- type Token
- type TokenKeyBasedStruct
- type TokenService
- type User
- type UserKeyBasedStruct
- type UserService
Constants ¶
const ( ScopeActivation = "activation" Authentication = "authentication" )
Define constants for the token scope. For now we just define the scope "activation" but we'll add additional scopes later in the book.
Variables ¶
var AnonymousUser = &User{}
Declare a new AnonymousUser variable.
var (
ErrorDuplicateEmail = errors.New("duplicate email")
)
Define a custom ErrorDuplicateEmail error.
Functions ¶
func ValidateEmail ¶
func ValidateTokenPlaintext ¶
Check that the plaintext token has been provided and is exactly 26 bytes long.
func ValidateUser ¶
Types ¶
type TokenKeyBasedStruct ¶
type TokenKeyBasedStruct struct {
Hash []byte `dynamodbav:"hash"`
}
type TokenService ¶
type TokenService struct { Store *clients.DynamoDbClientWrapper TableName string }
func NewTokenSrv ¶
func NewTokenSrv(store *clients.DynamoDbClientWrapper, tableName string) *TokenService
func (*TokenService) Insert ¶
func (s *TokenService) Insert(token *Token) error
type User ¶
type User struct { Email string `json:"email"` Name string `json:"name"` CreatedAt string `json:"created_at"` Password password `json:"-"` Activated bool `json:"activated"` Version int `json:"-"` }
func (*User) IsAnonymous ¶
Check if a User instance is the AnonymousUser.
type UserKeyBasedStruct ¶
type UserKeyBasedStruct struct {
Email string `dynamodbav:"email"`
}
type UserService ¶
type UserService struct { Store *clients.DynamoDbClientWrapper TableName string }
func New ¶
func New(store *clients.DynamoDbClientWrapper, tableName string) *UserService
func (UserService) GetByEmail ¶
func (s UserService) GetByEmail(email string) (*User, error)
Retrieve the User details from the database based on the user's email address. Because we have a UNIQUE constraint on the email column, this SQL query will only return one record (or none at all, in which case we return a ErrorRecordNotFound error).
func (UserService) Insert ¶
func (s UserService) Insert(user *User) error
func (UserService) Update ¶
func (s UserService) Update(user *User) error
Update the details for a specific user. Notice that we check against the version field to help prevent any race conditions during the request cycle, just like we did when updating a movie. And we also check for a violation of the "users_email_key" constraint when performing the update, just like we did when inserting the user record originally.