pax_global_header00006660000000000000000000000064125311706120014510gustar00rootroot0000000000000052 comment=55840daef9f0e7ef7c824055a45c20b5931e540c pinterface-2.0/000077500000000000000000000000001253117061200134715ustar00rootroot00000000000000pinterface-2.0/.gitignore000066400000000000000000000004121253117061200154560ustar00rootroot00000000000000# Compiled Object files, Static and Dynamic libs (Shared Objects) *.o *.a *.so # Folders _obj _test # Architecture specific extensions/prefixes *.[568vq] [568vq].out *.cgo1.go *.cgo2.c _cgo_defun.c _cgo_gotypes.go _cgo_export.* _testmain.go *.exe *.test *.prof pinterface-2.0/LICENSE000066400000000000000000000021001253117061200144670ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015 Alexander F Rødseth Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pinterface-2.0/README.md000066400000000000000000000006601253117061200147520ustar00rootroot00000000000000# pinterface Interfaces for: * [permissions2](https://github.com/xyproto/permissions2) and [simpleredis](https://github.com/xyproto/simpleredis) * [permissionbolt](https://github.com/xyproto/permissionbolt) and [simplebolt](https://github.com/xyproto/simplebolt) * [permissionsql](https://github.com/xyproto/permissionsql) and [simplemaria](https://github.com/xyproto/simplemaria) General information * Version 2.0 * License: MIT pinterface-2.0/pinterface.go000066400000000000000000000072631253117061200161500ustar00rootroot00000000000000package pinterface import "net/http" // Stable within the same version number const Version = 2.0 // Database interfaces type IList interface { Add(value string) error GetAll() ([]string, error) GetLast() (string, error) GetLastN(n int) ([]string, error) Remove() error Clear() error } type ISet interface { Add(value string) error Has(value string) (bool, error) GetAll() ([]string, error) Del(value string) error Remove() error Clear() error } type IHashMap interface { Set(owner, key, value string) error Get(owner, key string) (string, error) Has(owner, key string) (bool, error) Exists(owner string) (bool, error) GetAll() ([]string, error) DelKey(owner, key string) error Del(key string) error Remove() error Clear() error } type IKeyValue interface { Set(key, value string) error Get(key string) (string, error) Del(key string) error Inc(key string) (string, error) Remove() error Clear() error } // Interface for making it possible to depend on different versions of the permission package, or other packages that implement userstates. type IUserState interface { UserRights(req *http.Request) bool HasUser(username string) bool BooleanField(username, fieldname string) bool SetBooleanField(username, fieldname string, val bool) IsConfirmed(username string) bool IsLoggedIn(username string) bool AdminRights(req *http.Request) bool IsAdmin(username string) bool UsernameCookie(req *http.Request) (string, error) SetUsernameCookie(w http.ResponseWriter, username string) error AllUsernames() ([]string, error) Email(username string) (string, error) PasswordHash(username string) (string, error) AllUnconfirmedUsernames() ([]string, error) ConfirmationCode(username string) (string, error) AddUnconfirmed(username, confirmationCode string) RemoveUnconfirmed(username string) MarkConfirmed(username string) RemoveUser(username string) SetAdminStatus(username string) RemoveAdminStatus(username string) AddUser(username, password, email string) SetLoggedIn(username string) SetLoggedOut(username string) Login(w http.ResponseWriter, username string) error ClearCookie(w http.ResponseWriter) Logout(username string) Username(req *http.Request) string CookieTimeout(username string) int64 SetCookieTimeout(cookieTime int64) PasswordAlgo() string SetPasswordAlgo(algorithm string) error HashPassword(username, password string) string CorrectPassword(username, password string) bool AlreadyHasConfirmationCode(confirmationCode string) bool FindUserByConfirmationCode(confirmationcode string) (string, error) Confirm(username string) ConfirmUserByConfirmationCode(confirmationcode string) error SetMinimumConfirmationCodeLength(length int) GenerateUniqueConfirmationCode() (string, error) Users() IHashMap Host() IHost Creator() ICreator } // Database host (or file) type IHost interface { Ping() error Close() } // Redis host type IRedisHost interface { Pool() DatabaseIndex() } // Redis data structure creator type IRedisCreator interface { SelectDatabase(dbindex int) } // Data structure creator type ICreator interface { NewList(id string) (IList, error) NewSet(id string) (ISet, error) NewHashMap(id string) (IHashMap, error) NewKeyValue(id string) (IKeyValue, error) } // Middleware for permissions type IPermissions interface { SetDenyFunction(f http.HandlerFunc) DenyFunction() http.HandlerFunc UserState() IUserState Clear() AddAdminPath(prefix string) AddUserPath(prefix string) AddPublicPath(prefix string) SetAdminPath(pathPrefixes []string) SetUserPath(pathPrefixes []string) SetPublicPath(pathPrefixes []string) Rejected(w http.ResponseWriter, req *http.Request) bool ServeHTTP(w http.ResponseWriter, req *http.Request, next http.HandlerFunc) }