webservice

package module
v0.0.0-...-76af178 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: GPL-3.0 Imports: 17 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(username string, account func(string) tiedb.Collection) (Reply, error)

type Credentials

type Credentials struct {
	Username string
	Password string
}

type MailSettings

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

func ReadMailSettings

func ReadMailSettings(result *tiedb.StringSliceSet, 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
}

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(username string, account func(string) tiedb.Collection) (Reply, error)
}

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(username string, account func(string) tiedb.Collection) (Reply, error)

type Webservice

type Webservice struct {
	// 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(w http.ResponseWriter, raw_data []byte, r RequestInterface, username string)

func (*Webservice) BasicAuth

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

func (*Webservice) DelUser

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

func (*Webservice) GetAccount

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

func (*Webservice) GetPassword

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

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
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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