Files
bds/modules/datas/user/token/sqlite.go
Matheus Sampaio Queiroga ad65c0a9b0 Refactor user management and server templates
- Removed old SQLite user schema and replaced it with a new structure that includes password handling and cookie management.
- Updated user.go to implement password encryption and user creation logic.
- Modified web templates to reflect the new server management system, including the removal of outdated templates and the addition of new server creation and listing functionalities.
- Introduced error handling templates for better user feedback on bad requests and server errors.
- Added a makefile for easier database setup and management with Docker.

Signed-off-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
2025-05-09 22:03:06 -03:00

34 lines
829 B
Go

package token
import (
"database/sql"
_ "embed"
"sirherobrine23.com.br/go-bds/bds/modules/datas/permission"
)
var (
//go:embed sqlite/create.sql
sqliteTableCreate string
)
// Create table on start
func SqliteStartTable(connection *sql.DB) error {
_, err := connection.Exec(sqliteTableCreate)
return err
}
func (t *Token) sqliteCheck(token string) (exist bool, userID int64, perm permission.Permission, err error) {
row := t.DB.QueryRow("SELECT (user_id, permission) FROM token WHERE token = $1", token)
if err = row.Err(); err == nil {
err = row.Scan(&userID, &perm)
exist = true
}
return
}
func (t *Token) sqliteCreate(userID int, token string, perm permission.Permission) error {
_, err := t.DB.Exec("INSERT INTO tokens (user_id, token, permission) VALUE ($1, $2, $3)", userID, token, perm)
return err
}