authgrp

package
v0.0.0-...-8414c70 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package authgrp provides handlers for user registration and signin

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewUserResponse

func NewUserResponse(user db_generated.User) userResponse

Types

type Handler

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

func New

func New(store db.Store, task task.Manager, frontendHost string) *Handler

func (*Handler) Register

func (h *Handler) Register(app *web.App)

func (*Handler) SendEmail

func (h *Handler) SendEmail(ctx context.Context, w http.ResponseWriter, r *http.Request) error

SendEmail godoc

@Summary		Send an email to user with given subject
@Description	Send an email to user with given subject, currently subject=welcome, subject=verify and subject=report are implemented. User needs to have a non-null email to be verified, and have a verified email to receive emails of other subjects.
@Tags			Authentication
@Accept			json
@Produce		json
@Security		Bearer
@Param			request	body	SendEmailRequest	true	"Email subject"
@Success		201
@Failure		400
@Failure		404
@Failure		409
@Router			/send-email [post]

func (*Handler) Signin

func (h *Handler) Signin(ctx context.Context, w http.ResponseWriter, r *http.Request) error

Signin godoc

@Summary		Signin
@Description	Signin with username and password
@Tags			Authentication
@Accept			json
@Produce		json
@Param			body	body		SigninRequest	true	"request body"
@Success		200		{object}	SigninResponse
@Failure		400
@Failure		409
@Router			/signin [post]

func (*Handler) Signup

func (h *Handler) Signup(ctx context.Context, w http.ResponseWriter, r *http.Request) error

Signup godoc

@Summary		Signup
@Description	Signup with username, email (optional) and password.
@Tags			Authentication
@Accept			json
@Produce		json
@Param			body	body		SignupRequest	true	"request body"
@Success		201		{object}	SignupResponse
@Failure		400
@Failure		409
@Router			/signup [post]

func (*Handler) VerifyEmail

func (h *Handler) VerifyEmail(ctx context.Context, w http.ResponseWriter, r *http.Request) error

VerifyEmail godoc

@Summary		Verify email
@Description	Verify email with the id and code
@Tags			Authentication
@Accept			json
@Produce		json
@Security		Bearer
@Param			body	body		VerifyEmailRequest	true	"request body"
@Success		200		{object}	VerifyEmailResponse
@Failure		400
@Failure		404
@Router			/verify-email [post]

type SendEmailRequest

type SendEmailRequest struct {
	Subject string `json:"subject" validate:"required"`
}

type SendEmailResponse

type SendEmailResponse struct {
	TaskId string `json:"task_id"`
}

type SigninRequest

type SigninRequest struct {
	//
	Username string `json:"username" validate:"required,alphanum,username"`
	Password string `json:"password" validate:"required,password"`
}

type SigninResponse

type SigninResponse struct {
	User        userResponse `json:"user"`
	AccessToken string       `json:"access_token"`
}

type SignupRequest

type SignupRequest struct {
	// 3 to 20 characters, only letters and numbers
	Username string `json:"username" validate:"required,alphanum,username"`
	// Email address (Optional)
	Email string `json:"email"    validate:""`
	// 6 to 20 characters
	Password string `json:"password" validate:"required,password"`
}

type SignupResponse

type SignupResponse struct {
	// The created user model
	User userResponse `json:"user"`
	// Access token for the user
	AccessToken string `json:"access_token"`
	// Task id for the email delivery task, if email is provided in the request
	TaskId string `json:"task_id,omitempty"`
}

type VerifyEmailRequest

type VerifyEmailRequest struct {
	Id   string `json:"id"   validate:"required"`
	Code string `json:"code" validate:"required"`
}

type VerifyEmailResponse

type VerifyEmailResponse struct {
	Ok bool `json:"ok"`
}

Jump to

Keyboard shortcuts

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