libuser

package
v0.0.0-...-d66398d Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2014 License: GPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Handles the user account page

Libuser contains functionality for user management

Handles the login functionality for users.

Handles the user loggout functionality

Handles the registration functionality for users

Handles the password reset functionality for users

Contains various utility functions

Handles the verification of email address for users.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleError

func HandleError(w http.ResponseWriter, err error)

func VerifyEmail

func VerifyEmail(email string) (bool, error)

Types

type Login

type Login struct {
	Username string `schema:"username"`
	Password string `schema:"password"`
}

type Registration

type Registration struct {
	Username string `schema:"username"`
	Email    string `schema:"email"'`
	Password string `schema:"password"`
}

type User

type User struct {
	UUID     string `db:"uid"`
	Username string
	Email    string
	// @TODO: Ensure this is never sent in a response.
	Password  []byte `json:"-"`
	Verified  bool
	Enabled   bool
	Created   time.Time
	Updated   time.Time
	LastLogin time.Time `db:"last_login"`
}

Define user type

func CreateUser

func CreateUser() User

/ CreateUser creates an empty user and returns it.

func (*User) SetPassword

func (u *User) SetPassword(password []byte) (bool, error)

SetPassword takes a plaintext passwords and encrypts it. Call this function, do not directly set the password on the user struct.

type UserAccount

type UserAccount struct {
	Storage        UserStorage
	TemplateConfig libtmpl.HTMLTemplateConfig
	//@TODO: Should just pass in a session instead of the session store.
	SessionStore sessions.Store
}

func (UserAccount) AccountPage

func (ua UserAccount) AccountPage(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

type UserLogin

type UserLogin struct {
	Storage        UserStorage
	TemplateConfig libtmpl.HTMLTemplateConfig
	//@TODO: Should just pass in a session instead of the session store.
	SessionStore sessions.Store
}

Login functionality. Should handle checking the user's username and password. Should be able to easily take a username or email address to improve the user experience.

func (UserLogin) HandleError

func (ul UserLogin) HandleError(w http.ResponseWriter, err error)

func (UserLogin) LoginForm

func (ul UserLogin) LoginForm(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (UserLogin) LoginSubmission

func (ul UserLogin) LoginSubmission(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

type UserLogout

type UserLogout struct {
	Storage        UserStorage
	TemplateConfig libtmpl.HTMLTemplateConfig
	//@TODO: Should just pass in a session instead of the session store.
	SessionStore sessions.Store
}

func (UserLogout) Logout

type UserRegistration

type UserRegistration struct {
	Storage        UserStorage
	TemplateConfig libtmpl.HTMLTemplateConfig
	//@TODO: Should just pass in a session instead of the session store.
	SessionStore sessions.Store
}

Registration should be simple as we are only collecting a user's username, email address, and password. We should ensure the uniqueness checks (for username and email) are fast.

func (UserRegistration) GetRegistrationForm

func (ur UserRegistration) GetRegistrationForm(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (UserRegistration) HandleError

func (ur UserRegistration) HandleError(w http.ResponseWriter, err error)

func (UserRegistration) HandleRegistrationSubmission

func (ur UserRegistration) HandleRegistrationSubmission(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

type UserStorage

type UserStorage interface {
	// Retrieve a user.
	// @TODO: Potentially use a paratially filled in user object to retrieve the
	// full user object. This would allow retrieval via usernam, email, or UUID
	RetrieveUser(username string) (User, error)
	CreateUser(user User) (bool, error)
	UpdateUser(user User) (bool, error)
	DeleteUser(user User) (bool, error)
	// Checks if the username has already been used
	// Returns true if it has and false if it hasn't
	CheckUsername(username string) (bool, error)
	// Checks if the email address has already been used
	// Returns true if it has and false if it hasn't
	CheckEmail(email string) (bool, error)
	CheckPassword(username, password string) (bool, error)
}

Jump to

Keyboard shortcuts

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