db

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogTypeAuthLogin      = "auth.login"
	LogTypeAuthPassReset  = "auth.passreset"
	LogTypeAuthPassChange = "auth.passchange"
)

#nosec G101 LogTypeAuth enum

View Source
const (
	SearchFilterLocked = iota
	SearchFilterNotLocked
)

Variables

View Source
var (
	// Auth
	ErrIDPassInvalid  = errors.New("ID or password is incorrect")
	ErrInvalidToken   = errors.New("Token is expired or invalid")
	ErrExistUser      = errors.New("UserName or email is already exist")
	ErrInvalidSession = errors.New("SessionID is invalid")

	// User/Team
	ErrUserNotFound     = errors.New("The user is not found")
	ErrUserTeamNotFound = errors.New("User/team is not found")

	// Document/Folder
	ErrDocumentNotFound = errors.New("Document is not found")
	ErrFolderNotFound   = errors.New("Folder is not found")
)

Errors

Functions

func GenerateID

func GenerateID(t IDType) (string, error)

GenerateID generates random IDs

func GenerateJWT

func GenerateJWT(uuid string, sessionid string) (string, error)

GenerateJWT generates JWT using UUID and sessionID

func GenerateSessionID

func GenerateSessionID() (string, error)

GenerateSessionID generates randomID for sessions

func LoadKeys

func LoadKeys(rsaPrivateKeyFile, rsaPublicKeyFile string) error

LoadKeys read public/private keys

Types

type Auth

type Auth struct {
	UUID     string
	Email    string
	Password string
	Salt     string
}

Auth table model

type DB

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

DB holds DB connection

func OpenDB

func OpenDB(dbHost, dbPort, dbUser, dbPass, dbName string) (*DB, error)

OpenDB connects to DB server and return DB instance

func (*DB) AddLogLogin

func (d *DB) AddLogLogin(uuid string, sessionID string, ipaddr string, devinfo string) error

AddLogLogin adds login log

func (*DB) AddLogPassChange

func (d *DB) AddLogPassChange(uuid string, ipaddr string, sessionID string) error

AddLogPassChange adds pass change log

func (*DB) AddLogPassReset

func (d *DB) AddLogPassReset(uuid string, ipaddr string, devinfo string) error

AddLogPassReset adds pass reset log

func (*DB) AddSession

func (d *DB) AddSession(uuid string, sessionID string, IPAddr string, DeviceData string) error

AddSession records new session information

func (*DB) AddTeamMember

func (d *DB) AddTeamMember(teamuuid string, useruuid string, perm TeamPerm) error

AddTeamMember adds new member into the team

func (*DB) ChangePass

func (d *DB) ChangePass(uuid string, oldpass string, newpass string) error

ChangePass checks oldpass and changes to new pass

func (*DB) ChangeTeamOwner

func (d *DB) ChangeTeamOwner(teamuuid string, olduuid string, newuuid string) error

ChangeTeamOwner changes the owner of the team

func (*DB) CheckInviteToken

func (d *DB) CheckInviteToken(token string) error

CheckInviteToken checks invitation token

func (*DB) CleanupExpired

func (d *DB) CleanupExpired() error

CleanupExpired removes expired record

func (*DB) CreateDocument

func (d *DB) CreateDocument(title string, permission FilePerm, parentfid string, owneruuid string, updateruuid string) (string, error)

CreateDocument creates new document

func (*DB) CreateFolder

func (d *DB) CreateFolder(name string, permission FilePerm, parentfid string, owneruuid string, updateruuid string) (string, error)

CreateFolder creates new folder

func (*DB) CreateTeam

func (d *DB) CreateTeam(teamname string, useruuid string) (string, error)

CreateTeam creates new team

func (*DB) DeleteDocument

func (d *DB) DeleteDocument(did string) error

DeleteDocument deletes document

func (*DB) DeleteFolder

func (d *DB) DeleteFolder(fid string) error

DeleteFolder deletes folder

func (*DB) DeleteInviteToken

func (d *DB) DeleteInviteToken(token string) error

DeleteInviteToken removes invitation token

func (*DB) DeleteTeam

func (d *DB) DeleteTeam(teamuuid string) error

DeleteTeam deletes team

func (*DB) DeleteTeamMember

func (d *DB) DeleteTeamMember(teamuuid string, useruuid string) error

DeleteTeamMember removes the member from the team

func (*DB) DuplicateDocument added in v1.4.0

func (d *DB) DuplicateDocument(did string, permission FilePerm, parentfid string, owneruuid string, updateruuid string) (string, error)

DuplicateDocument duplicates document and save into target folder

func (*DB) GenerateInviteToken

func (d *DB) GenerateInviteToken(useruuid string) (string, error)

GenerateInviteToken generates token for invitation

func (*DB) GetDocList

func (d *DB) GetDocList(fid string) ([]string, error)

GetDocList returns the list of documents in the specified folder

func (*DB) GetDocumentInfo

func (d *DB) GetDocumentInfo(fid string) (Document, error)

GetDocumentInfo returns document information

func (*DB) GetFolderInfo

func (d *DB) GetFolderInfo(fid string) (Folder, error)

GetFolderInfo returns folder information

func (*DB) GetFolderList

func (d *DB) GetFolderList(fid string) ([]string, error)

GetFolderList returns the list of folders in the specified folder

func (*DB) GetLatestDocument

func (d *DB) GetLatestDocument(did string) (string, error)

GetLatestDocument returns document data

func (*DB) GetLoginPassResetLog

func (d *DB) GetLoginPassResetLog(logid int64) (LogExtLoginPassReset, error)

GetLoginPassResetLog returns log of loginpassreset

func (*DB) GetLogs

func (d *DB) GetLogs(offset int, limit int, uuid string, target []string, ltype []string) ([]Log, error)

GetLogs returns the list of logs target is list of teamids

func (*DB) GetProfileByUUID

func (d *DB) GetProfileByUUID(uuid string) (Profile, error)

GetProfileByUUID returns the profile info

func (*DB) GetProfileByUsername

func (d *DB) GetProfileByUsername(name string) (Profile, error)

GetProfileByUsername returns the profile info

func (*DB) GetRootFID

func (d *DB) GetRootFID() (string, error)

GetRootFID returns root folder ID

func (*DB) GetSession

func (d *DB) GetSession(uuid string) ([]Session, error)

GetSession deletes the session

func (*DB) GetTeamMember

func (d *DB) GetTeamMember(teamuuid string, limit int, offset int, uuid string) (int, []TeamMember, error)

GetTeamMember returns the member list of the team

func (*DB) GetTeamMemberPerm

func (d *DB) GetTeamMemberPerm(teamuuid string, useruuid string) (TeamPerm, error)

GetTeamMemberPerm returns team member permission

func (*DB) GetTeamsByUser

func (d *DB) GetTeamsByUser(useruuid string) ([]string, error)

GetTeamsByUser returns team IDs for specified user

func (*DB) GetUUIDByEmail added in v1.3.0

func (d *DB) GetUUIDByEmail(email string) (string, error)

ResetPass generates and returns token to reset password

func (*DB) GetUserFID

func (d *DB) GetUserFID() (string, error)

GetUserFID returns user folder ID

func (*DB) IsAdmin

func (d *DB) IsAdmin(uuid string) (bool, error)

IsAdmin checks user is admin or not

func (*DB) IsUserLocked

func (d *DB) IsUserLocked(uuid string) (bool, error)

IsUserLocked checks the user is locked.

func (*DB) LockUser added in v1.3.0

func (d *DB) LockUser(uuid string) error

LockUser locks user.

func (*DB) ModifyTeamMember

func (d *DB) ModifyTeamMember(teamuuid string, useruuid string, perm TeamPerm) error

ModifyTeamMember updates team member permission

func (*DB) MoveDocument

func (d *DB) MoveDocument(did string, targetfid string) error

MoveDocument moves document to target folder

func (*DB) MoveFolder

func (d *DB) MoveFolder(fid string, targetfid string) error

MoveFolder moves folder

func (*DB) PasswordCheck

func (d *DB) PasswordCheck(userid string, pass string) (string, error)

PasswordCheck checks given ID and pass and returns UUID

func (*DB) PreRegistUser

func (d *DB) PreRegistUser(username string, email string, password string) (string, error)

PreRegistUser records new user information into preuser and return token to activate

func (*DB) RegistUser

func (d *DB) RegistUser(token string) error

RegistUser activates preuser

func (*DB) RemoveSession

func (d *DB) RemoveSession(uuid string, sessionID string) error

RemoveSession deletes the session

func (*DB) ResetPass

func (d *DB) ResetPass(uuid string) (string, error)

ResetPass generates and returns token to reset password

func (*DB) ResetPassTokenCheck

func (d *DB) ResetPassTokenCheck(token string) (string, error)

ResetPassTokenCheck checks the token to reset password and returns UUID

func (*DB) ResetPassVerify

func (d *DB) ResetPassVerify(token string, newpass string) (string, error)

ResetPassVerify checks the token and changes to new pass

func (*DB) SaveDocument

func (d *DB) SaveDocument(did string, updateruuid string, text string) error

SaveDocument store the document data

func (*DB) SearchTeam

func (d *DB) SearchTeam(query string, limit int, offset int) (int, []string, error)

SearchTeam returns the team uuid list of search

func (*DB) SearchUser

func (d *DB) SearchUser(query string, limit int, offset int, filters []int) (int, []string, error)

SearchUser returns the user uuid list of search

func (*DB) SetPass

func (d *DB) SetPass(uuid string, newpass string) error

SetPass changes to new pass

func (*DB) SetProfile

func (d *DB) SetProfile(profile Profile) error

SetProfile updates the profile info

func (*DB) UnlockUser added in v1.3.0

func (d *DB) UnlockUser(uuid string) error

UnlockUser unlocks user.

func (*DB) UpdateDocument

func (d *DB) UpdateDocument(did string, updateruuid string) error

UpdateDocument modifies document update time

func (*DB) UpdateDocumentInfo

func (d *DB) UpdateDocumentInfo(dat Document) error

UpdateDocumentInfo modifies document info

func (*DB) UpdateFolder

func (d *DB) UpdateFolder(fid string, updateruuid string) error

UpdateFolder modifies folder update time

func (*DB) UpdateFolderInfo

func (d *DB) UpdateFolderInfo(dat Folder) error

UpdateFolderInfo modifies folder info

func (*DB) UpdateSessionLastUsed

func (d *DB) UpdateSessionLastUsed(uuid string, sessionID string) error

UpdateSessionLastUsed deletes the session

func (*DB) VerifyToken

func (d *DB) VerifyToken(token string) (string, string, error)

VerifyToken verifies JWT and returns UUID and sessionID of JWT holder

type Document

type Document struct {
	UUID             string
	OwnerUUID        string
	ParentFolderUUID string
	Title            string
	Permission       FilePerm
	CreatedAt        int64
	UpdatedAt        int64
	UpdaterUUID      string
	Revision         int
}

Document table model

type DocumentRevision

type DocumentRevision struct {
	UUID      string
	Text      string
	UpdatedAt int64
	Revision  int
}

DocumentRevision table model

type FilePerm

type FilePerm int

FilePerm is enum of file and folder permission.

const (
	FilePermPrivate FilePerm = iota
	FilePermRead
	FilePermReadWrite
)

FilePerm list

type Folder

type Folder struct {
	UUID             string
	OwnerUUID        string
	ParentFolderUUID string
	Name             string
	Permission       FilePerm
	CreatedAt        int64
	UpdatedAt        int64
	UpdaterUUID      string
}

Folder table model

type IDType

type IDType int

IDType is enum of types of ID

const (
	IDTypeVerifyToken IDType = iota
	IDTypeSessionID
	IDTypeSalt
	IDTypeImageID
	IDTypeUser
	IDTypeTeam
	IDTypeFolder
	IDTypeDocument
)

IDType list

type Log

type Log struct {
	UUID       string
	Date       int64
	Type       string
	IPAddr     string
	SessionID  string
	TargetUUID string
	TargetFDID string
	ExtDataID  int64
}

Log table model

type LogExtLoginPassReset

type LogExtLoginPassReset struct {
	ID         int64
	DeviceData string
}

LogExtLoginPassReset table model

type Profile

type Profile struct {
	UUID     string
	Name     string
	Bio      string
	IconURI  string
	CreateAt int64
	Attr     string
	Lang     string
}

Profile table model

type Session

type Session struct {
	UUID       string
	SessionID  string
	LoginDate  int64
	LastDate   int64
	ExpireDate int64
	IPAddr     string
	DeviceData string
}

Session table model

type TeamMember

type TeamMember struct {
	TeamUUID   string
	UserUUID   string
	Permission TeamPerm
	JoinAt     int64
}

TeamMember table model

type TeamPerm

type TeamPerm int

TeamPerm is enum of team member's permission.

const (
	TeamPermUser TeamPerm = iota
	TeamPermAdmin
	TeamPermOwner
)

TeamPerm list

Jump to

Keyboard shortcuts

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