service

package
v0.0.0-...-0d639c9 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthController

type AuthController struct {
	Server *server.Server
}

func NewAuthController

func NewAuthController(s *server.Server) *AuthController

func (*AuthController) Delete

func (c *AuthController) Delete(req *fiber.Ctx) error

Delete handles the deletion of a user by retrieving the user data from the JWT token in the "auth" cookie, deleting the user from the database, and returning a JSON response with the status code fiber.StatusOK.

Parameters:

  • req: a pointer to a fiber.Ctx object representing the HTTP request context.

Returns:

  • error: an error object if there was an issue decoding the JWT token, finding the user, or deleting the user from the database. Otherwise, nil.

func (*AuthController) Login

func (c *AuthController) Login(req *fiber.Ctx) error

Login handles the login request by parsing the request body, finding the user by email, comparing the password, generating a JWT token, setting the "auth" cookie, and returning a JSON response with the status code fiber.StatusOK and the token.

Parameters:

  • req: a pointer to a fiber.Ctx object representing the HTTP request context.

Returns:

  • error: an error if there was an issue parsing the request, finding the user, comparing the password, generating the JWT token, setting the cookie, or creating the JSON response.

func (*AuthController) Logout

func (c *AuthController) Logout(req *fiber.Ctx) error

Logout handles the logout request by clearing the "auth" cookie and returning a JSON response with the status code fiber.StatusOK.

Parameters:

  • req: a pointer to a fiber.Ctx object representing the HTTP request context.

Returns:

  • error: an error if there was a problem setting the cookie or creating the JSON response.

func (*AuthController) Register

func (c *AuthController) Register(ctx *fiber.Ctx) error

Register handles the registration request by parsing the request body, finding the user role, creating a new user with the provided information, and returning a JSON response with the user data.

Parameters:

  • ctx: a pointer to a fiber.Ctx object representing the HTTP request context.

Returns:

  • error: an error if there was an issue parsing the request, finding the user role, creating the user, or returning the JSON response. Otherwise, nil.

func (*AuthController) User

func (c *AuthController) User(req *fiber.Ctx) error

User handles the user request by retrieving the "auth" cookie, decoding the JWT token, finding the user in the database, and returning the user data in a JSON response.

Parameters:

  • req: a pointer to a fiber.Ctx object representing the HTTP request.

Returns:

  • error: an error object if there was an issue decoding the JWT token, finding the user, or returning the JSON response. Otherwise, nil.

type UserJWT

type UserJWT struct {
	ID      int64
	Email   string
	Role    string
	ExpTime time.Time
}

func GetUserDataJWT

func GetUserDataJWT(prompt string) (*UserJWT, error)

func (*UserJWT) GenJWT

func (u *UserJWT) GenJWT(t string) (string, error)

Jump to

Keyboard shortcuts

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