diff options
author | FChannel <> | 2022-04-24 00:46:49 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | 3db517715bef6a53225c5c3c06e8fc5fd0bf71e3 (patch) | |
tree | 9aa7fbcb12f2ec8d0e4e66cd85ace058e38dd32d /db/redis.go | |
parent | 9718d34a757b66917747c1c4acfb9b35d154625b (diff) |
basic pass over view posts, post, catalog and manage page connections
Diffstat (limited to 'db/redis.go')
-rw-r--r-- | db/redis.go | 64 |
1 files changed, 47 insertions, 17 deletions
diff --git a/db/redis.go b/db/redis.go index 873ca27..1650b4f 100644 --- a/db/redis.go +++ b/db/redis.go @@ -3,10 +3,11 @@ package db import ( "bufio" "fmt" - "net/http" "os" + "strings" "github.com/FChannel0/FChannel-Server/config" + "github.com/gofiber/fiber/v2" "github.com/gomodule/redigo/redis" ) @@ -22,6 +23,50 @@ func CloseCache() error { return Cache.Close() } +func GetClientKey() (string, error) { + file, err := os.Open("clientkey") + if err != nil { + return "", err + } + defer file.Close() + + scanner := bufio.NewScanner(file) + var line string + for scanner.Scan() { + line = fmt.Sprintf("%s", scanner.Text()) + } + + return line, nil +} + +func GetPasswordFromSession(c *fiber.Ctx) (string, string) { + + cookie := c.Cookies("session_token") + + if cookie == "" { + return "", "" + } + + sessionToken := cookie + + response, err := Cache.Do("GET", sessionToken) + + if err != nil { + return "", "" + } + + token := fmt.Sprintf("%s", response) + + parts := strings.Split(token, "|") + + if len(parts) > 1 { + return parts[0], parts[1] + } + + return "", "" +} + +/* TODO: Convert to fiber ctx func CheckSession(w http.ResponseWriter, r *http.Request) (interface{}, error) { c, err := r.Cookie("session_token") @@ -49,20 +94,5 @@ func CheckSession(w http.ResponseWriter, r *http.Request) (interface{}, error) { } return response, nil -} - -func GetClientKey() (string, error) { - file, err := os.Open("clientkey") - if err != nil { - return "", err - } - defer file.Close() - - scanner := bufio.NewScanner(file) - var line string - for scanner.Scan() { - line = fmt.Sprintf("%s", scanner.Text()) } - - return line, nil -} +*/ |