users

package
v0.0.0-...-8a09f7e Latest Latest
Warning

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

Go to latest
Published: May 9, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DB is the reference to our DB, which contains our user data.
	DB = newDB()

	// ErrUserAlreadyExists is the error thrown when a user attempts to create
	// a new user in the DB with a duplicate username.
	ErrUserAlreadyExists = errors.New("users: username already exists")

	// ErrUserNotFound is the error thrown when a user can't be found in the
	// database.
	ErrUserNotFound = errors.New("users: user not found")
)
View Source
var CSRF = csrf.Protect(genRandBytes())

CSRF is used to prevent CSRF attacks

Functions

func AuthURLHandler

func AuthURLHandler(w http.ResponseWriter, r *http.Request)

AuthURLHandler just redirects the user to correct Oauth sign in page for our provider.

func AuthenticateUser

func AuthenticateUser(username string, password string) error

AuthenticateUser accepts a username and password, and checks that the given password matches the hashed password. It returns nil on success, and an error on failure.

func CallbackURLHandler

func CallbackURLHandler(w http.ResponseWriter, r *http.Request)

CallbackURLHandler handles all of the Oauth flow.

func GetSession

func GetSession(w http.ResponseWriter, r *http.Request) string

GetSession gets the current session from the cookie

func New

func New() *oauth2.Config

New creates a new oauth2 config

func NewUser

func NewUser(username string, password string) error

NewUser accepts a username and password and creates a new user in our DB from it.

func OverrideOldPassword

func OverrideOldPassword(username string, password string) error

OverrideOldPassword overrides the old password with the new password. For use when resetting passwords.

func ResetPassword

func ResetPassword(w http.ResponseWriter, r *http.Request)

ResetPassword is the HTTP handler that handles the password reset flow.

func SendPasswordResetEmail

func SendPasswordResetEmail(email string) error

SendPasswordResetEmail sends a password reset email to the given user.

func SetSession

func SetSession(w http.ResponseWriter, user string)

SetSession sets the session for the given user.

func VerifyToken

func VerifyToken(r *http.Request) (string, error)

VerifyToken gets the token from an HTTP request, and ensures that it's valid. It'll return the user's username as a string.

Types

type Store

type Store struct {
	DB       *bolt.DB
	Users    string
	Sessions string
}

Store is a reference to our BoltDB instance that contains two seperate internal stores: a user store, and a session store.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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