<commit_before>package users

import (
	"errors"
	"github.com/Unknwon/com"
	"github.com/belogik/goes"
	"github.com/firstrow/logvoyage/web/render"
	"github.com/martini-contrib/sessions"
	"net/http"
	"net/url"
)

type loginForm struct {
	Email    string
	Password string
	*EnableValidation
}

func (this *loginForm) SetupValidation() {
	this.Valid.Required(this.Email, "Email")
	this.Valid.Email(this.Email, "Email")
	this.Valid.Required(this.Password, "Password")
	this.Valid.MinSize(this.Password, 5, "Password")
	this.Valid.MaxSize(this.Password, 25, "Password")
}

func findUser(form *loginForm) error {
	conn := goes.NewConnection("localhost", "9200")

	var query = map[string]interface{}{
		"query": map[string]interface{}{
			"bool": map[string]interface{}{
				"must": map[string]interface{}{
					"term": map[string]interface{}{
						"email": map[string]interface{}{
							"value": form.Email,
						},
					},
				},
			},
		},
	}

	extraArgs := make(url.Values, 0)
	searchResults, err := conn.Search(query, []string{"users"}, []string{"user"}, extraArgs)

	if err != nil {
		return err
	}

	if searchResults.Hits.Total == 0 {
		return errors.New("User not found")
	}

	hash := com.Sha256(form.Password)
	if searchResults.Hits.Hits[0].Source["password"] != hash {<commit_msg>Added comment<commit_after>package users

import (
	"errors"
	"github.com/Unknwon/com"
	"github.com/belogik/goes"
	"github.com/firstrow/logvoyage/web/render"
	"github.com/martini-contrib/sessions"
	"net/http"
	"net/url"
)

type loginForm struct {
	Email    string
	Password string
	*EnableValidation
}

func (this *loginForm) SetupValidation() {
	this.Valid.Required(this.Email, "Email")
	this.Valid.Email(this.Email, "Email")
	this.Valid.Required(this.Password, "Password")
	this.Valid.MinSize(this.Password, 5, "Password")
	this.Valid.MaxSize(this.Password, 25, "Password")
}

// Search user by login and password
func findUser(form *loginForm) error {
	conn := goes.NewConnection("localhost", "9200")

	var query = map[string]interface{}{
		"query": map[string]interface{}{
			"bool": map[string]interface{}{
				"must": map[string]interface{}{
					"term": map[string]interface{}{
						"email": map[string]interface{}{
							"value": form.Email,
						},
					},
				},
			},
		},
	}

	extraArgs := make(url.Values, 0)
	searchResults, err := conn.Search(query, []string{"users"}, []string{"user"}, extraArgs)

	if err != nil {
		return err
	}

	if searchResults.Hits.Total == 0 {
		return errors.New("User not found")
	}

	hash := com.Sha256(form.Password)
	if searchResults.Hits.Hits[0].Source["password"] != hash {
{'fraction_non_alphanumeric': 0.17261219792865362, 'fraction_numerical': 0.009973149213655544, 'mean_word_length': 4.311608961303462, 'pattern_counts': {'":': 12, '<': 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': '4709174', 'n_tokens_mistral': 1016, 'n_tokens_neox': 911, 'n_words': 171}