user

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ENCRYPTION_TIMES = 10000

Variables

This section is empty.

Functions

func GenerateUsername

func GenerateUsername(n int) string

func GetUser

func GetUser(ctx iris.Context) (*auth.User, error)

从 ctx获取 User

func LoginRequire

func LoginRequire(ctx iris.Context)

从 ctx获取 User

func MakePassword

func MakePassword(password string) string

func Register

func Register(app *iris.Application, apiPrefix string)

func UserAuth added in v0.1.9

func UserAuth(ctx iris.Context) *auth.User

Types

type AuthUser

type AuthUser struct {
	Id          string                `json:"id" gorm:"primaryKey"`
	Password    string                `json:"password"`
	Username    string                `json:"username" gorm:"unique"`
	IsSuperuser bool                  `json:"is_superuser"`
	Phone       string                `json:"phone"`
	IsActive    bool                  `json:"is_active"`
	CreatedAt   datatypes.IRFTime     `json:"created_at" gorm:"autoCreateTime"`
	IsDel       soft_delete.DeletedAt `json:"is_del" gorm:"softDelete:flag"`
}

用户表 实现 auth.IUserModel

func CreateAuthUser

func CreateAuthUser(phone string, password string, isAdmin bool) (*AuthUser, error)

func GetUserModel

func GetUserModel(ctx iris.Context) (*AuthUser, error)

从 ctx获取 User

func (*AuthUser) GetByID added in v0.1.9

func (u *AuthUser) GetByID(id string) error

根据 id查询出来 user model

func (*AuthUser) GetByPwd

func (u *AuthUser) GetByPwd(phone string, pwd string) error

根据用户名的密码获取User对象

func (*AuthUser) GetID

func (u *AuthUser) GetID() string

实现 auth.IUserModel

func (*AuthUser) Save

func (u *AuthUser) Save() error

根据用户名的密码获取User对象

type IUserController added in v0.1.9

type IUserController interface {
	PostLoginbypwd(ctx iris.Context) response.IRFResult   // 手机密码登录
	Get(ctx iris.Context) response.IRFResult              // 获取登录用户的信息
	GetBy(ctx iris.Context, id string) response.IRFResult // 根据用户id获取用户信息
}

func NewUserController added in v0.1.9

func NewUserController() IUserController

type LoginByPwdSerializer

type LoginByPwdSerializer struct {
	Phone    string `json:"phone" validate:"number,len=11"`
	Password string `json:"password" validate:"min=6,max=12"`
}

手机号登录

type UserController added in v0.1.9

type UserController struct {
}

func (*UserController) BeforeActivation added in v0.1.9

func (c *UserController) BeforeActivation(b mvc.BeforeActivation)

添加 LoginRequire 中间件

func (*UserController) Get added in v0.1.9

func (c *UserController) Get(ctx iris.Context) response.IRFResult

@Summary 根据用户id获取用户信息 @Tags auth @Accept json @Description ### 返回:200 @Router /user [get]

func (*UserController) GetBy added in v0.1.9

func (c *UserController) GetBy(ctx iris.Context, id string) response.IRFResult

func (*UserController) PostLoginbypwd added in v0.1.9

func (c *UserController) PostLoginbypwd(ctx iris.Context) response.IRFResult

@Summary 根据用户手机号和密码获取 token @Tags user @Accept json @Description ### 返回:200 @Description ``` @Description { @Description "code": 0 @Description "data": { @Description "token": "eameeljfaldkfaldkf.alkfjelfkelfe.alekfjelfjkelfjelfj" @Description }, @Description } @Description ``` @Router /user [post]

Jump to

Keyboard shortcuts

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