Add Redis support for session and user management

This commit is contained in:
2024-09-08 00:03:43 +07:00
parent b9ac29d301
commit 2c5de2b336
26 changed files with 642 additions and 548 deletions

View File

@ -1,17 +1,31 @@
package googleOauthHandler
import (
"encoding/json"
"fmt"
"github.com/fossyy/filekeeper/app"
googleOauthCallbackHandler "github.com/fossyy/filekeeper/handler/auth/google/callback"
"github.com/fossyy/filekeeper/utils"
"net/http"
"time"
)
type CsrfToken struct {
Token string
CreateTime time.Time
}
func GET(w http.ResponseWriter, r *http.Request) {
token, err := utils.GenerateCSRFToken()
googleOauthCallbackHandler.CsrfTokens[token] = &googleOauthCallbackHandler.CsrfToken{Token: token, CreateTime: time.Now()}
csrfToken := CsrfToken{
Token: token,
CreateTime: time.Now(),
}
newCsrfToken, err := json.Marshal(csrfToken)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
app.Server.Cache.SetCache(r.Context(), "CsrfTokens:"+token, newCsrfToken, time.Minute*15)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
app.Server.Logger.Error(err.Error())