website

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2018 License: Apache-2.0 Imports: 28 Imported by: 0

README

This code all assumes that in the same directory as the binary connectordb there are two folders:

  • www: The website to show when not authenticated/logged in
    • Assumed to have the following pages:
      • index.html: The main webpage to show when not logged in
      • login.html: A login page to show when attempting to access resources
      • join.html: A form which is used to create new users
      • 404.html: Page to show upon a 404 error
  • app: The app which is shown to logged in users

Documentation

Overview

* Copyright (c) 2016 The ConnectorDB Contributors Licensed under the MIT license. *

* Copyright (c) 2016 The ConnectorDB Contributors Licensed under the MIT license. *

* Copyright (c) 2016 The ConnectorDB Contributors Licensed under the MIT license. *

* Copyright (c) 2016 The ConnectorDB Contributors Licensed under the MIT license. *

* Copyright (c) 2016 The ConnectorDB Contributors Licensed under the MIT license. *

* Copyright (c) 2016 The ConnectorDB Contributors Licensed under the MIT license. *

* Copyright (c) 2016 The ConnectorDB Contributors Licensed under the MIT license. *

Index

Constants

View Source
const (
	//The prefix to use for the paths in web server
	WWWPrefix = "www"
	AppPrefix = "app"
)

Variables

View Source
var (

	// WWWPath is the path to the not-logged-in website files
	WWWPath string
	// AppPath is the path to the logged-in user website files
	AppPath string

	// These are the pre-loaded templates for non-logged in users
	WWWTemplate *hot.Template
	// These are the pre-loaded templates for logged in users
	AppTemplate *hot.Template

	// These are convenience functions for accessing specific endpoints
	WWWLogin  wwwtemplatebookmark = "login.html"
	WWWIndex  wwwtemplatebookmark = "index.html"
	WWW404    wwwtemplatebookmark = "404.html"
	WWWJoin   wwwtemplatebookmark = "join.html"
	AppIndex  apptemplatebookmark = "index.html"
	AppUser   apptemplatebookmark = "user.html"
	AppDevice apptemplatebookmark = "device.html"
	AppStream apptemplatebookmark = "stream.html"
	AppError  apptemplatebookmark = "error.html"
)

Screw it, let's just use a global database

Functions

func Authenticator

func Authenticator(www wwwtemplatebookmark, apifunc webcore.APIHandler, db *connectordb.Database) http.HandlerFunc

Authenticator runs an auth check and either goes to the www template given or to the apifunc handler The only difference here is that the apihandler can return -1 for its log level to instead return the file template (as if no login ever happened)

func Device

func Device(o *authoperator.AuthOperator, writer http.ResponseWriter, request *http.Request, logger *log.Entry) (int, string)

Device reads the given device

func Index

func Index(o *authoperator.AuthOperator, writer http.ResponseWriter, request *http.Request, logger *log.Entry) (int, string)

Index reads the index

func JoinHandleGET

func JoinHandleGET(writer http.ResponseWriter, request *http.Request)

JoinHandleGET handles joining ConnectorDB - the frontend of joining (ie GET)

func JoinHandlePOST

func JoinHandlePOST(writer http.ResponseWriter, request *http.Request)

JoinHandlePOST handles the actual user creation based upon the given structure The only difference here than CRUD CreateUser is that the user creation is done with the admin operator

func LoadFiles

func LoadFiles() error

LoadFiles sets up all the necessary files

func Login

func Login(o *authoperator.AuthOperator, writer http.ResponseWriter, request *http.Request, logger *log.Entry) (int, string)

Login handles login to the system without the api call (direct web interface)

func LogoutHandler

func LogoutHandler(writer http.ResponseWriter, request *http.Request)

LogoutHandler handles log out of the system without an api call (direct web interface)

func NotFoundHandler

func NotFoundHandler(writer http.ResponseWriter, request *http.Request)

NotFoundHandler handles all pages that were not found by writing the 404 templates

func Router

func Router(db *connectordb.Database, r *mux.Router) (*mux.Router, error)

Router handles the website

func Stream

func Stream(o *authoperator.AuthOperator, writer http.ResponseWriter, request *http.Request, logger *log.Entry) (int, string)

Stream reads the given stream

func User

func User(o *authoperator.AuthOperator, writer http.ResponseWriter, request *http.Request, logger *log.Entry) (int, string)

User reads the given user

func VerifyCaptcha

func VerifyCaptcha(response string) (bool, error)

VerifyCaptcha checks if the captcha was solved successfully

func WriteError

func WriteError(logger *log.Entry, writer http.ResponseWriter, status int, err error, iserr bool, tp *TemplateData) (int, string)

WriteError writes the templated error page

Types

type JoinStream

type JoinStream struct {
	Name        string      `json:"name"`
	Nickname    string      `json:"nickname"`
	Description string      `json:"description"`
	Icon        string      `json:"icon"`
	Schema      interface{} `json:"schema"`
}

JoinStream is the structure used to encode a stream used for join

type Joiner

type Joiner struct {
	users.UserMaker
	Captcha string `json:"captcha"`
}

Joiner is the struct sent in when POST to join, which creates the desired user structure.

type TemplateData

type TemplateData struct {
	// Current unix timestamp in seconds since the epoch
	Timestamp int64

	//These are information about the device performing the query
	ThisUser   *users.User
	ThisDevice *users.Device

	//This is info about the u/d/s that is being queried
	User   *users.User
	Device *users.Device
	Stream *users.Stream

	//And some extra status info
	StatusCode int
	Msg        string
	Ref        string

	//The Database Version
	Version string
	// The root URL
	SiteURL string
	// contains filtered or unexported fields
}

TemplateData is the struct that is passed to the templates

func GetTemplateData

func GetTemplateData(o *authoperator.AuthOperator, request *http.Request) (*TemplateData, error)

GetTemplateData initializes the template

func (*TemplateData) DataURIToAttr

func (td *TemplateData) DataURIToAttr(uri string) template.HTMLAttr

func (*TemplateData) ReadDevices

func (t *TemplateData) ReadDevices() (out []*users.Device, err error)

Reads the devices for the page's user

func (*TemplateData) ReadMyDevices

func (t *TemplateData) ReadMyDevices() (out []*users.Device, err error)

Reads the devices for the user requesting the page

func (*TemplateData) ReadMyStreams

func (t *TemplateData) ReadMyStreams() (out []*users.Stream, err error)

Reads the streams for the user requesting the page

func (*TemplateData) ReadStreams

func (t *TemplateData) ReadStreams() (out []*users.Stream, err error)

Reads the streams for the page's device

func (*TemplateData) ReadUsers

func (t *TemplateData) ReadUsers() (out []*users.User, err error)

Reads all users on the system

Jump to

Keyboard shortcuts

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