<commit_before>package controllers

import (
    "github.com/revel/revel"
    "encoding/json"
    "io/ioutil"
    "github.com/ip4368/go-password"
    "github.com/ip4368/go-userprofile"
    "github.com/janekolszak/revmgo"
)

func init() {
    revmgo.ControllerInit()
}

type Users struct {
    *revel.Controller
}

type RegisterProfile struct {
    Username string `json:"username"`
    Password string `json:"password"`
    Email string `json:"email"`
}

func (c *Users) Register() revel.Result {
	// start with initialise response interface
	data := make(map[string]interface{})
	data["error"] = nil
	data["message"] = "Successfully Registered"

	// read request body to byte
	var r RegisterProfile
	var bodyBytes []byte
	if c.Request.Body != nil {
		bodyBytes, _ = ioutil.ReadAll(c.Request.Body)
	}
	json.Unmarshal([]byte(bodyBytes), &r)

	// validate all email, username and password
	if !userprofile.ValidateEmail(r.Email) {
		data["error"] = 1
		data["message"] = "Invalid Email"
		return c.RenderJson(data)
	}
	if !userprofile.ValidateUsername(r.Username) {
		data["error"] = 2
		data["message"] = "Invalid Username"
		return c.RenderJson(data)
	}
	if !password.ValidatePassword(r.Password) {
		data["error"] = 3
		data["message"] = "Invalid Password"
		return c.RenderJson(data)
	}
	
	//hashed, salt, _ := password.HashAutoSalt(r.Password)
	return c.RenderJson(data)
}

func (c *Users) Login() revel.Result {
	// start with initialise response interface
	data := make(map[string]interface{})
	data["error"] = nil
	data["message"] = "Successfully Logged In"

	// read request body to byte<commit_msg>add mgo to the Users controller<commit_after>package controllers

import (
    "github.com/revel/revel"
    "encoding/json"
    "io/ioutil"
    "github.com/ip4368/go-password"
    "github.com/ip4368/go-userprofile"
    "github.com/janekolszak/revmgo"
)

func init() {
    revmgo.ControllerInit()
}

/*type Users struct {
    *revel.Controller
}*/

type Users struct {
    *revel.Controller
    revmgo.MongoController
}

type RegisterProfile struct {
    Username string `json:"username"`
    Password string `json:"password"`
    Email string `json:"email"`
}

func (c Users) Register() revel.Result {
	// start with initialise response interface
	data := make(map[string]interface{})
	data["error"] = nil
	data["message"] = "Successfully Registered"

	// read request body to byte
	var r RegisterProfile
	var bodyBytes []byte
	if c.Request.Body != nil {
		bodyBytes, _ = ioutil.ReadAll(c.Request.Body)
	}
	json.Unmarshal([]byte(bodyBytes), &r)

	// validate all email, username and password
	if !userprofile.ValidateEmail(r.Email) {
		data["error"] = 1
		data["message"] = "Invalid Email"
		return c.RenderJson(data)
	}
	if !userprofile.ValidateUsername(r.Username) {
		data["error"] = 2
		data["message"] = "Invalid Username"
		return c.RenderJson(data)
	}
	if !password.ValidatePassword(r.Password) {
		data["error"] = 3
		data["message"] = "Invalid Password"
		return c.RenderJson(data)
	}
	
	//hashed, salt, _ := password.HashAutoSalt(r.Password)
	return c.RenderJson(data)
}

func (c Users) Login() revel.Result {
	// start with initialise response interface
	data := make(map[string]interface{})
	data["error"] = nil
	data["message"] = "Successfully Logged In"

	// read request body to byte
{'fraction_non_alphanumeric': 0.14134382566585957, 'fraction_numerical': 0.006658595641646489, 'mean_word_length': 4.069018404907975, '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': '5182426', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1106, 'n_words': 257}