auth

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

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAuth

func BasicAuth(s Session) http.HandlerFunc

BasicAuth provides basic authentication.

func Login

func Login(s Session) http.HandlerFunc

Login takes a user credentials and authenticates it.

func LoginGoogle

func LoginGoogle(s Session) http.HandlerFunc

LoginGoogle redirects the user to the google oauth2.

func Logout

func Logout(s Session) http.HandlerFunc

Logout logs the user out from the session and removes cookies.

func OAuth2Google

func OAuth2Google(s Session) http.HandlerFunc

OAuth2Google executes the oauth2 login with Google.

Types

type Session

type Session interface {
	AlreadyLoggedIn(ctx context.Context, r *http.Request) bool
	Login(ctx context.Context, w http.ResponseWriter, r *http.Request, email, password string) error
	LoginOAuth(ctx context.Context, w http.ResponseWriter, r *http.Request, email string) error
	Logout(ctx context.Context, w http.ResponseWriter, r *http.Request) error
}

Session provides auth operations.

func NewSession

func NewSession(db *sqlx.DB, rdb *redis.Client, config config.Session, development bool) Session

NewSession creates a new session with the necessary dependencies.

type User

type User struct {
	ID            string `json:"id"`
	CartID        string `json:"cart_id" db:"cart_id"`
	Username      string `json:"username"`
	Email         string `json:"email" validate:"email,required"`
	Password      string `json:"password" validate:"required,min=6"`
	VerifiedEmail bool   `json:"-" db:"verified_email"`
}

User represents a customer trying to log in.

type UserAuth

type UserAuth struct {
	Email    string `json:"email" validate:"email,required"`
	Password string `json:"password" validate:"required,min=6"`
}

UserAuth is the login request used to authenticate users.

Jump to

Keyboard shortcuts

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