webservice

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PASSWORDFIELD         = "password"
	MAILSETTINGSDB        = "mailsettingsdb"
	REQUESTVALIDATIONCODE = "requestvalidationcode"
	REQUESTCREATEACCOUNT  = "requestcreateaccount"
	VALIDATIONCHARS       = "0123456789"
	MAIL                  = "mail"     // Used for mail settings db
	SERVER                = "server"   // Used for mail settings db
	FROM                  = "from"     // Used for mail settings db
	SUBJECT               = "subject"  // Used for mail settings db
	USERNAME              = "username" // Used for mail settings db
	PASSWORD              = "password" // Used for mail settings db
	MESSAGE               = "message"  // Used for mail settings db
	VALIDATIONLENGTH      = 4
)
View Source
const (
	IdCreateAccount = "CreateAccount"
)
View Source
const (
	IdValidationCode = "ValidationCode"
)
View Source
const (
	ReplyTypeEmpty = "Empty"
)

Variables

This section is empty.

Functions

func ErrorToJsonString

func ErrorToJsonString(prepend string, err error) string

func LoginAuth

func LoginAuth(username, password string) smtp.Auth

func RandomCode

func RandomCode() string

func ReadReply

func ReadReply[T ReplyInterface](reply *Reply) *T

Types

type Client

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

func NewClient

func NewClient(server, username, password string) *Client

func (*Client) Run

func (c *Client) Run(request RequestInterface) (*Reply, error)

type CreateAccountReply

type CreateAccountReply struct {
	ReplyStatus
}

type CreateAccountRequest

type CreateAccountRequest struct {
	Request
	Email          string
	Password       string
	ValidationCode string
	// contains filtered or unexported fields
}

func NewCreateAccountRequest

func NewCreateAccountRequest() *CreateAccountRequest

func (*CreateAccountRequest) Reply

func (request *CreateAccountRequest) Reply(env *Environment) (Reply, error)

type Credentials

type Credentials struct {
	Username string
	Password string
}

type Environment

type Environment struct {
	Username   string
	Account    func(account string) *tiedb.Collection
	Collection func(namespace, collection string) *tiedb.Collection
	Webservice *Webservice
}

type MailSettings

type MailSettings struct {
	Server   string
	From     string
	Subject  string
	Username string
	Password string
	Message  string
}

func ReadMailSettings

func ReadMailSettings(result tiedb.TripleSet, code string) MailSettings

type Reply

type Reply struct {
	RequestName    string
	ReplyStructPtr interface{}
}

func (*Reply) DataCreateAccount

func (reply *Reply) DataCreateAccount() *CreateAccountReply

func (*Reply) DataValidationCode

func (reply *Reply) DataValidationCode() *ValidationCodeReply

type ReplyInterface

type ReplyInterface interface {
	GetSuccess() bool
	GetMessage() string
}

type ReplyStatus

type ReplyStatus struct {
	Success bool
	Message string
	OrigKey string
}

func (ReplyStatus) GetMessage

func (r ReplyStatus) GetMessage() string

func (ReplyStatus) GetSuccess

func (r ReplyStatus) GetSuccess() bool

type Request

type Request struct {
	Id             string
	ReplyStructPtr interface{}
}

func (*Request) GetId

func (r *Request) GetId() string

func (*Request) GetReplyStructPtr

func (r *Request) GetReplyStructPtr() interface{}

type RequestInterface

type RequestInterface interface {
	GetId() string
	GetReplyStructPtr() interface{}
	Reply(environment *Environment) (Reply, error)
}

type RequestToAnswer

type RequestToAnswer struct {
	AnswerTo http.ResponseWriter
	RawData  []byte
	Request  RequestInterface
	Username string
	Wait     *sync.WaitGroup
}

type ValidationCodeReply

type ValidationCodeReply struct {
	ReplyStatus
}

type ValidationCodeRequest

type ValidationCodeRequest struct {
	Request

	Email string
	// contains filtered or unexported fields
}

func NewValidationCodeRequest

func NewValidationCodeRequest() *ValidationCodeRequest

func (*ValidationCodeRequest) Reply

func (request *ValidationCodeRequest) Reply(env *Environment) (Reply, error)

type Webservice

type Webservice struct {
	Config WebserviceConfig
	// contains filtered or unexported fields
}

func NewWebservice

func NewWebservice(config WebserviceConfig, requests []RequestInterface) *Webservice

func (*Webservice) AddUser

func (ws *Webservice) AddUser(username, password string)

func (*Webservice) AnswerRequest

func (ws *Webservice) AnswerRequest(req *RequestToAnswer)

func (ws *Webservice) AnswerRequest(w http.ResponseWriter, raw_data []byte, r RequestInterface, username string) {

func (*Webservice) BasicAuth

func (ws *Webservice) BasicAuth(h httprouter.Handle) httprouter.Handle

func (*Webservice) DbPath

func (ws *Webservice) DbPath(namespace string) string

func (*Webservice) DelUser

func (ws *Webservice) DelUser(username, password string) bool

func (*Webservice) GetAccount

func (ws *Webservice) GetAccount(account string) *tiedb.Collection

func (*Webservice) GetCollection

func (ws *Webservice) GetCollection(namespace, collection string) *tiedb.Collection

func (*Webservice) GetPassword

func (ws *Webservice) GetPassword(user string) (password string, exists bool)

func (*Webservice) GetValidationCode

func (ws *Webservice) GetValidationCode(user string) string

func (*Webservice) ListenAndServe

func (ws *Webservice) ListenAndServe(routes func(*httprouter.Router))

func (*Webservice) RequestHandler

func (ws *Webservice) RequestHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func (*Webservice) SetMailSettings

func (ws *Webservice) SetMailSettings(mail MailSettings)

func (*Webservice) UpdatePassword

func (ws *Webservice) UpdatePassword(username, password, newpassword string) bool

func (*Webservice) Validate

func (ws *Webservice) Validate(user, code string) bool

type WebserviceConfig

type WebserviceConfig struct {
	ListenOn      string
	Insecure      bool
	CertFile      string
	KeyFile       string
	UseCertmagic  bool
	CertmagicHost string
	AuthNamespace string
	UserNamespace string
	AuthFile      string

	DbPath string
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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