auth

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The database table name for password resets.
	PasswordTableName = "password_resets"
	// ErrLoginMsg is returned by login when
	// authentication failed.
	ErrLoginMsg = "These credentials don't match our records."
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Repository

type Repository interface {
	Login(email, password string) (domain.User, error)
	Logout(token string) (int, error)
	ResetPassword(token, password string) error
	SendResetPassword(email string) (domain.UserPart, string, error)
	VerifyPasswordToken(token string) (domain.PasswordReset, error)
	CleanPasswordResets() error
}

Repository defines methods for auth to interact with the database.

type Store

type Store struct {
	*config.Config
	// contains filtered or unexported fields
}

Store defines the data layer for auth.

func New

func New(cfg *config.Config) *Store

New

Creates a new auth store.

func (*Store) CleanPasswordResets

func (s *Store) CleanPasswordResets() error

CleanPasswordResets

Verify the token is valid from the password resets table Returns errors.INTERNAL if the SQL query was invalid.

func (*Store) Login

func (s *Store) Login(email, password string) (domain.User, error)

Login

Authenticate compares the email & password for a match in the DB. Returns errors.NOTFOUND if the user is not found.

func (*Store) Logout

func (s *Store) Logout(token string) (int, error)

Logout

Logout checks to see if see if the the token is valid & then proceeds to create a new token and returns the user ID. Returns errors.NOTFOUND if the user was not found by the given token. Returns errors.INTERNAL if the SQL query was invalid.

func (*Store) ResetPassword

func (s *Store) ResetPassword(token, password string) error

ResetPassword

Obtains the password reset information from the table and creates a new hash, it then updates the user table with the new details and removes the temporary entry in the PasswordTableName table.

Returns errors.NOTFOUND if the user was not found by the given token. Returns errors.INTERNAL if the SQL query was invalid, unable to create a new password or delete from the password resets table.

func (*Store) SendResetPassword

func (s *Store) SendResetPassword(email string) (domain.UserPart, string, error)

SendResetPassword

Obtains the user by email and generates a new email token. A temporary record is inserted to the password resets table and an email is sent to the user by the reset passwords event. passwords event. Returns errors.NOTFOUND if the user was not found by the given email. Returns errors.INTERNAL if the SQL query was invalid.

func (*Store) VerifyPasswordToken

func (s *Store) VerifyPasswordToken(token string) (domain.PasswordReset, error)

VerifyPasswordToken

Checks to see if the token is valid from the password resets table. Returns errors.INTERNAL if there was an error executing the query. Returns errors.NOTFOUND if the user was not found by the given token.

Jump to

Keyboard shortcuts

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