implement a bit of the register.php call (and the DB schema)

This commit is contained in:
2022-11-13 22:31:28 +01:00
parent 0e58a5c5f0
commit 1671490485
13 changed files with 460 additions and 188 deletions

View File

@@ -2,10 +2,13 @@ package logic
import (
scn "blackforestbytes.com/simplecloudnotifier"
"blackforestbytes.com/simplecloudnotifier/common/ginresp"
"context"
"database/sql"
"fmt"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
"math/rand"
"net"
"net/http"
"os"
@@ -61,3 +64,48 @@ func (app *Application) Run() {
}
}
func (app *Application) GenerateRandomAuthKey() string {
charset := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
k := ""
for i := 0; i < 64; i++ {
k += string(charset[rand.Int()%len(charset)])
}
return k
}
func (app *Application) RunTransaction(ctx context.Context, opt *sql.TxOptions, fn func(tx *sql.Tx) (ginresp.HTTPResponse, bool)) ginresp.HTTPResponse {
tx, err := app.Database.BeginTx(ctx, opt)
if err != nil {
return ginresp.InternAPIError(0, fmt.Sprintf("Failed to create transaction: %v", err))
}
res, commit := fn(tx)
if commit {
err = tx.Commit()
if err != nil {
return ginresp.InternAPIError(0, fmt.Sprintf("Failed to commit transaction: %v", err))
}
} else {
err = tx.Rollback()
if err != nil {
return ginresp.InternAPIError(0, fmt.Sprintf("Failed to rollback transaction: %v", err))
}
}
return res
}
func (app *Application) QuotaMax(ispro bool) int {
if ispro {
return 1000
} else {
return 50
}
}
func (app *Application) VerifyProToken(token string) (bool, error) {
return false, nil //TODO implement pro verification
}