database

package
v0.0.0-...-efa6b18 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

YetAnotherToDoList Copyright © 2023 gilex-dev gilex-dev@proton.me

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

YetAnotherToDoList Copyright © 2023 gilex-dev gilex-dev@proton.me

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

YetAnotherToDoList Copyright © 2023 gilex-dev gilex-dev@proton.me

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

YetAnotherToDoList Copyright © 2023 gilex-dev gilex-dev@proton.me

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

YetAnotherToDoList Copyright © 2023 gilex-dev gilex-dev@proton.me

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

This section is empty.

Variables

View Source
var RevokedAccessTokens []*AccessToken

Functions

func RevokeAccessToken

func RevokeAccessToken(accessToken *AccessToken)

RevokeAccessToken revokes all access tokens with matching UserId and UserRole that don't have a later ExpiryDate. revokedAccessToken.ExpiryDate should be set to now + token-lifetime.

func ValidatePassword

func ValidatePassword(password string) error

ValidatePassword validates the passed string against the password criteria.

func ValidateUserName

func ValidateUserName(userName string) error

ValidateUserName validates the passed string against the user name criteria.

Types

type AccessToken

type AccessToken struct {
	UserId        string `json:"userId"`
	IsAdmin       bool   `json:"isAdmin"`
	IsUserCreator bool   `json:"isUserCreator"`
	ExpiryDate    int    `json:"expiryDate"`
}

type CustomDB

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

func InitSQLite3

func InitSQLite3(path string, schema uint, logger *log.Logger, secret []byte, initialAdminName string, initialAdminPassword string) *CustomDB

func (CustomDB) AddUserRole

func (db CustomDB) AddUserRole(userId string, roleId string, isRoleManager bool) (relationId string, err error)

func (CustomDB) CheckAccessToken

func (db CustomDB) CheckAccessToken(encAccessToken string) (accessToken *AccessToken, err error)

func (CustomDB) CleanExpiredRefreshTokensTicker

func (db CustomDB) CleanExpiredRefreshTokensTicker(interval time.Duration) (stopCleaner chan bool)

func (CustomDB) CleanRevokedAccessTokensTicker

func (db CustomDB) CleanRevokedAccessTokensTicker(interval time.Duration) (stopCleaner chan bool)

CleanRevokedTokensTicker removes expired tokens from the list. This should be called in an interval of > accessTokenLifetime.

func (CustomDB) CreateInitialAdmin

func (db CustomDB) CreateInitialAdmin(initialAdminName string, initialAdminPassword string) error

func (CustomDB) CreateRole

func (db CustomDB) CreateRole(newRole *model.NewRole) (role *model.Role, err error)

func (CustomDB) CreateTodo

func (db CustomDB) CreateTodo(newTodo model.NewTodo) (*model.Todo, error)

CreateTodo creates a Todo for the passed newTodo.UserID. Check if the source has the rights to call this.

func (CustomDB) CreateUser

func (db CustomDB) CreateUser(newUser model.NewUser) (*model.User, error)

func (CustomDB) DeleteRole

func (db CustomDB) DeleteRole(roleId string) (*string, error)

func (CustomDB) DeleteTodo

func (db CustomDB) DeleteTodo(todoId string) (deletedTodoId *string, err error)

func (CustomDB) DeleteUser

func (db CustomDB) DeleteUser(userId string) (*string, error)

func (CustomDB) GenerateHashFromPassword

func (db CustomDB) GenerateHashFromPassword(password string) (passwordHash []byte, err error)

GenerateHashFromPassword generates a hash of the passed password. Returns salt and salted & peppered hash.

func (CustomDB) GetAllRefreshTokens

func (db CustomDB) GetAllRefreshTokens() ([]*model.RefreshToken, error)

func (CustomDB) GetAllRoles

func (db CustomDB) GetAllRoles() ([]*model.Role, error)

func (CustomDB) GetAllTodos

func (db CustomDB) GetAllTodos() ([]*model.Todo, error)

GetAllTodos gets all todos from the database. Check if the source has the rights to call this.

func (CustomDB) GetAllUsers

func (db CustomDB) GetAllUsers() ([]*model.User, error)

func (CustomDB) GetOwner

func (db CustomDB) GetOwner(todoId string) (string, error)

GetOwner takes a todoId and return the owner's userId. Call before Update/Get/DeleteTodo when not IS_admin.

func (CustomDB) GetRefreshToken

func (db CustomDB) GetRefreshToken(token *model.RefreshToken) (*model.RefreshToken, error)

func (CustomDB) GetRefreshTokenOwner

func (db CustomDB) GetRefreshTokenOwner(tokenId string) (ownerId string, err error)

GetRefreshTokenOwner takes a tokenId and return the owner's userId. Call before Update/Get/DeleteRefreshToken when not IS_admin.

func (CustomDB) GetRefreshTokensFrom

func (db CustomDB) GetRefreshTokensFrom(userId string) ([]*model.RefreshToken, error)

func (CustomDB) GetRole

func (db CustomDB) GetRole(role *model.Role) (*model.Role, error)

func (CustomDB) GetRoleMembers

func (db CustomDB) GetRoleMembers(roleId string) ([]*model.RelationRoleUser, error)

func (CustomDB) GetRolesFrom

func (db CustomDB) GetRolesFrom(userId string) ([]*model.RelationUserRole, error)

func (CustomDB) GetTodo

func (db CustomDB) GetTodo(todo *model.Todo) (*model.Todo, error)

GetTodo takes a *model.Todo with at least ID set and adds the missing fields.

func (CustomDB) GetTodoOwner

func (db CustomDB) GetTodoOwner(todo *model.Todo) (owner *model.User, err error)

GetTodoOwner takes a *model.Todo with at least ID set and returns an *model.User with Id set to the todo's owner Id.

func (CustomDB) GetTodosFrom

func (db CustomDB) GetTodosFrom(user *model.User) ([]*model.Todo, error)

GetTodosFrom gets all todos from the passed *model.User. ID must be set.

func (CustomDB) GetUser

func (db CustomDB) GetUser(user *model.User) (*model.User, error)

GetUser takes a *model.User with at least ID or UserName set and adds the missing fields.

func (CustomDB) GetUserPermissions

func (db CustomDB) GetUserPermissions(userId string) (isAdmin bool, isUserCreator bool, err error)

func (CustomDB) IssueAccessToken

func (db CustomDB) IssueAccessToken(refreshToken *RefreshToken) (*AccessToken, error)

IssueAccessToken issues an access token if the passed refresh token is valid. Returned access token must be passed to SignAccessToken to be accepted.

func (CustomDB) IssueRefreshToken

func (db CustomDB) IssueRefreshToken(userId string, tokenName *string) (refreshToken *RefreshToken, refreshTokenId string, err error)

IssueRefreshToken issues a refresh token if the passed user credentials are valid. Returned refresh token can be passed to IssueAccessToken.

func (CustomDB) RemoveUserRole

func (db CustomDB) RemoveUserRole(userId string, roleId string) (relationId string, err error)

func (CustomDB) RevokeRefreshToken

func (db CustomDB) RevokeRefreshToken(tokenId string) (*string, error)

RevokeRefreshToken revokes the access token matching the tokenId. Also calls RevokeAccessToken.

func (CustomDB) SignAccessToken

func (db CustomDB) SignAccessToken(accessToken AccessToken) (encAccessToken string, err error)

SignAccessToken signs an access token and attaches a header. Returns access token encoded as jwt.

func (CustomDB) UpdateRefreshToken

func (db CustomDB) UpdateRefreshToken(tokenId string, changes *model.UpdateRefreshToken) (*model.RefreshToken, error)

func (CustomDB) UpdateRole

func (db CustomDB) UpdateRole(roleId string, changes *model.UpdateRole) (*model.Role, error)

func (CustomDB) UpdateTodo

func (db CustomDB) UpdateTodo(todoId string, changes *model.UpdateTodo) (*model.Todo, error)

func (CustomDB) UpdateUser

func (db CustomDB) UpdateUser(userId string, changes *model.UpdateUser) (*model.User, error)

func (CustomDB) UpdateUserRole

func (db CustomDB) UpdateUserRole(userId string, roleId string, isRoleManager bool) (relationId string, err error)

func (CustomDB) ValidateUserCredentials

func (db CustomDB) ValidateUserCredentials(userId *string, userName *string, password string) (validUserId string, err error)

type RefreshToken

type RefreshToken struct {
	Selector   string `json:"selector"`
	Token      string `json:"token"`
	ExpiryDate int    `json:"expiryDate"`
}

Jump to

Keyboard shortcuts

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