uranium

package module
v0.0.0-...-6a53fb6 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2021 License: AGPL-3.0 Imports: 14 Imported by: 0

README

ushio

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRecaptchaFailed  = NewError(1001, http.StatusBadRequest, "Recaptcha failed.")
	ErrUsernameNotFound = NewError(1002, http.StatusNotFound, "Username(email) not found.")
	ErrWrongPassword    = NewError(1003, http.StatusUnauthorized, "Password is not correct.")
	ErrUserLocked       = NewError(1004, http.StatusUnauthorized, "User has been locked or disabled.")
	ErrInvalidTokenType = NewError(1005, http.StatusUnauthorized, "Invalid token type.")
)

========================= AUTH =============================

View Source
var (
	// When token is need but no token found.
	ErrTokenRequired = NewError(1006, http.StatusUnauthorized, "Token required.")
	// When the action requires sudo permission but no sudo token found.
	ErrSudoTokenRequired = NewError(1007, http.StatusUnauthorized, "Sudo token required.")
	// When the action requires admin permission but no admin token found.
	ErrAdminTokenRequired = NewError(1008, http.StatusUnauthorized, "Admin token required.")
	// When the resource is only available to mod/admin, then return this error.
	ErrNoPermission = NewError(1009, http.StatusForbidden, "No permission to the resource.")

	// When token can be found in user request but cannot be found in database.
	ErrInvalidToken = NewError(1010, http.StatusUnauthorized, "Invalid token.")
	// When token can be found in user request and in database, but has been expired.
	ErrTokenExpired = NewError(1011, http.StatusUnauthorized, "Token has been expired.")

	// When sudo token found in user request but cannot be found in database.
	ErrInvalidSudoToken = NewError(1012, http.StatusUnauthorized, "Invalid sudo token.")
	// When sudo token found in user request and in database, but has been expired.
	ErrSudoTokenExpired = NewError(1013, http.StatusUnauthorized, "Sudo token has been expired.")

	// When mod token found in user request but cannot be found in database.
	ErrInvalidModToken = NewError(1014, http.StatusUnauthorized, "Invalid mod token.")
	// When mod token found in user request and in database, but has been expired.
	ErrModTokenExpired = NewError(1015, http.StatusUnauthorized, "Mod token has been expired.")

	// When admin token found in user request but cannot be found in database.
	ErrInvalidAdminToken = NewError(1016, http.StatusUnauthorized, "Invalid admin token.")
	// When admin token found in user request and in database, but has been expired.
	ErrAdminTokenExpired = NewError(1017, http.StatusUnauthorized, "Admin token has been expired.")
)

========================= TOKEN ============================= In normal cases, user shouldn't meet these errors, unless they have modified their cookies.

View Source
var (
	ErrInvalidUID   = NewError(1018, http.StatusBadRequest, "Invalid UID.")
	ErrUserNotFound = NewError(1019, http.StatusNotFound, "User not found.")
)

========================= USER =============================

View Source
var WipeCookieExpires = time.Date(2000, 1, 1, 8, 0, 0, 0, time.UTC)

Functions

This section is empty.

Types

type Config

type Config struct {
	SiteName        string
	SiteURL         string
	LoginRecaptcha  bool
	SignUpRecaptcha bool
}

type Error

type Error struct {
	StatusCode int    `json:"-"`
	Code       int    `json:"code"`
	Err        bool   `json:"err"`
	Msg        string `json:"msg"`
}

func NewError

func NewError(code, status int, msg string) *Error

func (*Error) Error

func (e *Error) Error() string

type SuccessResp

type SuccessResp struct {
	Success bool `json:"success"`
}

type Uranium

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

func New

func New(s storage.Provider, c cache.Cacher, mail sendmail.Sender, conf Config) (*Uranium, error)

func (*Uranium) AuthAdminOnly

func (uranium *Uranium) AuthAdminOnly(ctx *fiber.Ctx) error

func (*Uranium) AuthSudoAndAdmin

func (uranium *Uranium) AuthSudoAndAdmin(ctx *fiber.Ctx) (int16, error)

AuthSudoAndAdmin validates the cookie "token_sudo" and "token_admin", it matches the resource which can be accessed by user in sudo mode and super admin.

func (*Uranium) AuthUser

func (uranium *Uranium) AuthUser(ctx *fiber.Ctx) error

AuthUser validates the cookie "token", it matches the resource which can be accessed by every user.

func (*Uranium) HandleTestPassword

func (uranium *Uranium) HandleTestPassword(ctx *fiber.Ctx) error

func (*Uranium) HandleTestSession

func (uranium *Uranium) HandleTestSession(ctx *fiber.Ctx) error

func (*Uranium) HandleUserAuthByUID

func (uranium *Uranium) HandleUserAuthByUID(ctx *fiber.Ctx) error

func (*Uranium) HandleUserBasicByUID

func (uranium *Uranium) HandleUserBasicByUID(ctx *fiber.Ctx) error

func (*Uranium) HandleUserInfoByUID

func (uranium *Uranium) HandleUserInfoByUID(ctx *fiber.Ctx) error

func (*Uranium) HandleUserInfoByUsername

func (uranium *Uranium) HandleUserInfoByUsername(ctx *fiber.Ctx) error

func (*Uranium) HandleUserLogin

func (uranium *Uranium) HandleUserLogin(ctx *fiber.Ctx) error

func (*Uranium) HandleUserProfileByUID

func (uranium *Uranium) HandleUserProfileByUID(ctx *fiber.Ctx) error

func (*Uranium) HandleUserProfileByUsername

func (uranium *Uranium) HandleUserProfileByUsername(ctx *fiber.Ctx) error

func (*Uranium) RouteForFiber

func (uranium *Uranium) RouteForFiber(app *fiber.App)

type UserLoginReq

type UserLoginReq struct {
	Username  string `json:"username"`
	Password  []byte `json:"password"`
	IsEmail   bool   `json:"is_email"`
	Remember  bool   `json:"remember"`
	Recaptcha string `json:"recaptcha"`
	Type      int16  `json:"type"`
}

Jump to

Keyboard shortcuts

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