goth

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2022 License: MIT Imports: 11 Imported by: 0

README

goth

An easy to use web authorization system for MongoDB.




Written 100% in Golang!

Contributing

Feel free to add an issue, and if you have a fix, create a pull request. When developing, it is important that you create a test_config.env file. This environment file should contain the MongoDB uri - this is used for testing purposes, and the file is gitignored.

Demo

You can find a barebones application in the example directory. Checkout the repo, add your uri to the .env file, and then run index.go.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var URI = (func() string {
	goenv.Load("test_config.env")
	return os.Getenv("uri")
})()

Functions

func GenLoginRoute

func GenLoginRoute(serve func(writer http.ResponseWriter), getLoginData func(*http.Request) LoginData, afterAuthed func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request)

Generates a login route to be given as the http handler for the /login route.

func GenLoginWall

func GenLoginWall(ifNotAuthed func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) bool

Generates a login wall that blocks entrance to the route. It also saves some visit-related metric data and saves it with a granularity level of 1 (meaning day-level granularity). The metric custodian gradually reduces the granularity - for example, every month, the previous month's day-level data will be scrapped for the month level data.

func GenSignupRoute

func GenSignupRoute(serve func(http.ResponseWriter), getSignupData func(*http.Request) SignupData, successfullyCreated func(http.ResponseWriter, *http.Request)) func(writer http.ResponseWriter, r *http.Request)

Generates a signup route to be used as the http handler for the /signup route

func SetURI

func SetURI(uri string)

Configures the URI

Types

type LoginData

type LoginData struct {
	// The username provided to the login route.
	Username string
	// The password provided to the login route. This password is only used to generate the token for authentication, then is deleted.
	Password string
}

The encapsulator for the login data returned by the getLoginData parameter function for GenLoginRoute. This data is typically from a form.

type SignupData

type SignupData struct {
	// The username provided to the signup route.
	Username string
	// The password provided to the signup route. This password is only used to generate the token for authentication.
	Password string
}

The encapsulator for the signup data returned by the getSignupData parameter function for GenSignupRoute. This data is typically from a form.

type Token

type Token struct {
	/* The token, which will be a SHA256 sum of the username and password concatenated. */
	Token string `json:"token"`
}

The struct representing the token.

func GenToken

func GenToken(username string, password string) Token

Creates a new Token from the given credentials.

func (Token) IsEqualToTokenOf

func (t Token) IsEqualToTokenOf(username string, password string) (bool, error)

Checks if the token is valid.

type User

type User struct {
	// Username of the user.
	Username string `json:"username"`
	// User token (generated by the GenToken function).
	Token string `json:"token"`
}

Model of a user.

func GetUser

func GetUser(filter bson.D) (bool, User)

Gets a user filtered by the given bson.D.

type UserDataHandle

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

func NewDataHandle

func NewDataHandle(filter bson.D) UserDataHandle

func (*UserDataHandle) GetDataHandle

func (u *UserDataHandle) GetDataHandle() *map[string]interface{}

func (*UserDataHandle) Push

func (u *UserDataHandle) Push()

Directories

Path Synopsis
metrics module

Jump to

Keyboard shortcuts

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