<commit_before>package main

import (
	"time"

	"bitbucket.org/firstrow/logvoyage/models"
	"bitbucket.org/firstrow/logvoyage/shared/config"

	jwt "github.com/dgrijalva/jwt-go"
	"github.com/go-ozzo/ozzo-validation"
	"github.com/go-ozzo/ozzo-validation/is"
	"golang.org/x/crypto/bcrypt"
	"gopkg.in/kataras/iris.v6"
)

type userData struct {
	Email    string `json:"email"`
	Name     string `json:"name"`
	Password string `json:"password"`
}

func (u userData) Validate() error {
	return validation.ValidateStruct(&u,
		validation.Field(&u.Email, validation.Required, is.Email),
		validation.Field(&u.Name, validation.Required, validation.Length(3, 255)),
		validation.Field(&u.Password, validation.Required, validation.Length(5, 255)),
	)
}

func UsersCreate(ctx *iris.Context) {
	var data userData
	ctx.ReadJSON(&data)

	err := data.Validate()

	if err != nil {
		response.Error(ctx, err)
		return
	}

	exists, res := models.EmailExists(data.Email)

	if res.Error != nil {
		response.Panic(ctx, err)
		return
	}

	if exists == true {
		response.Error(ctx, "Email is already used")
		return
	}

	_, res = models.CreateUser(data.Email, data.Name, data.Password)

	if res.Error != nil {
		response.Panic(ctx, err)
		return
	}

	response.Success(ctx)
}

func UsersLogin(ctx *iris.Context) {
	var data userData
	ctx.ReadJSON(&data)

	user, res := models.FindUserByEmail(data.Email)

	if res.Error != nil {
		if res.RecordNotFound() {
			response.Error(ctx, "User not found")
		} else {
			response.Panic(ctx, res.Error)
		}
		return
	}<commit_msg>Small refactor<commit_after>package main

import (
	"time"

	"bitbucket.org/firstrow/logvoyage/models"
	"bitbucket.org/firstrow/logvoyage/shared/config"

	jwt "github.com/dgrijalva/jwt-go"
	"github.com/go-ozzo/ozzo-validation"
	"github.com/go-ozzo/ozzo-validation/is"
	"golang.org/x/crypto/bcrypt"
	"gopkg.in/kataras/iris.v6"
)

type userData struct {
	Email    string `json:"email"`
	Name     string `json:"name"`
	Password string `json:"password"`
}

func (u userData) Validate() error {
	return validation.ValidateStruct(&u,
		validation.Field(&u.Email, validation.Required, is.Email),
		validation.Field(&u.Name, validation.Required, validation.Length(3, 255)),
		validation.Field(&u.Password, validation.Required, validation.Length(5, 255)),
	)
}

func UsersCreate(ctx *iris.Context) {
	var data userData
	ctx.ReadJSON(&data)

	err := data.Validate()

	if err != nil {
		response.Error(ctx, err)
		return
	}

	exists, res := models.EmailExists(data.Email)

	if res.Error != nil {
		response.Panic(ctx, err)
		return
	}

	if exists {
		response.Error(ctx, "Email is already used")
		return
	}

	_, res = models.CreateUser(data.Email, data.Name, data.Password)

	if res.Error != nil {
		response.Panic(ctx, err)
		return
	}

	response.Success(ctx)
}

func UsersLogin(ctx *iris.Context) {
	var data userData
	ctx.ReadJSON(&data)

	user, res := models.FindUserByEmail(data.Email)

	if res.Error != nil {
		if res.RecordNotFound() {
			response.Error(ctx, "User not found")
		} else {
			response.Panic(ctx, res.Error)
		}
		return
	}
{'fraction_non_alphanumeric': 0.1469918699186992, 'fraction_numerical': 0.005853658536585366, 'mean_word_length': 4.059210526315789, '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': '4457835', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1133, 'n_words': 218}