Documentation ¶
Index ¶
- type DatabaseHandler
- func (db *DatabaseHandler) CreateSession(username string, permissionLevel int) (string, error)
- func (db *DatabaseHandler) CreateUser(username string, password string, permissionLevel int) error
- func (db *DatabaseHandler) DeleteSession(cookieValue string)
- func (db *DatabaseHandler) DeleteUser(username string) error
- func (db *DatabaseHandler) GetUserList() []string
- func (db *DatabaseHandler) InitEmptyDatabase()
- func (db *DatabaseHandler) IsValidCredentials(username string, password string) (bool, int)
- func (db *DatabaseHandler) LoadDatabase(file string) error
- func (db *DatabaseHandler) LoginUserHandler(w http.ResponseWriter, r *http.Request)
- func (db *DatabaseHandler) SaveDatabase() error
- func (db *DatabaseHandler) ValidateSession(cookieValue string) (bool, int)
- type SessionsTable
- type UserTable
- func (ut *UserTable) CreateUser(username string, password string, permissionLevel int) error
- func (ut *UserTable) DeleteUser(username string) error
- func (ut *UserTable) GetUserList() []string
- func (ut *UserTable) IsValidCredentials(username string, password string) (bool, int)
- func (ut *UserTable) MarshalJSON() ([]byte, error)
- func (ut *UserTable) UnmarshalJSON(data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DatabaseHandler ¶
type DatabaseHandler struct { sync.RWMutex Users *UserTable `json:"users"` Pmods map[string]pmod `json:"pmods"` // contains filtered or unexported fields }
userSessions should be indexed by cookie value to prevent users from being logged out by overwrites
func CreateDatabaseHandler ¶
func CreateDatabaseHandler() *DatabaseHandler
func (*DatabaseHandler) CreateSession ¶
func (db *DatabaseHandler) CreateSession(username string, permissionLevel int) (string, error)
Returns the cookie value and an error value
func (*DatabaseHandler) CreateUser ¶
func (db *DatabaseHandler) CreateUser(username string, password string, permissionLevel int) error
Adds user to in memory database and triggers a file dump to store state
func (*DatabaseHandler) DeleteSession ¶
func (db *DatabaseHandler) DeleteSession(cookieValue string)
func (*DatabaseHandler) DeleteUser ¶
func (db *DatabaseHandler) DeleteUser(username string) error
Delete user from memory database and triggers a file dump to store state
func (*DatabaseHandler) GetUserList ¶
func (db *DatabaseHandler) GetUserList() []string
func (*DatabaseHandler) InitEmptyDatabase ¶
func (db *DatabaseHandler) InitEmptyDatabase()
func (*DatabaseHandler) IsValidCredentials ¶
func (db *DatabaseHandler) IsValidCredentials(username string, password string) (bool, int)
func (*DatabaseHandler) LoadDatabase ¶
func (db *DatabaseHandler) LoadDatabase(file string) error
Loads existing database from JSON file
func (*DatabaseHandler) LoginUserHandler ¶
func (db *DatabaseHandler) LoginUserHandler(w http.ResponseWriter, r *http.Request)
HTTP Handler for login route
func (*DatabaseHandler) SaveDatabase ¶
func (db *DatabaseHandler) SaveDatabase() error
func (*DatabaseHandler) ValidateSession ¶
func (db *DatabaseHandler) ValidateSession(cookieValue string) (bool, int)
Checks database for session Purges expired sessions if value is found in database but is expired. This is kind of a lazy approach to cleaning the database. A secondary trigger is needed to prevent the database from exploding in size in ideal operating conditions (when all cookies are time valid).
type SessionsTable ¶
func CreateSessionsTable ¶
func CreateSessionsTable() *SessionsTable
func (*SessionsTable) CleanSessions ¶
func (st *SessionsTable) CleanSessions()
Removes expired sessions from the database Called when a session value queried is found to be invalid and once an hour
func (*SessionsTable) CreateSession ¶
func (st *SessionsTable) CreateSession(username string, permissionLevel int) (string, error)
func (*SessionsTable) DeleteSession ¶
func (st *SessionsTable) DeleteSession(cookieValue string)
func (*SessionsTable) ValidateSession ¶
func (st *SessionsTable) ValidateSession(cookieValue string) (bool, int)
Returns a bool for session validity and returns permission level of found session.
type UserTable ¶
func CreateUserTable ¶
func CreateUserTable() *UserTable
func (*UserTable) CreateUser ¶
func (*UserTable) DeleteUser ¶
func (*UserTable) GetUserList ¶
func (*UserTable) IsValidCredentials ¶
func (*UserTable) MarshalJSON ¶
This is critical for making the database JSON Marshalable
func (*UserTable) UnmarshalJSON ¶
This is critical for making the database JSON Unmarshalable