user

package
v0.0.0-...-780089a Latest Latest
Warning

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

Go to latest
Published: May 4, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateUserOpts

type CreateUserOpts struct {
	Username string `json:"username"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

type LoginInput

type LoginInput struct {
	Username string `json:"username" validate:"required,min=3,max=24"`
	Password string `json:"password" validate:"required,min=6"`
}

type LoginResult

type LoginResult struct {
	ID       uuid.UUID `json:"id"`
	Token    string    `json:"token"`
	Username string    `json:"username"`
	Exp      int64     `json:"exp"`
}

type PgRepo

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

func NewPgRepo

func NewPgRepo(pool *pgxpool.Pool) *PgRepo

func (*PgRepo) FindByID

func (r *PgRepo) FindByID(ctx context.Context, id uuid.UUID) (*User, error)

func (*PgRepo) FindByUsername

func (r *PgRepo) FindByUsername(ctx context.Context, username string) (*User, error)

func (*PgRepo) Save

func (r *PgRepo) Save(ctx context.Context, u *User) error

func (*PgRepo) Update

func (r *PgRepo) Update(ctx context.Context, u *User) error

func (*PgRepo) VerifyPassword

func (r *PgRepo) VerifyPassword(ctx context.Context, username, password string) error

VerifyPassword returns nil on success TODO: This looks unneccessary or should return user too

type RegisterInput

type RegisterInput struct {
	Username string `json:"username" validate:"required,min=3,max=24"`
	Email    string `json:"email" validate:"required,email"`
	Password string `json:"password" validate:"required,min=6"`
}

type Repo

type Repo interface {
	Save(ctx context.Context, u *User) error
	FindByID(ctx context.Context, id uuid.UUID) (*User, error)
	FindByUsername(ctx context.Context, username string) (*User, error)
	VerifyPassword(ctx context.Context, username, password string) error // IDK
	Update(ctx context.Context, u *User) error
}

type Routes

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

func NewRoutes

func NewRoutes(repo Repo, jwtSecret string, validator *validate.Validate) *Routes

func (*Routes) FindByID

func (r *Routes) FindByID(c *fiber.Ctx) error

FindByID

@ID			User-FindByID
@Summary	Find User By ID
@Tags		users
@Accept		json
@Produce	json
@Param		id	path		string	true	"User ID"
@Success	200	{object}	User
@Failure	400
@Failure	500
@Router		/users/{id} [get]

func (*Routes) Login

func (r *Routes) Login(c *fiber.Ctx) error

Login

@ID			User-Login
@Summary	Login With Credentials
@Tags		users
@Accept		json
@Produce	json
@Param		credentials	body	LoginInput	true	"User Credentials"
@Success	200
@Failure	400
@Failure	500
@Router		/users/login [post]

func (*Routes) Register

func (r *Routes) Register(c *fiber.Ctx) error

Register

@ID			User-Register
@Summary	Register New User
@Tags		users
@Accept		json
@Produce	json
@Param		options	body	RegisterInput	true	"New User Info"
@Success	201
@Failure	400
@Failure	500
@Router		/users/register [post]

func (*Routes) UpdatePassword

func (r *Routes) UpdatePassword(c *fiber.Ctx) error

UpdatePassword

@ID			User-Update-Password
@Summary	Upate Password
@Tags		users
@Security	BearerAuth
@Accept		json
@Produce	json
@Param		credentials	body		UpdatePasswordInput	true	"User Credentials and New Password"
@Success	200			{object}	User
@Failure	400
@Failure	500
@Router		/users/update-password [patch]

type UpdatePasswordInput

type UpdatePasswordInput struct {
	Password    string `json:"password" validate:"required"`
	NewPassword string `json:"new_password" validate:"required,min=6"`
}

type User

type User struct {
	ID             uuid.UUID `json:"id"`
	Username       string    `json:"username"`
	Email          string    `json:"email"`
	HashedPassword []byte    `json:"-"`
	Bio            string    `json:"bio"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func CreateUser

func CreateUser(opts CreateUserOpts) (User, error)

CreateUser creates brand new user with new ID!

func (*User) UpdateBio

func (u *User) UpdateBio(bio string)

func (*User) UpdateEmail

func (u *User) UpdateEmail(email string)

func (*User) UpdatePassword

func (u *User) UpdatePassword(password string) error

Jump to

Keyboard shortcuts

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