sql

package
v0.0.0-...-aeca20e Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BadUserError = errors.New("bad user name & password")

Functions

func AddEmail

func AddEmail(db *sql.DB, user *User, email EmailRecord) error

func DelEmail

func DelEmail(db *sql.DB, user *User, email string) error

func Feedback

func Feedback(db *sql.DB, user *User, now int64, text string) error

func ParseSocialKey

func ParseSocialKey(socialkey []byte) (service, id string)

func SetLogin

func SetLogin(db *sql.DB, user *User, username, password string) error

Set local login for a social-login user

func SetUserPassword

func SetUserPassword(db *sql.DB, user *User) error

func SetUserPrefs

func SetUserPrefs(db *sql.DB, user *User) error

func SocialKey

func SocialKey(service, uid string) string

Types

type EmailMetadata

type EmailMetadata struct {
	Validated bool
	Added     int64 // unix timestamp
	Data      map[string]interface{}
}

type EmailRecord

type EmailRecord struct {
	Email string
	EmailMetadata
}

func NewEmail

func NewEmail(email string) EmailRecord

type PrefsBlob

type PrefsBlob struct {
	DisplayName string                 `json:"dn,omitempty"`
	Data        map[string]interface{} `json:"d,omitempty"`
}

type User

type User struct {
	// primary key
	Guid int64

	// goog, fb, twit, etc.
	Social []UserSocial

	// Local Username must be unique across local users
	Username string
	Password []byte

	// lost password recovery, notifications
	Email []EmailRecord

	// What we show them when we talk to them. "Hi, ____"
	// Need not be unique.
	DisplayName string

	// Serialized by encoding/json or similar
	Data map[string]interface{}
}

func (*User) BestDisplayName

func (u *User) BestDisplayName() string

func (*User) GoodPassword

func (u *User) GoodPassword(qpw string) bool

func (*User) HasEmail

func (u *User) HasEmail(email string) bool

func (*User) HasLocalUser

func (u *User) HasLocalUser() bool

mostly for use in templates

func (*User) SetPassword

func (u *User) SetPassword(npw string) error

type UserDB

type UserDB interface {
	// Setup will create or mirgate tables
	Setup() error

	PutNewUser(nu *User) (*User, error)

	GetUser(guid int64) (*User, error)
	GetLocalUser(username string) (*User, error)
	GetSocialUser(service, id string) (*User, error)

	// copy misc data out of User struct into preferences
	SetUserPrefs(user *User) error
	SetUserPassword(user *User) error

	// Set local login for a social-login user
	SetLogin(user *User, username, password string) error

	AddEmail(user *User, email EmailRecord) error
	DelEmail(user *User, email string) error

	Feedback(user *User, now int64, text string) error
}

Actions on users: new user (with local/social/email) disable user delete user

add local login to user update user local password update user prefs

add/del email to user set metadata for email

add/del social login to user set metadata for social

func NewSqlUserDB

func NewSqlUserDB(db *sql.DB) UserDB

type UserSocial

type UserSocial struct {
	Service string
	Id      string
	Data    interface{}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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