<commit_before>package signup

import (
	"database/sql"
	"github.com/gorilla/context"
	"github.com/gorilla/mux"
	_ "github.com/lib/pq"
	"gopkg.in/unrolled/render.v1"
	"log"
	"net/http"
	"encoding/json"
)

type Signup struct {
	Email 		string 		`json:"email"`
	Password 	string 		`json:"password"`
}

func Init(router *mux.Router) {
	router.Methods("POST").Path("/signup").HandlerFunc(signup)
}
/*
{
	"email": "<EMAIL>",
	"password": "<PASSWORD>"
}
*/
func signup(w http.ResponseWriter, req *http.Request) {
	render := context.Get(req, "render").(*render.Render)
	db := context.Get(req, "db").(*sql.DB)
	decoder := json.NewDecoder(req.Body)

	signup := Signup{} 
	err := decoder.Decode(&signup)
	if err != nil {
		render.JSON(w, http.StatusBadRequest, map[string]string{"error": err.Error()})
	} else {
		rows, err := db.Query("SELECT 1 FROM users WHERE email = $1", signup.Email)
		if err != nil {
			render.JSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
		} else {
			defer rows.Close()
			if rows.Next() {
				render.JSON(w, http.StatusBadRequest, map[string]string{"error": "Email's already existed."})
				return
			}
		}

		stmt, err := db.Prepare("INSERT INTO users(encrypted_password, email) VALUES ($1, $2)")
		if err != nil {
			log.Print(err)
			render.JSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
			return
		}
		_, err = stmt.Exec(signup.Password, signup.Email)
		if err != nil {
			log.Print(err)
			render.JSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
			return
		}

		if err != nil {
			render.JSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
		} else {
			render.JSON(w, http.StatusOK, map[string]string{"success": ""})
		}
	}
}<commit_msg>signing up email and password cannot be null<commit_after>package signup

import (
	"database/sql"
	"github.com/gorilla/context"
	"github.com/gorilla/mux"
	_ "github.com/lib/pq"
	"gopkg.in/unrolled/render.v1"
	"log"
	"net/http"
	"encoding/json"
)

type Signup struct {
	Email 		string 		`json:"email"`
	Password 	string 		`json:"password"`
}

func Init(router *mux.Router) {
	router.Methods("POST").Path("/signup").HandlerFunc(signup)
}
/*
{
	"email": "<EMAIL>",
	"password": "<PASSWORD>"
}
*/
func signup(w http.ResponseWriter, req *http.Request) {
	render := context.Get(req, "render").(*render.Render)
	db := context.Get(req, "db").(*sql.DB)
	decoder := json.NewDecoder(req.Body)

	signup := Signup{} 
	err := decoder.Decode(&signup)
	if err != nil {
		render.JSON(w, http.StatusBadRequest, map[string]string{"error": err.Error()})
	} else {
		if len(signup.Email) == 0 || len(signup.Password) == 0 {
			render.JSON(w, http.StatusBadRequest, map[string]string{"error": "Email/Password cannot be null."})
			return
		}
		
		rows, err := db.Query("SELECT 1 FROM users WHERE email = $1", signup.Email)
		if err != nil {
			render.JSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
		} else {
			defer rows.Close()
			if rows.Next() {
				render.JSON(w, http.StatusBadRequest, map[string]string{"error": "Email's already existed."})
				return
			}
		}

		stmt, err := db.Prepare("INSERT INTO users(encrypted_password, email) VALUES ($1, $2)")
		if err != nil {
			log.Print(err)
			render.JSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
			return
		}
		_, err = stmt.Exec(signup.Password, signup.Email)
		if err != nil {
			log.Print(err)
			render.JSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
			return
		}

		if err != nil {
			render.JSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
		} else {
			render.JSON(w, http.StatusOK, map[string]string{"success": ""})
		}
	}
}
{'fraction_non_alphanumeric': 0.18097997892518441, 'fraction_numerical': 0.003161222339304531, 'mean_word_length': 4.237241379310345, 'pattern_counts': {'":': 19, '<': 7, '<?xml version=': 0, '>': 7, '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': '7173379', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1371, 'n_words': 268}