handler

package
v0.0.0-...-8e21e68 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorCodeUnknown = iota + 1000

	ErrorCodeDBEnv
	ErrorCodeDBConn
	ErrorCodeNoDBConn
	ErrorCodeWrongDBConn
	ErrorCodeDBTransaction

	ErrorCodeSignJWT
	ErrorCodeParseJWT

	ErrorCodeSendEmail

	ErrorCodeTmplExecute
	ErrorCodeTmplParse
)

Internal server error codes.

View Source
const (
	ErrorCodeBindJSON = iota + 2000

	ErrorCodeBadPage
	ErrorCodeBadPageSize

	ErrorCodeExpiredToken

	ErrorCodeInvalidPassword
)

Parameter error codes.

View Source
const (
	ErrorCodeNotFoundUser = iota + 3000
	ErrorCodeUserAlreadyExists
	ErrorCodeIncorrectPassword
	ErrorCodeSetPassword

	ErrorCodeOTPAlreadyRegistered
	ErrorCodeNoOTPSecretKey
	ErrorCodeIncorrectOTP
	ErrorCodeNoOTPBackupCodes
	ErrorCodeRequireVerifyOTP

	ErrorCodeOTPProvisioningURI
	ErrorCodeSetOTPBackupCodes
	ErrorCodeOTPNotRegistered
)

User data error codes.

View Source
const (
	ErrorCodeAuthorizedUser = iota + 4000
)

Authorized User error codes.

Variables

This section is empty.

Functions

func Authorize

func Authorize() gin.HandlerFunc

Authorize .

func AuthorizedUser

func AuthorizedUser(c *gin.Context) (user db.User, err error)

AuthorizedUser .

func AuthorizedUserIsAdmin

func AuthorizedUserIsAdmin() gin.HandlerFunc

AuthorizedUserIsAdmin .

func ChangePassword

func ChangePassword(c *gin.Context)

ChangePassword .

func ConfirmOTP

func ConfirmOTP(c *gin.Context)

ConfirmOTP .

func DBConnOrAbort

func DBConnOrAbort(c *gin.Context) *gorm.DB

DBConnOrAbort .

func DBConnection

func DBConnection() gin.HandlerFunc

DBConnection .

func DeleteUser

func DeleteUser(c *gin.Context)

DeleteUser .

func GenerateOTP

func GenerateOTP(c *gin.Context)

GenerateOTP .

func LogFormat

func LogFormat() gin.HandlerFunc

LogFormat .

func New

func New() http.Handler

New .

func Page

func Page(c *gin.Context) (int, error)

Page .

func PageSize

func PageSize(c *gin.Context) (int, error)

PageSize .

func RenewSession

func RenewSession(c *gin.Context)

RenewSession .

func RequestID

func RequestID() gin.HandlerFunc

RequestID .

func RequesterIsAuthorizedUser

func RequesterIsAuthorizedUser() gin.HandlerFunc

RequesterIsAuthorizedUser .

func ResetOTP

func ResetOTP(c *gin.Context)

ResetOTP .

func SendResetPasswordEmail

func SendResetPasswordEmail(c *gin.Context)

SendResetPasswordEmail .

func SendVerificationEmail

func SendVerificationEmail(c *gin.Context)

SendVerificationEmail .

func Signin

func Signin(c *gin.Context)

Signin .

func Signup

func Signup(c *gin.Context)

Signup .

func User

func User(c *gin.Context)

User .

func Users

func Users(c *gin.Context)

Users .

func VerifySignupToken

func VerifySignupToken(c *gin.Context)

VerifySignupToken .

Types

type ChangePasswordParam

type ChangePasswordParam struct {
	CurrentPassword string `json:"current_password" binding:"required"`
	Password        string `json:"password" binding:"required"`
}

ChangePasswordParam .

type ConfirmOTPParam

type ConfirmOTPParam struct {
	OTP string `json:"otp" binding:"required,numeric"`
}

ConfirmOTPParam .

type ErrorCodeResponse

type ErrorCodeResponse struct {
	ErrorCode    int    `json:"error_code"`
	ErrorMessage string `json:"error_message"`
	Links        []Link `json:"links"`
}

ErrorCodeResponse .

func NewErrRes

func NewErrRes(code int) ErrorCodeResponse

NewErrRes .

func NewErrResWithErr

func NewErrResWithErr(code int, err error) ErrorCodeResponse

NewErrResWithErr .

func NewErrResWithLinks(code int, links []Link) ErrorCodeResponse

NewErrResWithLinks .

type Link struct {
	Rel    string `json:"rel"`
	Method string `json:"method"`
	Href   string `json:"href"`
}

Link .

type ResetOTPParam

type ResetOTPParam struct {
	BackupCode string `json:"backup_code" binding:"required,numeric"`
}

ResetOTPParam .

type ResetPasswordEmailData

type ResetPasswordEmailData struct {
	UserEmail    string `json:"user_email"`
	ResetURL     string `json:"reset_url"`
	ExpireMin    int    `json:"expire_min"`
	Organization string `json:"organization"`
}

ResetPasswordEmailData .

type ResetPasswordEmailResponseForTest

type ResetPasswordEmailResponseForTest struct {
	ResetPasswordEmailData
	ResetPasswordToekn string `json:"reset_password_token"`
	Subject            string `json:"subject"`
	Body               string `json:"body"`
}

ResetPasswordEmailResponseForTest .

type SendEmailParam

type SendEmailParam struct {
	Email   string `json:"email" binding:"required,email"`
	Subject string `json:"subject" binding:"required"`
	Body    string `json:"body" binding:"required"`
}

SendEmailParam .

type SiginResponse

type SiginResponse struct {
	User  db.User `json:"user"`
	Token string  `json:"token"`
}

SiginResponse .

type SigninParam

type SigninParam struct {
	Email    string `json:"email" binding:"required"`
	Password string `json:"password" binding:"required"`
	OTP      string `json:"otp"`
}

SigninParam .

type SignupParam

type SignupParam struct {
	Token    string `json:"token" binding:"required"`
	Password string `json:"password" binding:"required"`
}

SignupParam .

type UsersResponse

type UsersResponse struct {
	Page     int       `json:"page"`
	PageSize int       `json:"page_size"`
	HasNext  bool      `json:"has_next"`
	Users    []db.User `json:"users"`
	Links    []Link    `json:"links"`
}

UsersResponse .

func (*UsersResponse) Adjust

func (r *UsersResponse) Adjust(pageSize int)

Adjust .

func (r *UsersResponse) AttachLinks(page, pageSize int, emails []string)

AttachLinks .

type VerificationEmailData

type VerificationEmailData struct {
	UserEmail    string `json:"user_email"`
	SignupURL    string `json:"signup_url"`
	ExpireMin    int    `json:"expire_min"`
	Organization string `json:"organization"`
}

VerificationEmailData .

type VerificationEmailResponseForTest

type VerificationEmailResponseForTest struct {
	VerificationEmailData
	SignupToken string `json:"signup_token"`
	Subject     string `json:"subject"`
	Body        string `json:"body"`
}

VerificationEmailResponseForTest .

Jump to

Keyboard shortcuts

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