auth

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package auth implements a service for user authentication.

Index

Constants

View Source
const (
	SignInError = "Invalid username or password"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangePasswordUser

type ChangePasswordUser struct {
	OldPassword        string `json:"oldPassword" validate:"required"`
	NewPassword        string `json:"newPassword" validate:"required,min=10,max=25"`
	NewPasswordConfirm string `json:"newPasswordConfirm" validate:"required,eqfield=NewPassword"`
}

ChangePasswordUser is a user that changes password.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is a service for user authentication.

func New

func New(db *db.Service, sender *email.Sender, validator *validator.Validate, signKey []byte, logger *log.Logger) *Service

New creates a new Service.

func (*Service) AuthenticationMiddleware

func (s *Service) AuthenticationMiddleware(next http.Handler) http.Handler

AuthenticationMiddleware is a middleware that checks if the user is authenticated.

func (*Service) ChangePassword

func (s *Service) ChangePassword(w http.ResponseWriter, r *http.Request)

ChangePassword changes a user's password.

func (*Service) DeleteUser

func (s *Service) DeleteUser(w http.ResponseWriter, r *http.Request)

func (*Service) SignIn

func (s *Service) SignIn(w http.ResponseWriter, r *http.Request)

SignIn signs in a user.

func (*Service) SignUp

func (s *Service) SignUp(w http.ResponseWriter, r *http.Request)

SignUp signs up a user.

func (*Service) SignUpDefaultUser

func (s *Service) SignUpDefaultUser() error

type SignInUser

type SignInUser struct {
	Username string `json:"username" validate:"required,min=4,max=20,alphanum"`
	Password string `json:"password" validate:"required"`
}

SignInUser is a user that logs in.

type SignUpUser

type SignUpUser struct {
	Username string `json:"username" validate:"required,min=4,max=20,alphanum"`
	Email    string `json:"email" validate:"required,email"`
}

SignUpUser is a user that signs up.

Jump to

Keyboard shortcuts

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