Documentation ¶
Overview ¶
Package model manages the business data model entities and their behaviuor.
Index ¶
- Variables
- func ClearPasswordToken(id, token string)
- type Account
- func (a *Account) Activate(token string) (err error, conflict bool)
- func (a *Account) ChangeEmail(token string) (err error, conflict bool)
- func (a *Account) ChangePassword(token, pwd1, pwd2 string) (err error, conflict bool)
- func (a *Account) ClearEmailToken(token string) (err error, conflict bool)
- func (a *Account) ClearSuspendToken(token string) (err error)
- func (a *Account) CreateEmailToken(newEmail string) (err error, conflict bool)
- func (a *Account) CreatePasswordToken() error
- func (a *Account) CreateSuspendToken(sure string) (err error, conflict bool)
- func (a *Account) IsActive() bool
- func (a *Account) Refresh() (current bool)
- func (a *Account) Suspend(token string, sure string) (err error, conflict bool)
- func (a *Account) ValidatePassword(password string) (err error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidCredentials = errors.New("ErrInvalidCredentials") ErrEmailTaken = errors.New("ErrEmailTaken") )
var ( ErrPasswordEmpty = errors.New("ErrPasswordEmpty") ErrPasswordsNotEqual = errors.New("ErrPasswordsNotEqual") ErrNotActivated = errors.New("ErrNotActivated") ErrPasswordTokenTimedOut = errors.New("ErrPasswordTokenTimedOut") )
var (
ErrAlreadyActivated = errors.New("ErrAlreadyActivated")
)
Functions ¶
func ClearPasswordToken ¶
func ClearPasswordToken(id, token string)
ClearPasswordToken clears the token to cancel the password changing process.
Types ¶
type Account ¶
type Account struct { *entity.Base Email string Password *password ActivateToken string PasswordToken *passwordToken EmailToken string NewEmail string SuspendToken string }
Account represents the user's tollgate to the application.
When logged in, an encrypted representation of the user's Account is kept in an HTTP cookie to authorise any subsequent requests.
func GetAccount ¶
GetAccount returns the stored Account with the given id and/or email address.
func NewAccount ¶
NewAccount creates a new Account in the database, if a unique email address is given, and the same password twice. The password is never saved, so it's not deductable from the database. Only a cryptographic hash is stored, to compare to the computed hash of the password to validate on log in.
func (*Account) Activate ¶
Activate activates the account, or returns an error if the account was already activated, or the token given is invalid.
func (*Account) ChangeEmail ¶
ChangeEmail sets the Account's Email to the NewEmail, if the given token is correct.
func (*Account) ChangePassword ¶
ChangePassword sets the Account's Password to the new password, if the given token and old password are correct.
func (*Account) ClearEmailToken ¶
ClearEmailToken clears the token to cancel the email address changing process.
func (*Account) ClearSuspendToken ¶
ClearSuspendToken clears the token to cancel the account suspending process.
func (*Account) CreateEmailToken ¶
CreateEmailToken generates a token that is needed to change the Account's email address.
func (*Account) CreatePasswordToken ¶
CreatePasswordToken generates a token that is needed to change the Account's password.
func (*Account) CreateSuspendToken ¶
CreateSuspendToken generates a token that is needed to suspend the Account, if sure is "affirmative".
func (*Account) IsActive ¶
IsActive returns wehther the account is activated to confirm the user's control over the email address provided.
func (*Account) Refresh ¶
Refresh updates the account's field values & returns the validity of the session. It's called by the function that validates the session cookie.
func (*Account) Suspend ¶
Suspend deletes the Account if the given token is correct and sure is "affirmative".
func (*Account) ValidatePassword ¶
ValidatePassword tests whether the given password is valid for the Account. It computes a cryptographic hash value that is compared to the hash stored in the database.