model

package
v0.0.0-...-263c4a3 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2017 License: LGPL-3.0 Imports: 7 Imported by: 2

Documentation

Overview

Package model manages the business data model entities and their behaviuor.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCredentials = errors.New("ErrInvalidCredentials")
	ErrEmailTaken         = errors.New("ErrEmailTaken")
)
View Source
var (
	ErrPasswordEmpty         = errors.New("ErrPasswordEmpty")
	ErrPasswordsNotEqual     = errors.New("ErrPasswordsNotEqual")
	ErrNotActivated          = errors.New("ErrNotActivated")
	ErrPasswordTokenTimedOut = errors.New("ErrPasswordTokenTimedOut")
)
View Source
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

func GetAccount(id string, address ...string) (account *Account, err error, conflict bool)

GetAccount returns the stored Account with the given id and/or email address.

func NewAccount

func NewAccount(address, pwd1, pwd2 string) (account *Account, err error, conflict bool)

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

func (a *Account) Activate(token string) (err error, conflict bool)

Activate activates the account, or returns an error if the account was already activated, or the token given is invalid.

func (*Account) ChangeEmail

func (a *Account) ChangeEmail(token string) (err error, conflict bool)

ChangeEmail sets the Account's Email to the NewEmail, if the given token is correct.

func (*Account) ChangePassword

func (a *Account) ChangePassword(token, pwd1, pwd2 string) (err error, conflict bool)

ChangePassword sets the Account's Password to the new password, if the given token and old password are correct.

func (*Account) ClearEmailToken

func (a *Account) ClearEmailToken(token string) (err error, conflict bool)

ClearEmailToken clears the token to cancel the email address changing process.

func (*Account) ClearSuspendToken

func (a *Account) ClearSuspendToken(token string) (err error)

ClearSuspendToken clears the token to cancel the account suspending process.

func (*Account) CreateEmailToken

func (a *Account) CreateEmailToken(newEmail string) (err error, conflict bool)

CreateEmailToken generates a token that is needed to change the Account's email address.

func (*Account) CreatePasswordToken

func (a *Account) CreatePasswordToken() error

CreatePasswordToken generates a token that is needed to change the Account's password.

func (*Account) CreateSuspendToken

func (a *Account) CreateSuspendToken(sure string) (err error, conflict bool)

CreateSuspendToken generates a token that is needed to suspend the Account, if sure is "affirmative".

func (*Account) IsActive

func (a *Account) IsActive() bool

IsActive returns wehther the account is activated to confirm the user's control over the email address provided.

func (*Account) Refresh

func (a *Account) Refresh() (current bool)

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

func (a *Account) Suspend(token string, sure string) (err error, conflict bool)

Suspend deletes the Account if the given token is correct and sure is "affirmative".

func (*Account) ValidatePassword

func (a *Account) ValidatePassword(password string) (err error)

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.

Jump to

Keyboard shortcuts

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