<commit_before>package http

import (
	"net/http"
	"time"

	"github.com/pkg/errors"

	"github.com/VagabondDataNinjas/gizlinebot/storage"
	jwt "github.com/dgrijalva/jwt-go"
	"github.com/labstack/echo"
	log "github.com/sirupsen/logrus"
)

func loginHandler(s *storage.Sql) func(c echo.Context) error {
	return func(c echo.Context) error {
		inputUser := c.FormValue("user")
		inputPass := c.FormValue("pass")

		user, err := s.GetConfigVal("adminUser")
		if err != nil {
			return err
		}
		pass, err := s.GetConfigVal("adminPass")
		if err != nil {
			return err
		}
		secret, err := s.GetConfigVal("jwtSecret")
		if err != nil {
			return err
		}

		log.Infof("User: %s; Pass: %s", user, pass)
		log.Infof("Iuser: %s; iPass: %s", user, pass)

		if user == "" || pass == "" || secret == "" {
			return errors.New("Setup error: missing adminUser, adminUser, or jwtSecret from DB setup")
		}

		if inputUser == user && inputPass == pass {
			// Create token
			token := jwt.New(jwt.SigningMethodHS256)

			// Set claims
			claims := token.Claims.(jwt.MapClaims)
			claims["exp"] = time.Now().Add(time.Hour * 72).Unix()

			// Generate encoded token and send it as response.
			t, err := token.SignedString([]byte(secret))
			if err != nil {
				return err
			}
			return c.JSON(http.StatusOK, map[string]string{
				"token": t,
			})
		}

		return echo.ErrUnauthorized
	}
}<commit_msg>Set cooking on login<commit_after>package http

import (
	"net/http"
	"time"

	"github.com/pkg/errors"

	"github.com/VagabondDataNinjas/gizlinebot/storage"
	jwt "github.com/dgrijalva/jwt-go"
	"github.com/labstack/echo"
	log "github.com/sirupsen/logrus"
)

func loginHandler(s *storage.Sql) func(c echo.Context) error {
	return func(c echo.Context) error {
		inputUser := c.FormValue("user")
		inputPass := c.FormValue("pass")

		user, err := s.GetConfigVal("adminUser")
		if err != nil {
			return err
		}
		pass, err := s.GetConfigVal("adminPass")
		if err != nil {
			return err
		}
		secret, err := s.GetConfigVal("jwtSecret")
		if err != nil {
			return err
		}

		log.Infof("User: %s; Pass: %s", user, pass)
		log.Infof("Iuser: %s; iPass: %s", user, pass)

		if user == "" || pass == "" || secret == "" {
			return errors.New("Setup error: missing adminUser, adminUser, or jwtSecret from DB setup")
		}

		if inputUser == user && inputPass == pass {
			// Create token
			token := jwt.New(jwt.SigningMethodHS256)

			// Set claims
			claims := token.Claims.(jwt.MapClaims)
			claims["exp"] = time.Now().Add(time.Hour * 72).Unix()

			// Generate encoded token
			t, err := token.SignedString([]byte(secret))
			if err != nil {
				return err
			}

			cookie := new(http.Cookie)
			cookie.Name = "token"
			cookie.Value = t
			cookie.Expires = time.Now().Add(87600 * time.Hour)
			c.SetCookie(cookie)

			return c.JSON(http.StatusOK, map[string]string{
				"status": "success",
			})
		}

		return echo.ErrUnauthorized
	}
}
{'fraction_non_alphanumeric': 0.16191130972842901, 'fraction_numerical': 0.005156411137848058, 'mean_word_length': 3.2920353982300883, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6907458', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1067, 'n_words': 240}