Files
bds/modules/datas/user/cookie/cookie.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

42 lines
875 B
Go

package cookie
import (
"crypto/rand"
"database/sql"
"encoding/hex"
"fmt"
)
type Cookie struct {
Driver string
DB *sql.DB
}
func (cookie *Cookie) Cookie(cookieValue string) (exist bool, userID int64, err error) {
switch cookie.Driver {
case "sqlite3":
return cookie.sqliteCookie(cookieValue)
default:
return false, -1, fmt.Errorf("%s not supported yet", cookie.Driver)
}
}
func (cookie *Cookie) CreateCookie(userID int64) (cookieValue string, err error) {
cookieBytes := make([]byte, 12)
rand.Read(cookieBytes)
cookieBytes[0] = 'm'
cookieBytes[1] = 'a'
cookieBytes[2] = 'y'
cookieBytes[3] = '1'
cookieBytes[4] = '4'
cookieValue = hex.EncodeToString(cookieBytes)
switch cookie.Driver {
case "sqlite3":
err = cookie.sqliteInsertCookie(userID, cookieValue)
default:
return "", fmt.Errorf("%s not supported yet", cookie.Driver)
}
return
}