implement a bit of the register.php call (and the DB schema)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user