auth

package
v0.0.0-...-bcfd2cf Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewService

func NewService(r *postgres.Pg) *service

NewService instantiates a new Service layer for customer

func Routes

func Routes(g *echo.Group, s Service)

Routes mounts auth routes on the main group

Types

type ChangePasswordBody

type ChangePasswordBody struct {
	NewPassword string `json:"new_password" validate:"required,password,nefield=OldPassword,alphanum"`
	OldPassword string `json:"old_password" validate:"required,password,nefield=NewPassword,alphanum"`
}

ChangePasswordBody body request to change password

type LoginBody

type LoginBody struct {
	Email    string `json:"email" validate:"required,email"`
	Password string `json:"password" validate:"required,password"`
}

LoginBody encoded email and password authentication

type LoginResp

type LoginResp struct {
	Token string   `json:"token"`
	User  UserResp `json:"user"`
}

LoginResp encoded email and password authentication

type Service

type Service interface {
	Login(body *LoginBody) (*LoginResp, error)
	Signup(body *SignupBody) (*SignupResp, error)
	GenerateAPIKey(ID, email string) (string, error)
	ChangePassword(ID, oldPassword, newPassword string) error
}

Service interface exports available methods for user service

type SignupBody

type SignupBody struct {
	Email     string `json:"email" validate:"required,email"`
	Password  string `json:"password" validate:"required,password"`
	FirstName string `json:"first_name" validate:"required,min=2"`
	LastName  string `json:"last_name" validate:"required,min=2"`
	Username  string `json:"username" validate:"required,min=2"`
}

SignupBody encoded user data for registration

type SignupResp

type SignupResp struct {
	Message string `json:"message"`
}

SignupResp signup successfull message

type UserResp

type UserResp struct {
	Email     string `json:"email" validate:"required,email" gorm:"index"`
	Username  string `json:"username" validate:"required" gorm:"index"`
	FirstName string `json:"first_name" validate:"required,min=2"`
	LastName  string `json:"last_name" validate:"required,min=2"`

	LastLogin time.Time `json:"last_login" validate:""`

	IsActive  bool           `json:"is_active,omitempty" gorm:"default:false"`
	Lang      string         `json:"lang,omitempty" gorm:"default:'en'"`
	IsBlocked bool           `json:"isBlocked" gorm:"default:false"`
	APIKeys   pq.StringArray `json:"apiKeys,omitempty" gorm:"type:varchar(255)[]"`
}

UserResp includes relevant user fields for login response

Jump to

Keyboard shortcuts

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