<commit_before>package controller

import (
	"net/http"
	"encoding/json"
	"rest-commander/store"
	"strings"
	"rest-commander/model/dto"
)

type AuthenticationController interface {
	HandleLogin(w http.ResponseWriter, r *http.Request)
	HandleLogout(w http.ResponseWriter, r *http.Request)
}

type AccessDeniedController interface {
	HandleAccessDenied(w http.ResponseWriter, r *http.Request)
}

func (t *AuthenticationRoute) HandleAccessDenied(w http.ResponseWriter, r *http.Request){
	HandleAccessDenied(w, r)
}

func HandleAccessDenied(w http.ResponseWriter, r *http.Request){
	w.WriteHeader(http.StatusForbidden)
}

func ExtractTokenFromRequest(r *http.Request) string{
	for h, v := range r.Header {
		if strings.EqualFold(h, HEADER_TOKEN) {
			return v[0]
		}
	}

	return ""
}

func (t *AuthenticationRoute) HandleLogin(w http.ResponseWriter, r *http.Request){
	var auth dto.LoginRequest
	err := json.NewDecoder(r.Body).Decode(&auth)

	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}

	if !t.userStore.CheckPassword(auth.Username, auth.Password) {
		resp := dto.ErrorResponse{
			Message: "Username or password are incorrect!",
		}
		w.WriteHeader(http.StatusBadRequest)
		json.NewEncoder(w).Encode(resp)
		return
	}

	token := store.NewAuthenticationToken(auth.Username)

	t.tokenStore.Add(token)
	resp := dto.LoginResponse{<commit_msg>store users password after login<commit_after>package controller

import (
	"net/http"
	"encoding/json"
	"rest-commander/store"
	"strings"
	"rest-commander/model/dto"
)

type AuthenticationController interface {
	HandleLogin(w http.ResponseWriter, r *http.Request)
	HandleLogout(w http.ResponseWriter, r *http.Request)
}

type AccessDeniedController interface {
	HandleAccessDenied(w http.ResponseWriter, r *http.Request)
}

func (t *AuthenticationRoute) HandleAccessDenied(w http.ResponseWriter, r *http.Request){
	HandleAccessDenied(w, r)
}

func HandleAccessDenied(w http.ResponseWriter, r *http.Request){
	w.WriteHeader(http.StatusForbidden)
}

func ExtractTokenFromRequest(r *http.Request) string{
	for h, v := range r.Header {
		if strings.EqualFold(h, HEADER_TOKEN) {
			return v[0]
		}
	}

	return ""
}

func (t *AuthenticationRoute) HandleLogin(w http.ResponseWriter, r *http.Request){
	var auth dto.LoginRequest
	err := json.NewDecoder(r.Body).Decode(&auth)

	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}

	if !t.userStore.CheckPassword(auth.Username, auth.Password) {
		resp := dto.ErrorResponse{
			Message: "Username or password are incorrect!",
		}
		w.WriteHeader(http.StatusBadRequest)
		json.NewEncoder(w).Encode(resp)
		return
	}

	token := store.NewAuthenticationToken(auth.Username)

	t.tokenStore.Add(token)
	t.userStore.Get(auth.Username).Password = auth.Password

	resp := dto.LoginResponse{
{'fraction_non_alphanumeric': 0.12423698384201078, 'fraction_numerical': 0.002872531418312388, 'mean_word_length': 5.123076923076923, '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': '3311218', 'n_tokens_mistral': 990, 'n_tokens_neox': 948, 'n_words': 193}