<commit_before>package handlers

import (
	"fmt"

	"github.com/dgrijalva/jwt-go"
	"github.com/gin-gonic/gin"

	"github.com/gobricks/facecontrol/classes/credentials"
	"github.com/gobricks/facecontrol/classes/response"
	"github.com/gobricks/facecontrol/config"
)

// Check accepts JWT token string and returns user credentials
func Check(c *gin.Context) {
	tokenString := c.Param("token")

	token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
		if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
			return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
		}
		return []byte(config.JWTSecret), nil
	})

	if err != nil || token.Valid == false {
		c.JSON(400, response.BaseResponse{
			Success: false,
			Error:   err.Error(),
		})
		return
	}

	credentials := c.MustGet("credentials").(*credentials.Credentials)
	uid := token.Claims["uid"].(string)

	user, err := credentials.Get(uid)
	if err != nil {
		c.JSON(400, response.BaseResponse{
			Success: false,
			Error:   err.Error(),
		})
		return
	}

	c.JSON(200, response.UserResponse{
		BaseResponse: response.BaseResponse{
			Success: true,
		},
		User: user.Payload,
	})
}
<commit_msg>using right HTTP status codes<commit_after>package handlers

import (
	"fmt"
	"net/http"

	"github.com/dgrijalva/jwt-go"
	"github.com/gin-gonic/gin"

	"github.com/gobricks/facecontrol/classes/credentials"
	"github.com/gobricks/facecontrol/classes/response"
	"github.com/gobricks/facecontrol/config"
)

// Check accepts JWT token string and returns user credentials
func Check(c *gin.Context) {
	tokenString := c.Param("token")

	token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
		if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
			return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
		}
		return []byte(config.JWTSecret), nil
	})

	if err != nil {
		c.JSON(400, response.BaseResponse{
			Success: false,
			Error:   err.Error(),
		})
		return
	}
	
	if token.Valid == false {
		c.JSON(403, response.BaseResponse{
			Success: false,
			Error:   http.StatusText(http.StatusForbidden),
		})
		return
	}

	credentials := c.MustGet("credentials").(*credentials.Credentials)
	uid := token.Claims["uid"].(string)

	user, err := credentials.Get(uid)
	if err != nil {
		c.JSON(404, response.BaseResponse{
			Success: false,
			Error:   err.Error(),
		})
		return
	}

	c.JSON(200, response.UserResponse{
		BaseResponse: response.BaseResponse{
			Success: true,
		},
		User: user.Payload,
	})
}

{'fraction_non_alphanumeric': 0.15717092337917485, 'fraction_numerical': 0.008251473477406679, 'mean_word_length': 4.031620553359684, 'pattern_counts': {'":': 0, '<': 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': '6477947', 'n_tokens_mistral': 990, 'n_tokens_neox': 897, 'n_words': 175}