auth

package
v0.0.0-...-c9b56a8 Latest Latest
Warning

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

Go to latest
Published: May 9, 2021 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Overview

用户认证 ( authentication ) 与授权 ( authorization ) 模块

通证 ( Token ) 相关。

通证 ( Token ): 当客户端用户登陆成功后,系统会向该客户端用户签发一定有效期的 token,之后客户端用户每次请求的时候,都需要在请求头部携带该 token, 以标示自己的用户身份。

Index

Constants

This section is empty.

Variables

View Source
var SMSLogin *smsLogin

Functions

func SetupSMSLogin

func SetupSMSLogin(sender func(phoneNumber int64, code string) error, rds *redis.Client)

初始化 SMSLogin 控制器

Types

type TokenUser

type TokenUser struct {
	// 用户 ID
	ID int64 `json:"i"`

	// Token 失效时间
	ExpiresAt int64 `json:"e"`

	// 用户角色
	Roles []int64 `json:"r"`

	// 用户权限
	Perms    []int64 `json:"p"`
	Settings int64   `json:"s"`
}

TokenUser: 编码在 token 字符串中的用户信息

func ExtractTokenUser

func ExtractTokenUser(ctx *rpc.Context) (user TokenUser, err error)

http.Request 中解析 TokenUser

func NewTokenUser

func NewTokenUser(u *models.User) (*TokenUser, error)

从 models.User 获得 TokenUser

func (*TokenUser) Encode

func (t *TokenUser) Encode() string

func (*TokenUser) IsAnon

func (u *TokenUser) IsAnon() bool

是否是匿名用户 (即未登陆用户)

func (*TokenUser) User

func (u *TokenUser) User(tx *gorm.DB) *models.User

使用 TokenUser 获取 models.User

Directories

Path Synopsis
数据库模型定义
数据库模型定义
用于配制和初始化 auth 模块
用于配制和初始化 auth 模块

Jump to

Keyboard shortcuts

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