From bc9051fd1a17e793647cf309c973a7feefebd98f Mon Sep 17 00:00:00 2001 From: KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> Date: Tue, 2 Nov 2021 16:10:57 -0300 Subject: down to the main package it seems --- session.go | 94 -------------------------------------------------------------- 1 file changed, 94 deletions(-) delete mode 100644 session.go (limited to 'session.go') diff --git a/session.go b/session.go deleted file mode 100644 index 46c58ea..0000000 --- a/session.go +++ /dev/null @@ -1,94 +0,0 @@ -package main - -import ( - "bufio" - "fmt" - "net/http" - "os" - "strings" - - "github.com/gomodule/redigo/redis" -) - -var cache redis.Conn - -func InitCache() { - conn, err := redis.DialURL(GetConfigValue("redis", "redis://localhost")) - if err != nil { - panic(err) - } - cache = conn -} - -func CheckSession(w http.ResponseWriter, r *http.Request) (interface{}, error) { - - c, err := r.Cookie("session_token") - - if err != nil { - if err == http.ErrNoCookie { - w.WriteHeader(http.StatusUnauthorized) - return nil, err - } - - w.WriteHeader(http.StatusBadRequest) - return nil, err - } - - sessionToken := c.Value - - response, err := cache.Do("GET", sessionToken) - - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - return nil, err - } - if response == nil { - w.WriteHeader(http.StatusUnauthorized) - return nil, err - } - - return response, nil -} - -func GetClientKey() string { - file, err := os.Open("clientkey") - - CheckError(err, "could not open client key in file") - - defer file.Close() - - scanner := bufio.NewScanner(file) - var line string - for scanner.Scan() { - line = fmt.Sprintf("%s", scanner.Text()) - } - - return line -} - -func GetPasswordFromSession(r *http.Request) (string, string) { - - c, err := r.Cookie("session_token") - - if err != nil { - return "", "" - } - - sessionToken := c.Value - - response, err := cache.Do("GET", sessionToken) - - if CheckError(err, "could not get session from cache") != nil { - return "", "" - } - - token := fmt.Sprintf("%s", response) - - parts := strings.Split(token, "|") - - if len(parts) > 1 { - return parts[0], parts[1] - } - - return "", "" -} -- cgit v1.2.3