<commit_before>package auth

import (
	"fmt"

	"github.com/dokkur/swanager/core/entities"
	"github.com/dokkur/swanager/lib"
)

// WithToken authenticates with token
func WithToken(token string) (*entities.User, error) {
	if token == "" {
		return nil, fmt.Errorf("Empty token")
	}

	user, err := entities.GetUserByToken(token)
	if err != nil {
		return nil, fmt.Errorf("AuthWithToken error: %s", err)
	}

	return user, nil
}

// WithEmailAndPassword auths user with email and password, return newly created token
func WithEmailAndPassword(email, password string) (*entities.Token, error) {
	user, err := entities.GetUser(email)
	if err != nil {
		return nil, authError()
	}

	if user.Password != lib.CalculateMD5(password) {
		return nil, authError()
	}

	token := entities.GenerateToken()
	token.User = user
<commit_msg>Straighten auth<commit_after>package auth

import (
	"fmt"

	"github.com/dokkur/swanager/core/entities"
	"github.com/dokkur/swanager/lib"
)

// WithToken authenticates with token
func WithToken(token string) (*entities.User, error) {
	if token == "" {
		return nil, fmt.Errorf("Empty token")
	}

	user, err := entities.GetUserByToken(token)
	if err != nil {
		return nil, fmt.Errorf("AuthWithToken error: %s", err)
	}

	return user, nil
}

// WithEmailAndPassword auths user with email and password, return newly created token
func WithEmailAndPassword(email, password string) (*entities.Token, error) {
	if email == "" || password == "" {
		return nil, authError()
	}

	user, err := entities.GetUser(email)
	if err != nil {
		return nil, authError()
	}

	if user.Password != lib.CalculateMD5(password) {
		return nil, authError()
	}

	token := entities.GenerateToken()
	token.User = user

{'fraction_non_alphanumeric': 0.1327485380116959, 'fraction_numerical': 0.0011695906432748538, 'mean_word_length': 4.313664596273292, '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': '1629873', 'n_tokens_mistral': 593, 'n_tokens_neox': 571, 'n_words': 151}