models

package
v0.0.0-...-1fabf49 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func CodeMessage

func CodeMessage(code MCode) string

func CountAccounts

func CountAccounts() (int64, error)

func CountApplications

func CountApplications() (int64, error)

func PutAccount

func PutAccount(model *AccountModel) error

func PutSession

func PutSession(model *SessionModel) error

func UnmarshalWebauthnSession

func UnmarshalWebauthnSession(session string) (*webauthn.SessionData, error)

func UpdateAccountCredentials

func UpdateAccountCredentials(model *WebauthnAccount) error

func UpdateAccountPassword

func UpdateAccountPassword(pk string, password string) error

func UpdateAccountSession

func UpdateAccountSession(model *AccountModel, sessionData *webauthn.SessionData) error

Types

type AccountModel

type AccountModel struct {
	Pk          string    `json:"pk"`       // 主键标识
	Username    string    `json:"username"` // 账号
	Password    string    `json:"-"`        // 密码
	Photo       string    `json:"-"`        // 密码
	CreateTime  time.Time `json:"create_time" db:"create_time"`
	UpdateTime  time.Time `json:"update_time" db:"update_time"`
	Nickname    string    `json:"nickname"`
	Mail        string    `json:"mail"`
	Credentials string    `json:"-"`
	Session     string    `json:"-"`
	Description string    `json:"description"`
	Status      int       `json:"status"`
}

AccountModel 账号模型 table: accounts

func GetAccount

func GetAccount(pk string) (*AccountModel, error)

func GetAccountByUsername

func GetAccountByUsername(username string) (*AccountModel, error)

func NewAccountModel

func NewAccountModel(name string, displayName string) *AccountModel

func SelectAccounts

func SelectAccounts(offset int, limit int) ([]*AccountModel, error)

type AccountSchema

func NewAccountSchema

func NewAccountSchema() AccountSchema

func (AccountSchema) GetConditions

func (r AccountSchema) GetConditions() []datastore.ModelCondition

type ApplicationModel

type ApplicationModel struct {
	Pk             string    `json:"pk"` // 主键标识
	Id             string    `json:"id"` // 账号
	Secret         string    `json:"-"`
	RotatedSecrets string    `json:"-" db:"rotated_secrets"`
	RedirectUris   string    `json:"-" db:"redirect_uris"`
	ResponseTypes  string    `json:"-" db:"response_types"`
	GrantTypes     string    `json:"-" db:"grant_types"`
	Scopes         string    `json:"-"`
	Audience       string    `json:"-"`
	Creator        string    `json:"creator"`
	Title          string    `json:"title"`
	CreateTime     time.Time `json:"create_time" db:"create_time"`
	UpdateTime     time.Time `json:"update_time" db:"update_time"`
	Description    string    `json:"description"`
}

func GetApplication

func GetApplication(pk string) (*ApplicationModel, error)

func NewApplicationModel

func NewApplicationModel(title string) *ApplicationModel

func SelectApplications

func SelectApplications(offset int, limit int) ([]*ApplicationModel, error)

type ClientModel

type ClientModel struct {
	ID             string   `json:"id"`
	Secret         []byte   `json:"client_secret,omitempty"`
	RotatedSecrets [][]byte `json:"rotated_secrets,omitempty"`
	RedirectURIs   []string `json:"redirect_uris"`
	GrantTypes     []string `json:"grant_types"`
	ResponseTypes  []string `json:"response_types"`
	Scopes         []string `json:"scopes"`
	Audience       []string `json:"audience"`
	Public         bool     `json:"public"`
}

func GetClient

func GetClient(id string) (*ClientModel, error)

func (*ClientModel) GetAudience

func (c *ClientModel) GetAudience() fosite.Arguments

func (*ClientModel) GetGrantTypes

func (c *ClientModel) GetGrantTypes() fosite.Arguments

func (*ClientModel) GetHashedSecret

func (c *ClientModel) GetHashedSecret() []byte

func (*ClientModel) GetID

func (c *ClientModel) GetID() string

func (*ClientModel) GetRedirectURIs

func (c *ClientModel) GetRedirectURIs() []string

func (*ClientModel) GetResponseTypes

func (c *ClientModel) GetResponseTypes() fosite.Arguments

func (*ClientModel) GetRotatedHashes

func (c *ClientModel) GetRotatedHashes() [][]byte

func (*ClientModel) GetScopes

func (c *ClientModel) GetScopes() fosite.Arguments

func (*ClientModel) IsPublic

func (c *ClientModel) IsPublic() bool

type ClientTable

type ClientTable struct {
	Pk             string         `json:"pk"`
	ID             string         `json:"id"`
	Secret         string         `json:"secret"`
	RotatedSecrets sql.NullString `json:"rotated_secrets" db:"rotated_secrets"`
	RedirectURIs   sql.NullString `json:"redirect_uris" db:"redirect_uris"`
	GrantTypes     sql.NullString `json:"grant_types" db:"grant_types"`
	ResponseTypes  sql.NullString `json:"response_types" db:"response_types"`
	Scopes         sql.NullString `json:"scopes"`
	Audience       sql.NullString `json:"audience"`
	Public         sql.NullInt32  `json:"public"`
}

func (*ClientTable) ToModel

func (t *ClientTable) ToModel() *ClientModel

type CommonResult

type CommonResult struct {
	Code    MCode       `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

func NewCommonResult

func NewCommonResult(code MCode, message string, data interface{}) *CommonResult

func ParseCommonResult

func ParseCommonResult(data interface{}) *CommonResult

func (*CommonResult) SetCode

func (r *CommonResult) SetCode(code MCode) *CommonResult

func (*CommonResult) SetMessage

func (r *CommonResult) SetMessage(message string) *CommonResult

type MCode

type MCode int
const (
	CodeOk               MCode = 200
	CodeError            MCode = 500
	CodeAccountExists    MCode = 600 // 账号已存在
	CodeAccountNotExists MCode = 601 // 账号不存在
	CodeNotLogin         MCode = 602
	CodeInvalidParameter MCode = 603
	CodeNotFound         MCode = 404
	StatusAccountExists  MCode = 607 // 账号已存在
	CodeInvalidParams    MCode = 609 // 参数无效
)

func (MCode) String

func (c MCode) String() string

func (MCode) ToResult

func (c MCode) ToResult() *CommonResult

func (MCode) WithData

func (c MCode) WithData(data interface{}) *CommonResult

func (MCode) WithError

func (c MCode) WithError(err error) *CommonResult

func (MCode) WithMessage

func (c MCode) WithMessage(message string) *CommonResult

type PermissionModel

type PermissionModel struct {
	Pk          string    `json:"pk"`
	Name        string    `json:"name"`
	CreateTime  time.Time `json:"create_time" db:"create_time"`
	UpdateTime  time.Time `json:"update_time" db:"update_time"`
	Description string    `json:"description"`
}

PermissionModel 权限模型 table: permissions

type PermissionSchema

type PermissionSchema struct {
	Pk          datastore.ModelCondition
	Name        datastore.ModelCondition
	CreateTime  datastore.ModelCondition
	UpdateTime  datastore.ModelCondition
	Description datastore.ModelCondition
}

func NewPermissionSchema

func NewPermissionSchema() PermissionSchema

func (PermissionSchema) GetConditions

func (r PermissionSchema) GetConditions() []datastore.ModelCondition

type RoleModel

type RoleModel struct {
	Pk          string    `json:"pk"`
	Name        string    `json:"name"`
	CreateTime  time.Time `json:"create_time" db:"create_time"`
	UpdateTime  time.Time `json:"update_time" db:"update_time"`
	Description string    `json:"description"`
}

RoleModel table: roles

type RoleSchema

type RoleSchema struct {
	Pk          datastore.ModelCondition
	Name        datastore.ModelCondition
	CreateTime  datastore.ModelCondition
	UpdateTime  datastore.ModelCondition
	Description datastore.ModelCondition
}

func NewRoleSchema

func NewRoleSchema() RoleSchema

func (RoleSchema) GetConditions

func (r RoleSchema) GetConditions() []datastore.ModelCondition

type SessionModel

type SessionModel struct {
	Pk         string         `json:"pk"`
	Content    string         `json:"content"`
	CreateTime time.Time      `json:"create_time" db:"create_time"`
	UpdateTime time.Time      `json:"update_time" db:"update_time"`
	User       string         `json:"user"`
	Type       string         `json:"type"`
	Code       sql.NullString `json:"code"`
}

func GetSession

func GetSession(pk string) (*SessionModel, error)

type WebauthnAccount

type WebauthnAccount struct {
	AccountModel
	WebauthnCredentials
}

func CopyWebauthnAccount

func CopyWebauthnAccount(account *AccountModel) *WebauthnAccount

func NewWebauthnAccount

func NewWebauthnAccount(name string, displayName string) *WebauthnAccount

func (*WebauthnAccount) AddCredential

func (u *WebauthnAccount) AddCredential(cred webauthn.Credential)

AddCredential associates the credential to the user

func (*WebauthnAccount) CredentialExcludeList

func (u *WebauthnAccount) CredentialExcludeList() []protocol.CredentialDescriptor

CredentialExcludeList returns a CredentialDescriptor array filled with all the user's credentials

func (*WebauthnAccount) MarshalCredentials

func (model *WebauthnAccount) MarshalCredentials() (string, error)

func (*WebauthnAccount) WebAuthnCredentials

func (u *WebauthnAccount) WebAuthnCredentials() []webauthn.Credential

WebAuthnCredentials returns credentials owned by the user

func (*WebauthnAccount) WebAuthnDisplayName

func (u *WebauthnAccount) WebAuthnDisplayName() string

WebAuthnDisplayName returns the user's display name

func (*WebauthnAccount) WebAuthnID

func (u *WebauthnAccount) WebAuthnID() []byte

WebAuthnID returns the user's ID

func (*WebauthnAccount) WebAuthnIcon

func (u *WebauthnAccount) WebAuthnIcon() string

WebAuthnIcon is not (yet) implemented

func (*WebauthnAccount) WebAuthnName

func (u *WebauthnAccount) WebAuthnName() string

WebAuthnName returns the user's username

type WebauthnCredentials

type WebauthnCredentials struct {
	CredentialsSlice []webauthn.Credential
}

Jump to

Keyboard shortcuts

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