auth

package
v0.33.19 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: AGPL-3.0, AGPL-3.0-only Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserGroupAdmin uint8 = iota + 1
	UserGroupBangumiAdmin
	UserGroupWindowAdmin
	UserGroupQuite
	UserGroupBanned

	UserGroupCharacterAdmin
	UserGroupWikiAdmin
	UserGroupNormal
	UserGroupWikiEditor
)
View Source
const TokenTypeAccessToken = 1
View Source
const TokenTypeOauthToken = 0

Variables

This section is empty.

Functions

func AllowReadCharacter added in v0.22.0

func AllowReadCharacter(u Auth, c model.Character) bool

func AllowReadSubject added in v0.22.0

func AllowReadSubject(u Auth, s model.Subject) bool

Types

type AccessToken added in v0.30.3

type AccessToken struct {
	ExpiredAt time.Time
	CreatedAt time.Time
	Name      string
	ClientID  string
	ID        uint32
	UserID    model.UserID
}

type Auth added in v0.30.3

type Auth struct {
	Login      bool
	RegTime    time.Time
	ID         model.UserID // user id
	GroupID    user.GroupID
	Permission Permission `json:"-"` // disable cache for this field.
}

Auth is the basic authorization represent a user.

func (Auth) AllowNSFW added in v0.30.3

func (u Auth) AllowNSFW() bool

AllowNSFW return if current user is allowed to see NSFW resource.

func (Auth) RegisteredLongerThan added in v0.30.3

func (u Auth) RegisteredLongerThan(t time.Duration) bool

type Permission added in v0.30.3

type Permission struct {
	UserList           bool
	ManageUserGroup    bool
	ManageUserPhoto    bool
	ManageTopicState   bool
	ManageReport       bool
	UserBan            bool
	ManageUser         bool
	UserGroup          bool
	UserWikiApply      bool `doc:"申请 wiki 人"`
	UserWikiApprove    bool
	DoujinSubjectErase bool
	DoujinSubjectLock  bool
	SubjectEdit        bool
	SubjectLock        bool
	SubjectRefresh     bool
	SubjectRelated     bool
	SubjectMerge       bool
	SubjectErase       bool
	SubjectCoverLock   bool
	SubjectCoverErase  bool
	MonoEdit           bool
	MonoLock           bool
	MonoMerge          bool
	MonoErase          bool
	BanPost            bool
	EpEdit             bool
	EpMove             bool
	EpMerge            bool
	EpLock             bool
	EpErase            bool
	Report             bool
	ManageApp          bool
	AppErase           bool
}

type Repo added in v0.30.3

type Repo interface {
	// GetByToken return an authorized user by a valid access token.
	GetByToken(ctx context.Context, token string) (UserInfo, error)
	GetPermission(ctx context.Context, groupID uint8) (Permission, error)

	CreateAccessToken(
		ctx context.Context, userID model.UserID, name string, expiration time.Duration,
	) (token string, err error)

	ListAccessToken(ctx context.Context, userID model.UserID) ([]AccessToken, error)
	DeleteAccessToken(ctx context.Context, tokenID uint32) (bool, error)

	// GetByEmail return (Auth, HashedPassword, error)
	GetByEmail(ctx context.Context, email string) (UserInfo, []byte, error)
	GetTokenByID(ctx context.Context, id uint32) (AccessToken, error)
}

AuthRepo presents an authorization.

func NewMysqlRepo

func NewMysqlRepo(q *query.Query, log *zap.Logger) Repo

type Service added in v0.30.3

type Service interface {
	GetByToken(ctx context.Context, token string) (Auth, error)
	GetByID(ctx context.Context, userID model.UserID) (Auth, error)

	ComparePassword(hashed []byte, password string) (bool, error)

	Login(ctx context.Context, email, password string) (Auth, bool, error)

	GetTokenByID(ctx context.Context, tokenID uint32) (AccessToken, error)
	CreateAccessToken(
		ctx context.Context, userID model.UserID, name string, expiration time.Duration,
	) (token string, err error)
	ListAccessToken(ctx context.Context, userID model.UserID) ([]AccessToken, error)
	DeleteAccessToken(ctx context.Context, tokenID uint32) (bool, error)
}

func NewService

func NewService(repo Repo, u user.Repo, logger *zap.Logger, c cache.RedisCache) Service

type TokenInfo added in v0.18.0

type TokenInfo struct {
	CreatedAt time.Time `json:"created_at"`
	Name      string    `json:"name"`
}

type UserInfo added in v0.30.3

type UserInfo struct {
	RegTime time.Time
	ID      model.UserID
	GroupID user.GroupID
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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