moved to psql pool closes #99

This commit is contained in:
2024-04-17 17:46:43 +01:00
parent 8ece8306dd
commit a3913ccdf5
14 changed files with 132 additions and 98 deletions

View File

@@ -2,7 +2,6 @@ package users
import (
"crypto/rand"
"database/sql"
"encoding/hex"
"io"
"net/http"
@@ -10,6 +9,7 @@ import (
"golang.org/x/crypto/bcrypt"
"git.andr3h3nriqu3s.com/andr3/fyp/logic/db"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
dbtypes "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/models"
@@ -44,12 +44,12 @@ func genToken() string {
return hex.EncodeToString(token)
}
func deleteToken(db *sql.DB, userId string, time time.Time) (err error) {
func deleteToken(db db.Db, userId string, time time.Time) (err error) {
_, err = db.Exec("delete from tokens where emit_day=$1 and user_id=$2", time, userId)
return
}
func generateToken(db *sql.DB, email string, password string, name string) (string, bool) {
func generateToken(db db.Db, email string, password string, name string) (string, bool) {
row, err := db.Query("select id, salt, password from users where email = $1;", email)
if err != nil || !row.Next() {
return "", false
@@ -106,7 +106,7 @@ func DeleteUser(base BasePack, task Task) (err error) {
return
}
func UsersEndpints(db *sql.DB, handle *Handle) {
func UsersEndpints(db db.Db, handle *Handle) {
type UserLogin struct {
Email string `json:"email"`