passport

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package passport 验证系统

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExists = errors.New("user already exists")

	ErrUnauthorized = errors.New("unauthorized")
)

Functions

func Install

func Install(mod string, db *orm.DB)

Types

type Func

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

func (*Func) Add

func (p *Func) Add(tx *orm.Tx, uid int64, username string) error

Add 添加账号

将 uid 与 username 作关联

func (*Func) Delete

func (p *Func) Delete(tx *orm.Tx, uid int64) error

Delete 删除关联信息

func (*Func) Valid

func (p *Func) Valid(tx *orm.Tx, username, pass string) (int64, error)

Valid 验证登录正确性并返回其 uid

type OAuth

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

TODO: openid

func (*OAuth) AuthorizeURL

func (a *OAuth) AuthorizeURL() string

func (*OAuth) Receive

func (o *OAuth) Receive(ctx *web.Context) web.Responser

Receive 接口令牌

type Passport

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

Passport 当前模块对外公开的接口

func New

func New(mod string, db *orm.DB) *Passport

func (*Passport) Func

func (p *Passport) Func(t string, f func(string, string) bool) *Func

Func 以函数的方式验证账号密码

f 用于验证账号和密码的正确性。

func (*Passport) OAuth

func (p *Passport) OAuth(vendor, id, secret, authURL, tokenURL, redirectURL string) *OAuth

OAuth 添加以 OAuth 验证的方式

vendor OAuth 提供的商家 ID; authURL 为第三方验证登录页面; tokenURL 为从第三方获取 access_token 的页面; redirectURL 为传递给 authURL 的跳转页面;

func (*Passport) Password

func (p *Passport) Password(t string) *Password

Password 返回处理密码登录的对象

t 表示类型,比如同一个用户可能有登录密码和支付密码等,那么通过 t 可以区分这些密码。

type Password

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

func (*Password) Add

func (p *Password) Add(tx *orm.Tx, uid int64, username, pass string) error

Add 添加账号

如果 tx 为空,那么将采用 orm.DB 访问数据库。

func (*Password) Change

func (p *Password) Change(tx *orm.Tx, uid int64, old, pass string) error

func (*Password) Delete

func (p *Password) Delete(tx *orm.Tx, uid int64) error

Delete 删除关联的密码信息

func (*Password) Set

func (p *Password) Set(tx *orm.Tx, uid int64, pass string) error

Set 修改密码

func (*Password) Valid

func (p *Password) Valid(tx *orm.Tx, username, pass string) (int64, error)

Valid 验证登录正确性并返回其 uid

Jump to

Keyboard shortcuts

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