mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +00:00
throttle requests on failed token
This commit is contained in:
parent
0f00fc1c4a
commit
22e58c9c0e
@ -5,6 +5,7 @@ import (
|
||||
"databag/internal/store"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"time"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -19,6 +20,7 @@ func AddAccount(w http.ResponseWriter, r *http.Request) {
|
||||
if r.FormValue("token") != "" {
|
||||
token, _, res = AccessToken(r)
|
||||
if res != nil || token.TokenType != APPTokenCreate {
|
||||
time.Sleep(APPUsernameWait * time.Millisecond);
|
||||
ErrResponse(w, http.StatusUnauthorized, res)
|
||||
return
|
||||
}
|
||||
|
@ -15,11 +15,10 @@ type accountUsername struct {
|
||||
//GetAccountUsername determines if username is assignable
|
||||
func GetAccountUsername(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
time.Sleep(APPUsernameWait * time.Millisecond);
|
||||
|
||||
if r.FormValue("token") != "" {
|
||||
token, _, res := AccessToken(r)
|
||||
if res != nil || token.TokenType != APPTokenCreate {
|
||||
time.Sleep(APPUsernameWait * time.Second);
|
||||
ErrResponse(w, http.StatusUnauthorized, res)
|
||||
return
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"databag/internal/store"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"time"
|
||||
"github.com/theckman/go-securerandom"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
@ -14,6 +15,7 @@ func SetAccountAccess(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
token, _, res := AccessToken(r)
|
||||
if res != nil || token.TokenType != APPTokenReset {
|
||||
time.Sleep(APPUsernameWait * time.Millisecond);
|
||||
ErrResponse(w, http.StatusUnauthorized, res)
|
||||
return
|
||||
}
|
||||
|
@ -96,8 +96,8 @@ const APPTokenReset = "reset"
|
||||
//APPNotifyBuffer config for size of channel reciving notifications
|
||||
const APPNotifyBuffer = 4096
|
||||
|
||||
//APPUsernameWait milliseconds to delay response
|
||||
const APPUsernameWait = 333
|
||||
//APPUsernameWait seconds to delay response
|
||||
const APPUsernameWait = 1
|
||||
|
||||
//APPTopicUnconfirmed config for status name for unconfirmed
|
||||
const APPTopicUnconfirmed = "unconfirmed"
|
||||
|
Loading…
Reference in New Issue
Block a user