Added support for renewal tokens

This commit is contained in:
2021-01-05 16:49:50 +01:00
parent 2c82969152
commit a54b2eb847
5 changed files with 91 additions and 20 deletions

View File

@@ -6,7 +6,6 @@ import (
"github.com/google/uuid"
log "github.com/sirupsen/logrus"
"gitlab.larvit.se/power-plan/auth/src/utils"
)
// AccountCreate writes a user to database
@@ -112,21 +111,3 @@ func (d Db) AccountGet(accountID string, APIKey string, Name string) (Account, e
return account, nil
}
// RenewalTokenGet obtain a new renewal token
func (d Db) RenewalTokenGet(accountID string) (string, error) {
logContext := log.WithFields(log.Fields{"accountID": accountID})
logContext.Debug("Creating new renewal token")
newToken := utils.RandString(60)
insertSQL := "INSERT INTO \"renewalTokens\" (\"accountId\",token) VALUES($1,$2);"
_, insertErr := d.DbPool.Exec(context.Background(), insertSQL, accountID, newToken)
if insertErr != nil {
logContext.Error("Could not insert into database table \"renewalTokens\", err: " + insertErr.Error())
return "", insertErr
}
return newToken, nil
}