Documentation ¶
Index ¶
- Variables
- func NewCookieSessionStore(pairs ...[]byte) *cookieSessionStore
- type Mailer
- type PasswordHasher
- type SessionStore
- type Storer
- type User
- type UserManager
- func (m UserManager) Activate(u *User) error
- func (m UserManager) AdminFromSession(w http.ResponseWriter, r *http.Request) (*User, error)
- func (m UserManager) Authenticate(u *User, pw string) error
- func (m UserManager) ByEmail(email string) (*User, error)
- func (m UserManager) ById(id int64) (*User, error)
- func (m UserManager) ByToken(tok string) (*User, error)
- func (m UserManager) Deactivate(u *User) error
- func (m UserManager) DeleteUser(u *User) error
- func (m UserManager) DeleteUserById(id int64) error
- func (m UserManager) FromSession(w http.ResponseWriter, r *http.Request) (*User, error)
- func (m UserManager) Insert(u *User) error
- func (m UserManager) LogIn(w http.ResponseWriter, r *http.Request, u *User) error
- func (m UserManager) LogOut(w http.ResponseWriter, r *http.Request) error
- func (m UserManager) New(name, email, pw, confirmPw string, active, admin bool) (*User, error)
- func (m UserManager) RequestPwReset(u *User, disableCurrentPw bool) error
- func (m UserManager) SendSignupMail(u *User) error
- func (m UserManager) SignupUser(w http.ResponseWriter, r *http.Request, name, email, pw, confirmPw string, ...) (*User, error)
- func (m UserManager) Update(u *User) error
- func (m UserManager) UpdatePw(u *User, pw, confirm string) error
- func (m UserManager) UserResetPw(u *User, old, pw, confirm string) error
- func (m UserManager) Users() ([]*User, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrPwTooShort = errors.New("Supplied password too short") ErrPwTooLong = errors.New("Supplied password too long") ErrIncorrectPw = errors.New("Supplied password does not match the hash") )
var ( ErrNoSession = errors.New("No session present for the request") ErrWrongType = errors.New("The value stored in the session was the wrong type") )
Functions ¶
func NewCookieSessionStore ¶
func NewCookieSessionStore(pairs ...[]byte) *cookieSessionStore
Types ¶
type PasswordHasher ¶
func NewBcryptHasher ¶
func NewBcryptHasher(minPwLen, maxPwLen, bcryptCost int) PasswordHasher
type SessionStore ¶
type User ¶
type User struct { ID int64 `db:"id" json:"id"` Email string `db:"email" json:"email"` PwHash string `db:"pw_hash" json:"-"` Admin bool `db:"admin" json:"-"` Active bool `db:"active" json:"active"` Token string `db:"token" json:"token"` Name string `db:"name" json:"name"` CreatedAt *time.Time `db:"created_at" json:"createdAt"` }
type UserManager ¶
type UserManager struct {
// contains filtered or unexported fields
}
func NewUserManager ¶
func NewUserManager(h PasswordHasher, s Storer, m Mailer, sm SessionStore) *UserManager
NewUserManager creates an object which can be used to manipulate User objects.
func (UserManager) Activate ¶
func (m UserManager) Activate(u *User) error
Activate ensures that a user is able to log on.
func (UserManager) AdminFromSession ¶
func (m UserManager) AdminFromSession(w http.ResponseWriter, r *http.Request) (*User, error)
func (UserManager) Authenticate ¶
func (m UserManager) Authenticate(u *User, pw string) error
Authenticate checks to see if the password supplies is the same as the password that was used to create the hash
func (UserManager) ByEmail ¶
func (m UserManager) ByEmail(email string) (*User, error)
ByEmail obtains the user from the email supplied
func (UserManager) ById ¶
func (m UserManager) ById(id int64) (*User, error)
ById obtains the user by their id field
func (UserManager) ByToken ¶
func (m UserManager) ByToken(tok string) (*User, error)
ByToken obtains the user from the generated token. This can be used for password resets or signup links
func (UserManager) Deactivate ¶
func (m UserManager) Deactivate(u *User) error
Deactivate deactivates the user, disabling the user from logging on.
func (UserManager) DeleteUser ¶
func (m UserManager) DeleteUser(u *User) error
func (UserManager) DeleteUserById ¶
func (m UserManager) DeleteUserById(id int64) error
func (UserManager) FromSession ¶
func (m UserManager) FromSession(w http.ResponseWriter, r *http.Request) (*User, error)
FromSession retrieves the current user associated with the session
func (UserManager) Insert ¶
func (m UserManager) Insert(u *User) error
Insert saves a new User. This cannot be called if the user has already been saved.
func (UserManager) LogIn ¶
func (m UserManager) LogIn(w http.ResponseWriter, r *http.Request, u *User) error
func (UserManager) LogOut ¶
func (m UserManager) LogOut(w http.ResponseWriter, r *http.Request) error
func (UserManager) New ¶
func (m UserManager) New(name, email, pw, confirmPw string, active, admin bool) (*User, error)
New creates a new user. Note that this only creates the user, it does not save the user.
func (UserManager) RequestPwReset ¶
func (m UserManager) RequestPwReset(u *User, disableCurrentPw bool) error
RequestPwReset sends a password reset email to the user and optionally disables the user from logging on/
func (UserManager) SendSignupMail ¶
func (m UserManager) SendSignupMail(u *User) error
SendSignupMail sends the user a signup email
func (UserManager) SignupUser ¶
func (m UserManager) SignupUser(w http.ResponseWriter, r *http.Request, name, email, pw, confirmPw string, admin, active bool) (*User, error)
SignupUser creates a new user, emails a signup email, saves the user and logs them in.
func (UserManager) Update ¶
func (m UserManager) Update(u *User) error
Update saves any changes to the User object. This can only be called if the user has already been saved.
func (UserManager) UpdatePw ¶
func (m UserManager) UpdatePw(u *User, pw, confirm string) error
UpdatePw forces a password change. This can be useful for situations when the user does not know their password or if an admin wants to request a password change.
func (UserManager) UserResetPw ¶
func (m UserManager) UserResetPw(u *User, old, pw, confirm string) error
UserResetPw is used when a user requests a password update. The user must supply the correct password in order for the update to be successful
func (UserManager) Users ¶
func (m UserManager) Users() ([]*User, error)