user

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusInactive = iota
	StatusActive
	StatusBan

	StatusInactiveReason = "inactive"
	StatusActiveReason   = "active"
	StatusBanReason      = "banned"
)
View Source
const (
	TypeLocal = iota
	TypeOAuth
)

Variables

This section is empty.

Functions

func MustAdmin added in v0.0.6

func MustAdmin() gin.HandlerFunc

Types

type Controller

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

func NewController

func NewController() *Controller

func (*Controller) RegisterRoute

func (c *Controller) RegisterRoute(group *gin.RouterGroup)

type CustomClaims

type CustomClaims struct {
	User *User
	jwt.RegisteredClaims
}

type Group

type Group struct {
	ID     uuid.UUID `json:"id" gorm:"primary_key;type:uuid;" swaggerignore:"true" example:"00000000-0000-0000-0000-000000000000"`
	Title  string    `json:"title" gorm:"unique;not null" validate:"required"`
	Remark string    `json:"remark"`

	database.BaseModel
}

func (*Group) BeforeCreate

func (g *Group) BeforeCreate(tx *gorm.DB) error

func (*Group) TableName

func (g *Group) TableName() string

type JWTService

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

func GetJWTService

func GetJWTService() *JWTService

func NewJWTService

func NewJWTService(cfg *config.Config) *JWTService

func (*JWTService) CreateToken

func (s *JWTService) CreateToken(user *User) (string, error)

func (*JWTService) ParseToken

func (s *JWTService) ParseToken(tokenString string) (*User, error)

type ListUserResponse added in v0.0.6

type ListUserResponse struct {
	User
	Group string `json:"group"`
}

type LoginRequest added in v0.0.6

type LoginRequest struct {
	Username string `json:"username" validate:"required"`
	Password string `json:"password" validate:"required"`
}

type Relation

type Relation struct {
	ID      uuid.UUID `json:"id" gorm:"primary_key;type:uuid;" swaggerignore:"true" example:"00000000-0000-0000-0000-000000000000"`
	UserID  string    `json:"user_id" gorm:"not null" validate:"required"`
	GroupID uuid.UUID `json:"group_id" gorm:"not null;type:uuid;" validate:"required"`
}

func (*Relation) BeforeCreate added in v0.0.6

func (r *Relation) BeforeCreate(tx *gorm.DB) error

func (*Relation) TableName

func (r *Relation) TableName() string

type ResetPasswordRequest added in v0.0.6

type ResetPasswordRequest struct {
	Username string `json:"username" validate:"required"`
	Old      string `json:"old"`
	New      string `json:"new" validate:"required,min=6"`
}

type Service

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

func GetService

func GetService() *Service

func (*Service) AddUser

func (s *Service) AddUser(user *User) error

AddUser add user

func (*Service) DeleteUser

func (s *Service) DeleteUser(userID string) error

DeleteUser delete user

func (*Service) DetailUser

func (s *Service) DetailUser(userID string) (*User, error)

DetailUser detail user

func (*Service) GetAvailableOAuth

func (s *Service) GetAvailableOAuth() []oauth.AvailableOAuth

GetAvailableOAuth get available oauth

func (*Service) GetOAuthToken

func (s *Service) GetOAuthToken(authType string, code string) (token string, err error)

func (*Service) GetOAuthURL

func (s *Service) GetOAuthURL(authType string, redirectURL string) (string, error)

GetOAuthURL get oauth url

func (*Service) GetOAuthUserInfo

func (s *Service) GetOAuthUserInfo(authType string, code string) (*oauth.UserInfo, error)

GetOAuthUserInfo get user info

func (*Service) Initialize

func (s *Service) Initialize() error

func (*Service) ListUser

func (s *Service) ListUser(user *User) ([]*ListUserResponse, error)

ListUser list user

func (*Service) Login added in v0.0.6

func (s *Service) Login(user *LoginRequest) (string, error)

func (*Service) ResetPassword added in v0.0.6

func (s *Service) ResetPassword(user *ResetPasswordRequest, IsAdmin bool) error

func (*Service) SetUserStatus added in v0.0.6

func (s *Service) SetUserStatus(user *User, status int) error

func (*Service) UpdateUser

func (s *Service) UpdateUser(user *User) error

UpdateUser update user

type Uid added in v0.0.6

type Uid struct {
	ID string `json:"id" binding:"required"`
}

type User

type User struct {
	ID           string `json:"id" gorm:"primary_key;" swaggerignore:"true"`
	Username     string `json:"username" gorm:"unique;not null" validate:"required"`
	Nickname     string `json:"nickname" validate:"required"`
	Password     string `json:"-"`
	Avatar       string `json:"avatar"`
	Email        string `json:"email" validate:"required"`
	Phone        string `json:"phone"`
	Type         int    `json:"type"`
	Status       int    `json:"status"`
	StatusReason string `json:"statusReason"`

	database.BaseModel
}

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) error

func (*User) IsAdmin added in v0.0.6

func (u *User) IsAdmin() bool

func (*User) IsBanned added in v0.0.6

func (u *User) IsBanned() bool

func (*User) TableName

func (u *User) TableName() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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