models

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2018 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HasEngine bool

	DbCfg struct {
		Type, Host, Name, User, Passwd, Path, SSLMode string
	}

	EnableSQLite3 bool
)

Vars

Functions

func CountUsers

func CountUsers() int64

CountUsers returns number of users.

func CreateGitxt

func CreateGitxt(g *Gitxt) (err error)

CreateGitxt Create a new gitxt

func CreateUser

func CreateUser(u *User) (err error)

CreateUser and do some validation

func DeleteExpiredRepositories

func DeleteExpiredRepositories()

DeleteExpiredRepositories Delete expired

func DeleteOldRepositoryArchives

func DeleteOldRepositoryArchives()

DeleteOldRepositoryArchives Archive deletion

func DeleteRepository

func DeleteRepository(ownerID int64, repoID int64) error

DeleteRepository Delete repository :'(

func GetUserSalt

func GetUserSalt() (string, error)

GetUserSalt returns a ramdom user salt token.

func InitDb

func InitDb()

InitDb from config

func IsErrDeployKeyAlreadyExist

func IsErrDeployKeyAlreadyExist(err error) bool

IsErrDeployKeyAlreadyExist func

func IsErrDeployKeyNameAlreadyUsed

func IsErrDeployKeyNameAlreadyUsed(err error) bool

IsErrDeployKeyNameAlreadyUsed func

func IsErrDeployKeyNotExist

func IsErrDeployKeyNotExist(err error) bool

IsErrDeployKeyNotExist func

func IsErrEmailAlreadyUsed

func IsErrEmailAlreadyUsed(err error) bool

IsErrEmailAlreadyUsed func

func IsErrHashAlreadyExist

func IsErrHashAlreadyExist(err error) bool

IsErrHashAlreadyExist func

func IsErrKeyAccessDenied

func IsErrKeyAccessDenied(err error) bool

IsErrKeyAccessDenied func

func IsErrKeyAlreadyExist

func IsErrKeyAlreadyExist(err error) bool

IsErrKeyAlreadyExist func

func IsErrKeyNameAlreadyUsed

func IsErrKeyNameAlreadyUsed(err error) bool

IsErrKeyNameAlreadyUsed func

func IsErrKeyNotExist

func IsErrKeyNotExist(err error) bool

IsErrKeyNotExist func

func IsErrKeyUnableVerify

func IsErrKeyUnableVerify(err error) bool

IsErrKeyUnableVerify func

func IsErrNamePatternNotAllowed

func IsErrNamePatternNotAllowed(err error) bool

IsErrNamePatternNotAllowed func

func IsErrNameReserved

func IsErrNameReserved(err error) bool

IsErrNameReserved func

func IsErrUserAlreadyExist

func IsErrUserAlreadyExist(err error) bool

IsErrUserAlreadyExist func

func IsErrUserOwnRepos

func IsErrUserOwnRepos(err error) bool

IsErrUserOwnRepos func

func IsHashUsed

func IsHashUsed(uid int64, hash string) (bool, error)

IsHashUsed checks if given hash exist,

func IsUsableUsername

func IsUsableUsername(name string) error

IsUsableUsername or not

func IsUserExist

func IsUserExist(uid int64, name string) (bool, error)

IsUserExist checks if given user name exist, the user name should be noncased unique. If uid is presented, then check will rule out that one, it is used when update a user name in settings page.

func LoadConfigs

func LoadConfigs()

LoadConfigs to init db

func NewEngine

func NewEngine() (err error)

NewEngine to use

func NewMailerUser

func NewMailerUser(u *User) mailer.User

NewMailerUser mail user

func NewTestEngine

func NewTestEngine(x *xorm.Engine) (err error)

NewTestEngine to test

func Ping

func Ping() error

Ping pong

func SetEngine

func SetEngine() (err error)

SetEngine to use

func UpdateCounterGitxts

func UpdateCounterGitxts(u int64) error

UpdateCounterGitxts with count

func UpdateCounterGitxtsManaged

func UpdateCounterGitxtsManaged(c int64) error

UpdateCounterGitxtsManaged with count

func UpdateGitxt

func UpdateGitxt(u *Gitxt) error

UpdateGitxt with infos

func UpdateUser

func UpdateUser(u *User) error

UpdateUser with datas

func UserPath

func UserPath(userName string) string

UserPath returns the path absolute path of user repositories.

Types

type Counter

type Counter struct {
	ID    int64  `xorm:"pk autoincr"`
	Name  string `xorm:"UNIQUE NOT NULL"`
	Count int64
}

Counter struct

func GetCounterGitxts

func GetCounterGitxts() (*Counter, error)

GetCounterGitxts get it

func GetCounterGitxtsManaged

func GetCounterGitxtsManaged() (*Counter, error)

GetCounterGitxtsManaged get it

type Engine

type Engine interface {
	Delete(interface{}) (int64, error)
	Exec(string, ...interface{}) (sql.Result, error)
	Find(interface{}, ...interface{}) error
	Get(interface{}) (bool, error)
	Id(interface{}) *xorm.Session
	In(string, ...interface{}) *xorm.Session
	Insert(...interface{}) (int64, error)
	InsertOne(interface{}) (int64, error)
	Iterate(interface{}, xorm.IterFunc) error
	Sql(string, ...interface{}) *xorm.Session
	Table(interface{}) *xorm.Session
	Where(interface{}, ...interface{}) *xorm.Session
}

Engine represents a XORM engine or session.

type ErrDeployKeyAlreadyExist

type ErrDeployKeyAlreadyExist struct {
	KeyID  int64
	RepoID int64
}

ErrDeployKeyAlreadyExist struct

func (ErrDeployKeyAlreadyExist) Error

func (err ErrDeployKeyAlreadyExist) Error() string

Error func

type ErrDeployKeyNameAlreadyUsed

type ErrDeployKeyNameAlreadyUsed struct {
	RepoID int64
	Name   string
}

ErrDeployKeyNameAlreadyUsed struct

func (ErrDeployKeyNameAlreadyUsed) Error

func (err ErrDeployKeyNameAlreadyUsed) Error() string

Error func

type ErrDeployKeyNotExist

type ErrDeployKeyNotExist struct {
	ID     int64
	KeyID  int64
	RepoID int64
}

ErrDeployKeyNotExist struct

func (ErrDeployKeyNotExist) Error

func (err ErrDeployKeyNotExist) Error() string

Error func

type ErrEmailAlreadyUsed

type ErrEmailAlreadyUsed struct {
	Email string
}

ErrEmailAlreadyUsed struct

func (ErrEmailAlreadyUsed) Error

func (err ErrEmailAlreadyUsed) Error() string

Error func

type ErrHashAlreadyExist

type ErrHashAlreadyExist struct {
	Hash string
}

ErrHashAlreadyExist struct

func (ErrHashAlreadyExist) Error

func (err ErrHashAlreadyExist) Error() string

Error func

type ErrKeyAccessDenied

type ErrKeyAccessDenied struct {
	UserID int64
	KeyID  int64
	Note   string
}

ErrKeyAccessDenied struct

func (ErrKeyAccessDenied) Error

func (err ErrKeyAccessDenied) Error() string

Error func

type ErrKeyAlreadyExist

type ErrKeyAlreadyExist struct {
	OwnerID int64
	Content string
}

ErrKeyAlreadyExist struct

func (ErrKeyAlreadyExist) Error

func (err ErrKeyAlreadyExist) Error() string

Error func

type ErrKeyNameAlreadyUsed

type ErrKeyNameAlreadyUsed struct {
	OwnerID int64
	Name    string
}

ErrKeyNameAlreadyUsed struct

func (ErrKeyNameAlreadyUsed) Error

func (err ErrKeyNameAlreadyUsed) Error() string

Error func

type ErrKeyNotExist

type ErrKeyNotExist struct {
	ID int64
}

ErrKeyNotExist struct

func (ErrKeyNotExist) Error

func (err ErrKeyNotExist) Error() string

Error func

type ErrKeyUnableVerify

type ErrKeyUnableVerify struct {
	Result string
}

ErrKeyUnableVerify struct

func (ErrKeyUnableVerify) Error

func (err ErrKeyUnableVerify) Error() string

Error func

type ErrNamePatternNotAllowed

type ErrNamePatternNotAllowed struct {
	Pattern string
}

ErrNamePatternNotAllowed struct

func (ErrNamePatternNotAllowed) Error

func (err ErrNamePatternNotAllowed) Error() string

Error func

type ErrNameReserved

type ErrNameReserved struct {
	Name string
}

ErrNameReserved struct

func (ErrNameReserved) Error

func (err ErrNameReserved) Error() string

Error func

type ErrUserAlreadyExist

type ErrUserAlreadyExist struct {
	Name string
}

ErrUserAlreadyExist struct

func (ErrUserAlreadyExist) Error

func (err ErrUserAlreadyExist) Error() string

Error func

type ErrUserOwnRepos

type ErrUserOwnRepos struct {
	UID int64
}

ErrUserOwnRepos struct

func (ErrUserOwnRepos) Error

func (err ErrUserOwnRepos) Error() string

Error func

type Gitxt

type Gitxt struct {
	ID          int64  `xorm:"pk autoincr"`
	Hash        string `xorm:"UNIQUE NOT NULL"`
	UserID      int64  `xorm:"INDEX"`
	Anonymous   bool
	Description string `xorm:"TEXT"`

	// Chosen expiry in hours
	ExpiryHours int64 `xorm:"INDEX"`
	// Calculated expiry unix timestamp from the time of creation/update
	ExpiryUnix int64
	Expiry     time.Time `xorm:"-"`

	// Permissions
	IsPrivate bool `xorm:"DEFAULT 0"`

	Created     time.Time `xorm:"-"`
	CreatedUnix int64
	Updated     time.Time `xorm:"-"`
	UpdatedUnix int64
}

Gitxt struct

func GetRepositoryByName

func GetRepositoryByName(user string, name string) (*Gitxt, error)

GetRepositoryByName returns the repository by given name under user if exists.

func (*Gitxt) AfterSet

func (gitxt *Gitxt) AfterSet(colName string, _ xorm.Cell)

AfterSet hooks

func (*Gitxt) BeforeInsert

func (gitxt *Gitxt) BeforeInsert()

BeforeInsert hooks

func (*Gitxt) BeforeUpdate

func (gitxt *Gitxt) BeforeUpdate()

BeforeUpdate hooks

type GitxtOptions

type GitxtOptions struct {
	UserID      int64
	WithPrivate bool
	GetAll      bool
	Page        int
	PageSize    int
}

GitxtOptions struct

type GitxtWithUser

type GitxtWithUser struct {
	User  `xorm:"extends"`
	Gitxt `xorm:"extends"`
}

GitxtWithUser struct

func GetGitxts

func GetGitxts(opts *GitxtOptions) (gitxts []*GitxtWithUser, _ int64, _ error)

GetGitxts Get gitxts

type SSHKey

type SSHKey struct {
	ID     int64 `xorm:"pk autoincr"`
	UserID int64 `xorm:"INDEX NOT NULL"`

	Name        string `xorm:"NOT NULL"`
	Fingerprint string `xorm:"NOT NULL"`
	Content     string `xorm:"TEXT NOT NULL"`
	Mode        int    `xorm:"NOT NULL DEFAULT 2"`
	Type        int    `xorm:"NOT NULL DEFAULT 1"`

	Created     time.Time `xorm:"-"`
	CreatedUnix int64
	Updated     time.Time `xorm:"-"`
	UpdatedUnix int64
}

SSHKey struct

func (*SSHKey) BeforeInsert

func (sshKey *SSHKey) BeforeInsert()

BeforeInsert hooks

func (*SSHKey) BeforeUpdate

func (sshKey *SSHKey) BeforeUpdate()

BeforeUpdate hooks

type User

type User struct {
	ID        int64  `xorm:"pk autoincr"`
	UserName  string `xorm:"UNIQUE NOT NULL"`
	LowerName string `xorm:"UNIQUE NOT NULL"`
	Email     string `xorm:"NOT NULL"`

	Password string `xorm:"NOT NULL"`
	Rands    string `xorm:"VARCHAR(10)"`
	Salt     string `xorm:"VARCHAR(10)"`

	// Permissions
	IsAdmin  bool `xorm:"DEFAULT 0"`
	IsActive bool `xorm:"DEFAULT 0"`

	Created     time.Time `xorm:"-"`
	CreatedUnix int64
	Updated     time.Time `xorm:"-"`
	UpdatedUnix int64
}

User struct

func GetUserByEmail

func GetUserByEmail(email string) (*User, error)

GetUserByEmail returns the user object by given e-mail if exists.

func GetUserByID

func GetUserByID(id int64) (*User, error)

GetUserByID returns the user object by given ID if exists.

func GetUserByName

func GetUserByName(name string) (*User, error)

GetUserByName returns user by given name.

func UserLogin

func UserLogin(username, password string) (*User, error)

UserLogin validates user name and password.

func VerifyUserActiveCode

func VerifyUserActiveCode(code string) (user *User)

VerifyUserActiveCode when active account

func (*User) BeforeInsert

func (user *User) BeforeInsert()

BeforeInsert hooks

func (*User) BeforeUpdate

func (user *User) BeforeUpdate()

BeforeUpdate hooks

func (*User) EncodePasswd

func (user *User) EncodePasswd()

EncodePasswd encodes password to safe format.

func (*User) GenerateActivateCode

func (user *User) GenerateActivateCode() string

GenerateActivateCode generates an activate code based on user information.

func (*User) GenerateEmailActivateCode

func (user *User) GenerateEmailActivateCode(email string) string

GenerateEmailActivateCode generates an activate code based on user information and given e-mail.

func (*User) ValidatePassword

func (user *User) ValidatePassword(passwd string) bool

ValidatePassword checks if given password matches the one belongs to the user.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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