internal

package
v0.0.0-...-a0d1ad3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2022 License: MIT, Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccountsTable = "accounts"
	ActorsTable   = "actors"
)
View Source
const (
	UsernameAlreadyExists = "THE_USERNAME_ALREADY_EXISTS"
)

Variables

This section is empty.

Functions

func Run

func Run() error

Types

type Account

type Account interface {
	// IsExist Determine if the account exists.
	IsExist() bool

	// Create need to verify whether the username and email address have been registered or not,
	// and return an error if they have been registered.
	// publicKey is account auth public key not activitypub public key.
	Create(publicKey string) error

	// Delete Verify that the account is correct first, then delete the account by ID.
	Delete() error

	// EditUsername Edit username.
	EditUsername(username string) error

	// EditPassword Edit the password.
	EditPassword(newPassword string) error

	// EditEmail Editorial email.
	EditEmail(mail string) error

	// Verify that the account password is correct, used to verify when logging in or changing the password,
	// pass the password sent and then compare the password queried in the database.
	Verify(password string) (*Accounts, error)

	// GetPrivateKey When performing activitypub activities,
	// you need to obtain the private key for signing and other operations.
	GetPrivateKey() (string, error)

	GetAccountByUsername() (*Accounts, error)
}

type Accounts

type Accounts struct {
	gorm.Model

	// Username As the primary key of the database, it cannot be duplicated.
	Username string `gorm:"primaryKey;type:text;username;unique" validate:"required,min=4,max=16"`

	// Mail must ensure that the email is unique and properly formatted and cannot be empty.
	// When the user forgets the password, the user is required to provide an email which is unique.
	// Therefore, when registering, the user must provide an email.
	Mail string `gorm:"index;type:text;mail;unique" validate:"required,email"`

	// Password
	// The length of the password must be greater than 8 characters and
	// less than 24 characters, and must not contain spaces.
	Password string `gorm:"type:text;password" validate:"required,min=8,max=24"`

	// When creating a user, an actor needs to be created to record the basic information
	// of the user for compatibility with the ActivityPub protocol.
	// The ActorID field is the id of the actor and is used to associate the actor.
	ActorID uint `gorm:"type:bigint;actor_id"`

	// IsPrivate Set whether the account is private or not, private accounts are not displayed publicly.
	IsPrivate bool `gorm:"type:boolean;is_private"`

	// PrivateKey The private key corresponding to the Activitypub protocol is used
	// only for social activities and no other encryption is involved.
	PrivateKey string `gorm:"type:text;private_key"`
}

func NewAccounts

func NewAccounts(actorID uint, username, mail, password, privateKey string) *Accounts

NewAccounts This constructor is needed to formally create a complete account in the Create Account method.

func NewAccountsCreate

func NewAccountsCreate(username, mail, password string) *Accounts

NewAccountsCreate Constructor for creating an account.

func NewAccountsDelete

func NewAccountsDelete(username, password string) *Accounts

NewAccountsDelete Constructor for deleting an account.

func NewAccountsID

func NewAccountsID(id uint) *Accounts

NewAccountsID Constructing an account ID.

func NewEditPassword

func NewEditPassword(username, password string) *Accounts

NewEditPassword Constructor for editing an account's password.

func NewUsername

func NewUsername(username string) *Accounts

NewUsername constructor account's username.

func NewVerify

func NewVerify(username string) *Accounts

NewVerify Constructor for verifying an account.

func (*Accounts) Create

func (a *Accounts) Create(publicKey string) error

func (*Accounts) Delete

func (a *Accounts) Delete() error

func (*Accounts) EditEmail

func (a *Accounts) EditEmail(mail string) error

func (*Accounts) EditPassword

func (a *Accounts) EditPassword(new string) error

func (*Accounts) EditUsername

func (a *Accounts) EditUsername(username string) error

func (*Accounts) GetAccountByUsername

func (a *Accounts) GetAccountByUsername() (*Accounts, error)

func (*Accounts) GetPrivateKey

func (a *Accounts) GetPrivateKey() (string, error)

func (*Accounts) IsExist

func (a *Accounts) IsExist() bool

func (*Accounts) Verify

func (a *Accounts) Verify(password string) (*Accounts, error)

Jump to

Keyboard shortcuts

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