utils

package
v0.0.0-...-9bcf0d1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2024 License: GPL-3.0 Imports: 42 Imported by: 1

Documentation

Index

Constants

View Source
const AccessTokenLength = 32
View Source
const AccessTokenLifetime = 60 * 60 * 24
View Source
const AppTokenLength = 32
View Source
const AppTokenLifetime = 60 * 60 * 24
View Source
const CodeLength = 32
View Source
const RefreshTokenLength = 48
View Source
const RefreshTokenLifetime = 60 * 60 * 24 * 30

Variables

This section is empty.

Functions

func AddAuthorRelationsFromMeQuery

func AddAuthorRelationsFromMeQuery(q *sqlf.Stmt, userID *models.UserID) *sqlf.Stmt

func AddAuthorRelationsToMeQuery

func AddAuthorRelationsToMeQuery(q *sqlf.Stmt, userID *models.UserID) *sqlf.Stmt

func AddCanViewAuthorQuery

func AddCanViewAuthorQuery(q *sqlf.Stmt, userID *models.UserID) *sqlf.Stmt

func AddCanViewEntryQuery

func AddCanViewEntryQuery(q *sqlf.Stmt, userID *models.UserID) *sqlf.Stmt

func AddEntryOpenQuery

func AddEntryOpenQuery(q *sqlf.Stmt, userID *models.UserID, showMe bool) *sqlf.Stmt

func AddViewAuthorQuery

func AddViewAuthorQuery(q *sqlf.Stmt, userID *models.UserID) *sqlf.Stmt

func AddViewCommentQuery

func AddViewCommentQuery(q *sqlf.Stmt, userID *models.UserID) *sqlf.Stmt

func AddViewEntryQuery

func AddViewEntryQuery(q *sqlf.Stmt, userID *models.UserID) *sqlf.Stmt

func CanViewEntry

func CanViewEntry(tx *AutoTx, userID *models.UserID, entryID int64) bool

CanViewEntry returns true if the user is allowed to read the entry.

func CanViewTlogName

func CanViewTlogName(tx *AutoTx, userID *models.UserID, tlog string) bool

func ClearDatabase

func ClearDatabase(db *sql.DB)

ClearDatabase drops user data tables and then creates default user

func CreateApp

func CreateApp(tx *AutoTx, hash TokenHash, app CreateAppParameters) (int64, string, error)

func CreateUserLog

func CreateUserLog(db *sql.DB, log *zap.Logger) middleware.Builder

func CutHtml

func CutHtml(text string, maxLineCount, maxLineLen int) (string, bool)

func CutText

func CutText(text string, size int) (string, bool)

func FormatFloat

func FormatFloat(val float64) string

func FormatInt64

func FormatInt64(val int64) string

func GenerateString

func GenerateString(length int) string

GenerateString returns random string

func HideEmail

func HideEmail(email string) string

func LoadConfig

func LoadConfig(fileName string) *goconf.Config

LoadConfig creates app config from file

func LoadImage

func LoadImage(srv *MindwellServer, tx *AutoTx, imageID int64) *models.Image

func LoadOnlineUsers

func LoadOnlineUsers(tx *AutoTx) []*models.User

func LoadRelation

func LoadRelation(tx *AutoTx, from, to int64) string

func LoadUser

func LoadUser(tx *AutoTx, id int64) *models.User

func LoadUserByName

func LoadUserByName(tx *AutoTx, name string) *models.User

func LoadUserIDByID

func LoadUserIDByID(tx *AutoTx, id int64) (*models.UserID, error)

func LoadUserIDByName

func LoadUserIDByName(tx *AutoTx, name string) (*models.UserID, error)

func LogHandler

func LogHandler(tpe string, nextHandler http.Handler) (http.Handler, error)

func NewOAuth2App

func NewOAuth2App(h TokenHash, db *sql.DB) func(string, []string) (*models.UserID, error)

func NewOAuth2User

func NewOAuth2User(h TokenHash, db *sql.DB, flowReq AuthFlow) func(string, []string) (*models.UserID, error)

func NoAuthUser

func NoAuthUser() *models.UserID

func OpenDatabase

func OpenDatabase(config *goconf.Config) *sql.DB

OpenDatabase returns db opened from config.

func ParseFloat

func ParseFloat(val string) float64

func ParseInt64

func ParseInt64(val string) int64

func RemoveHTML

func RemoveHTML(text string) string

func ReplaceToHtml

func ReplaceToHtml(val string) string

func ScopeFromString

func ScopeFromString(scopes []string) (uint32, error)

func ScopeToString

func ScopeToString(scope uint32) []string

func Transact

func Transact(db *sql.DB, txFunc func(*AutoTx) middleware.Responder) middleware.Responder

Transact wraps func in an SQL transaction. Responder will be just passed through.

Types

type AuthFlow

type AuthFlow uint8
const (
	AppFlow      AuthFlow = 1
	CodeFlow     AuthFlow = 2
	PasswordFlow AuthFlow = 4
)

type AutoTx

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

func NewAutoTx

func NewAutoTx(db *sql.DB) *AutoTx

func (*AutoTx) Close

func (tx *AutoTx) Close()

func (*AutoTx) Error

func (tx *AutoTx) Error() error

func (*AutoTx) Exec

func (tx *AutoTx) Exec(query string, args ...interface{})

func (*AutoTx) ExecStmt

func (tx *AutoTx) ExecStmt(stmt *sqlf.Stmt) *AutoTx

func (*AutoTx) Finish

func (tx *AutoTx) Finish()

func (*AutoTx) HasQueryError

func (tx *AutoTx) HasQueryError() bool

func (*AutoTx) LastQuery

func (tx *AutoTx) LastQuery() string

func (*AutoTx) Query

func (tx *AutoTx) Query(query string, args ...interface{}) *AutoTx

func (*AutoTx) QueryBool

func (tx *AutoTx) QueryBool(query string, args ...interface{}) bool

func (*AutoTx) QueryBools

func (tx *AutoTx) QueryBools(query string, args ...interface{}) []bool

func (*AutoTx) QueryFloat64

func (tx *AutoTx) QueryFloat64(query string, args ...interface{}) float64

func (*AutoTx) QueryInt64

func (tx *AutoTx) QueryInt64(query string, args ...interface{}) int64

func (*AutoTx) QueryInt64s

func (tx *AutoTx) QueryInt64s(query string, args ...interface{}) []int64

func (*AutoTx) QueryStmt

func (tx *AutoTx) QueryStmt(stmt *sqlf.Stmt) *AutoTx

func (*AutoTx) QueryString

func (tx *AutoTx) QueryString(query string, args ...interface{}) string

func (*AutoTx) QueryStrings

func (tx *AutoTx) QueryStrings(query string, args ...interface{}) []string

func (*AutoTx) RowsAffected

func (tx *AutoTx) RowsAffected() int64

func (*AutoTx) Scan

func (tx *AutoTx) Scan(dest ...interface{}) bool

func (*AutoTx) ScanBool

func (tx *AutoTx) ScanBool() bool

func (*AutoTx) ScanBools

func (tx *AutoTx) ScanBools() []bool

func (*AutoTx) ScanFloat64

func (tx *AutoTx) ScanFloat64() float64

func (*AutoTx) ScanInt64

func (tx *AutoTx) ScanInt64() int64

func (*AutoTx) ScanInt64s

func (tx *AutoTx) ScanInt64s() []int64

func (*AutoTx) ScanString

func (tx *AutoTx) ScanString() string

func (*AutoTx) ScanStrings

func (tx *AutoTx) ScanStrings() []string

type CompositeNotifier

type CompositeNotifier struct {
	Mail MailSender
	Ntf  *Notifier
	Tg   *TelegramBot
	// contains filtered or unexported fields
}

func NewCompositeNotifier

func NewCompositeNotifier(srv *MindwellServer) *CompositeNotifier

func (*CompositeNotifier) NotifyMessage

func (ntf *CompositeNotifier) NotifyMessage(tx *AutoTx, msg *models.Message, user string)

func (*CompositeNotifier) NotifyMessageRead

func (ntf *CompositeNotifier) NotifyMessageRead(chatID, msgID int64, user string)

func (*CompositeNotifier) NotifyMessageRemove

func (ntf *CompositeNotifier) NotifyMessageRemove(chatID, msgID int64, user string)

func (*CompositeNotifier) NotifyMessageUpdate

func (ntf *CompositeNotifier) NotifyMessageUpdate(msg *models.Message, user string)

func (*CompositeNotifier) SendAdmReceived

func (ntf *CompositeNotifier) SendAdmReceived(tx *AutoTx, grandfather string)

func (*CompositeNotifier) SendAdmSent

func (ntf *CompositeNotifier) SendAdmSent(tx *AutoTx, grandson string)

func (*CompositeNotifier) SendEmailChanged

func (ntf *CompositeNotifier) SendEmailChanged(tx *AutoTx, userID *models.UserID, oldEmail, newEmail string)

func (*CompositeNotifier) SendGreeting

func (ntf *CompositeNotifier) SendGreeting(address, showName string)

func (*CompositeNotifier) SendInvited

func (ntf *CompositeNotifier) SendInvited(tx *AutoTx, from, to string)

func (*CompositeNotifier) SendNewAccept

func (ntf *CompositeNotifier) SendNewAccept(tx *AutoTx, from, to string)

func (*CompositeNotifier) SendNewComment

func (ntf *CompositeNotifier) SendNewComment(tx *AutoTx, cmt *models.Comment)

func (*CompositeNotifier) SendNewCommentComplain

func (ntf *CompositeNotifier) SendNewCommentComplain(tx *AutoTx, commentID, fromID int64, content string)

func (*CompositeNotifier) SendNewEntryComplain

func (ntf *CompositeNotifier) SendNewEntryComplain(tx *AutoTx, entryID, fromID int64, content string)

func (*CompositeNotifier) SendNewFollower

func (ntf *CompositeNotifier) SendNewFollower(tx *AutoTx, toPrivate bool, from, to string)

func (*CompositeNotifier) SendNewInvite

func (ntf *CompositeNotifier) SendNewInvite(tx *AutoTx, userID int)

func (*CompositeNotifier) SendNewMessageComplain

func (ntf *CompositeNotifier) SendNewMessageComplain(tx *AutoTx, msgID, fromID int64, content string)

func (*CompositeNotifier) SendNewThemeComplain

func (ntf *CompositeNotifier) SendNewThemeComplain(tx *AutoTx, against *models.User, fromID int64, content string)

func (*CompositeNotifier) SendNewUserComplain

func (ntf *CompositeNotifier) SendNewUserComplain(tx *AutoTx, against *models.User, fromID int64, content string)

func (*CompositeNotifier) SendNewWishComplain

func (ntf *CompositeNotifier) SendNewWishComplain(tx *AutoTx, wishID, fromID int64)

func (*CompositeNotifier) SendPasswordChanged

func (ntf *CompositeNotifier) SendPasswordChanged(tx *AutoTx, userID *models.UserID)

func (*CompositeNotifier) SendRead

func (ntf *CompositeNotifier) SendRead(name string, id int64)

func (*CompositeNotifier) SendRemoveComment

func (ntf *CompositeNotifier) SendRemoveComment(tx *AutoTx, commentID int64)

func (*CompositeNotifier) SendResetPassword

func (ntf *CompositeNotifier) SendResetPassword(email, showName, gender string)

func (*CompositeNotifier) SendUpdateComment

func (ntf *CompositeNotifier) SendUpdateComment(tx *AutoTx, cmt *models.Comment)

func (*CompositeNotifier) SendWishCreated

func (ntf *CompositeNotifier) SendWishCreated(tx *AutoTx, wishID int64, user string)

func (*CompositeNotifier) SendWishReceived

func (ntf *CompositeNotifier) SendWishReceived(tx *AutoTx, wishID int64, user string)

func (*CompositeNotifier) Stop

func (ntf *CompositeNotifier) Stop()

type CreateAppParameters

type CreateAppParameters struct {
	DevName     string
	Type        string
	Flow        string
	RedirectUri string
	Name        string
	ShowName    string
	Platform    string
	Info        string
}

type EmailAllowedChecker

type EmailAllowedChecker interface {
	IsAllowed(email string) bool
}

type EmailChecker

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

func NewEmailChecker

func NewEmailChecker(srv *MindwellServer) *EmailChecker

func (*EmailChecker) IsAllowed

func (ec *EmailChecker) IsAllowed(email string) bool

type MailSender

type MailSender interface {
	SendGreeting(address, name, code string)
	SendPasswordChanged(address, name string)
	SendEmailChanged(address, name string)
	SendResetPassword(address, name, gender, code string, date int64)
	SendNewComment(address, fromGender, toShowName, entryTitle string, cmt *models.Comment)
	SendNewFollower(address, fromName, fromShowName, fromGender string, toPrivate bool, toShowName string)
	SendNewAccept(address, fromName, fromShowName, fromGender, toShowName string)
	SendNewInvite(address, name string)
	SendInvited(address, fromShowName, fromGender, toShowName string)
	SendAdmSent(address, toShowName string)
	SendAdmReceived(address, toShowName string)
	SendCommentComplain(from, against, content, comment string, commentID, entryID int64)
	SendEntryComplain(from, against, content, entry string, entryID int64)
	Stop()
}

type MindwellServer

type MindwellServer struct {
	DB   *sql.DB
	API  *operations.MindwellAPI
	Ntf  *CompositeNotifier
	Imgs *cache.Cache
	Eac  EmailAllowedChecker
	// contains filtered or unexported fields
}

func NewMindwellServer

func NewMindwellServer(api *operations.MindwellAPI, configPath string) *MindwellServer

func (*MindwellServer) ConfigBool

func (srv *MindwellServer) ConfigBool(field string) bool

func (*MindwellServer) ConfigBytes

func (srv *MindwellServer) ConfigBytes(field string) []byte

func (*MindwellServer) ConfigInt

func (srv *MindwellServer) ConfigInt(field string) int

func (*MindwellServer) ConfigInt64

func (srv *MindwellServer) ConfigInt64(field string) int64

func (*MindwellServer) ConfigInt64s

func (srv *MindwellServer) ConfigInt64s(field string) []int64

func (*MindwellServer) ConfigInts

func (srv *MindwellServer) ConfigInts(field string) []int

func (*MindwellServer) ConfigOptString

func (srv *MindwellServer) ConfigOptString(field string) string

func (*MindwellServer) ConfigString

func (srv *MindwellServer) ConfigString(field string) string

func (*MindwellServer) ConfigStrings

func (srv *MindwellServer) ConfigStrings(field string) []string

func (*MindwellServer) ImagesFolder

func (srv *MindwellServer) ImagesFolder() string

func (*MindwellServer) Log

func (srv *MindwellServer) Log(tpe string) *zap.Logger

func (*MindwellServer) LogApi

func (srv *MindwellServer) LogApi() *zap.Logger

func (*MindwellServer) LogEmail

func (srv *MindwellServer) LogEmail() *zap.Logger

func (*MindwellServer) LogRequest

func (srv *MindwellServer) LogRequest() *zap.Logger

func (*MindwellServer) LogSystem

func (srv *MindwellServer) LogSystem() *zap.Logger

func (*MindwellServer) LogTelegram

func (srv *MindwellServer) LogTelegram() *zap.Logger

func (*MindwellServer) NewAvatar

func (srv *MindwellServer) NewAvatar(avatar string) *models.Avatar

func (*MindwellServer) NewCover

func (srv *MindwellServer) NewCover(id int64, cover string) *models.Cover

func (*MindwellServer) NewError

func (srv *MindwellServer) NewError(msg *i18n.Message) *models.Error

NewError returns error object with some message

func (*MindwellServer) StandardError

func (srv *MindwellServer) StandardError(name string) *models.Error

func (*MindwellServer) TokenHash

func (srv *MindwellServer) TokenHash() TokenHash

func (*MindwellServer) Transact

func (srv *MindwellServer) Transact(txFunc func(*AutoTx) middleware.Responder) middleware.Responder

type Notifier

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

func NewNotifier

func NewNotifier(apiURL, apiKey string) *Notifier

func (*Notifier) Notify

func (ntf *Notifier) Notify(tx *AutoTx, subjectID int64, tpe, user string)

func (*Notifier) NotifyMessage

func (ntf *Notifier) NotifyMessage(chatID, msgID int64, user string)

func (*Notifier) NotifyMessageRead

func (ntf *Notifier) NotifyMessageRead(chatID, msgID int64, user string)

func (*Notifier) NotifyMessageRemove

func (ntf *Notifier) NotifyMessageRemove(chatID, msgID int64, user string)

func (*Notifier) NotifyMessageUpdate

func (ntf *Notifier) NotifyMessageUpdate(chatID, msgID int64, user string)

func (*Notifier) NotifyRead

func (ntf *Notifier) NotifyRead(user string, ntfID int64)

func (*Notifier) NotifyRemove

func (ntf *Notifier) NotifyRemove(tx *AutoTx, subjectID int64, tpe string)

func (*Notifier) NotifyUpdate

func (ntf *Notifier) NotifyUpdate(tx *AutoTx, subjectID int64, tpe string)

func (*Notifier) Stop

func (ntf *Notifier) Stop()

type Postman

type Postman struct {
	BaseUrl   string
	Support   string
	Moderator string
	Logger    *zap.Logger
	// contains filtered or unexported fields
}

func (*Postman) SendAdm

func (pm *Postman) SendAdm(address, name, gender string)

func (*Postman) SendAdmReceived

func (pm *Postman) SendAdmReceived(address, toShowName string)

func (*Postman) SendAdmSent

func (pm *Postman) SendAdmSent(address, toShowName string)

func (*Postman) SendCommentComplain

func (pm *Postman) SendCommentComplain(from, against, content, comment string, commentID, entryID int64)

func (*Postman) SendEmailChanged

func (pm *Postman) SendEmailChanged(address, name string)

func (*Postman) SendEntryComplain

func (pm *Postman) SendEntryComplain(from, against, content, entry string, entryID int64)

func (*Postman) SendGreeting

func (pm *Postman) SendGreeting(address, name, code string)

func (*Postman) SendInvited

func (pm *Postman) SendInvited(address, fromShowName, fromGender, toShowName string)

func (*Postman) SendNewAccept

func (pm *Postman) SendNewAccept(address, fromName, fromShowName, fromGender, toShowName string)

func (*Postman) SendNewComment

func (pm *Postman) SendNewComment(address, fromGender, toShowName, entryTitle string, cmt *models.Comment)

func (*Postman) SendNewFollower

func (pm *Postman) SendNewFollower(address, fromName, fromShowName, fromGender string, toPrivate bool, toShowName string)

func (*Postman) SendNewInvite

func (pm *Postman) SendNewInvite(address, name string)

func (*Postman) SendPasswordChanged

func (pm *Postman) SendPasswordChanged(address, name string)

func (*Postman) SendReminder

func (pm *Postman) SendReminder(address, name, gender string)

func (*Postman) SendResetPassword

func (pm *Postman) SendResetPassword(address, name, gender, code string, date int64)

func (*Postman) SendSurvey

func (pm *Postman) SendSurvey(address, name, surveyUrl string)

func (*Postman) Start

func (pm *Postman) Start(smtpHost string, smtpPort int, username, password, helo string) error

func (*Postman) Stop

func (pm *Postman) Stop()

type TelegramBot

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

func NewTelegramBot

func NewTelegramBot(srv *MindwellServer) *TelegramBot

func (*TelegramBot) BuildToken

func (bot *TelegramBot) BuildToken(userID int64) string

func (*TelegramBot) SendAdmReceived

func (bot *TelegramBot) SendAdmReceived(chat int64)

func (*TelegramBot) SendAdmSent

func (bot *TelegramBot) SendAdmSent(chat int64)

func (*TelegramBot) SendCommentComplain

func (bot *TelegramBot) SendCommentComplain(from, against *models.User, content, comment string, commentID, entryID int64)

func (*TelegramBot) SendEmailChanged

func (bot *TelegramBot) SendEmailChanged(chat int64)

func (*TelegramBot) SendEntryComplain

func (bot *TelegramBot) SendEntryComplain(from, against *models.User, content, entry string, entryID int64)

func (*TelegramBot) SendInvited

func (bot *TelegramBot) SendInvited(chat int64, fromName, fromShowName, fromGender string)

func (*TelegramBot) SendMessageComplain

func (bot *TelegramBot) SendMessageComplain(from, against *models.User, content, message string, messageID int64)

func (*TelegramBot) SendNewAccept

func (bot *TelegramBot) SendNewAccept(chat int64, fromName, fromShowName, fromGender string)

func (*TelegramBot) SendNewComment

func (bot *TelegramBot) SendNewComment(chat int64, entryTitle string, cmt *models.Comment)

func (*TelegramBot) SendNewFollower

func (bot *TelegramBot) SendNewFollower(chat int64, fromName, fromShowName, fromGender string, toPrivate bool)

func (*TelegramBot) SendNewInvite

func (bot *TelegramBot) SendNewInvite(chat int64)

func (*TelegramBot) SendNewMessage

func (bot *TelegramBot) SendNewMessage(chat int64, msg *models.Message)

func (*TelegramBot) SendPasswordChanged

func (bot *TelegramBot) SendPasswordChanged(chat int64)

func (*TelegramBot) SendRemoveComment

func (bot *TelegramBot) SendRemoveComment(commentID int64)

func (*TelegramBot) SendRemoveMessage

func (bot *TelegramBot) SendRemoveMessage(messageID int64)

func (*TelegramBot) SendThemeComplain

func (bot *TelegramBot) SendThemeComplain(from, against *models.User, content, title string)

func (*TelegramBot) SendUpdateComment

func (bot *TelegramBot) SendUpdateComment(entryTitle string, cmt *models.Comment)

func (*TelegramBot) SendUpdateMessage

func (bot *TelegramBot) SendUpdateMessage(msg *models.Message)

func (*TelegramBot) SendUserComplain

func (bot *TelegramBot) SendUserComplain(from, against *models.User, content, title string)

func (*TelegramBot) SendWishComplain

func (bot *TelegramBot) SendWishComplain(from, against *models.User, wish string, wishID int64)

func (*TelegramBot) Stop

func (bot *TelegramBot) Stop()

func (*TelegramBot) VerifyToken

func (bot *TelegramBot) VerifyToken(token string) int64

type TokenHash

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

func NewTokenHash

func NewTokenHash(cfg TokenHashConfig) TokenHash

func (TokenHash) AccessTokenHash

func (th TokenHash) AccessTokenHash(token string) []byte

func (TokenHash) AppSecretHash

func (th TokenHash) AppSecretHash(secret string) []byte

func (TokenHash) AppTokenHash

func (th TokenHash) AppTokenHash(token string) []byte

func (TokenHash) CheckResetPasswordCode

func (th TokenHash) CheckResetPasswordCode(email, code string, date int64) bool

func (TokenHash) PasswordHash

func (th TokenHash) PasswordHash(password string) []byte

func (TokenHash) RefreshTokenHash

func (th TokenHash) RefreshTokenHash(token string) []byte

func (TokenHash) ResetPasswordCode

func (th TokenHash) ResetPasswordCode(email string) (string, int64)

func (TokenHash) VerificationCode

func (th TokenHash) VerificationCode(email string) string

type TokenHashConfig

type TokenHashConfig interface {
	ConfigString(key string) string
}

Jump to

Keyboard shortcuts

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