<commit_before>package readraptor

import (
	"bytes"
	"database/sql"
	"encoding/base64"
	"fmt"
	"net/http"
	"os"
	"strings"
	"text/template"
	"time"

	"github.com/codegangsta/martini"
	"github.com/cupcake/gokiq"
	pq "github.com/lib/pq"
	"github.com/martini-contrib/render"
	"github.com/martini-contrib/sessionauth"
	"github.com/martini-contrib/sessions"
	"github.com/technoweenie/grohl"
)

func GetAccount(r render.Render, user sessionauth.User) {
	data := struct {
		StripeKey string
		Account   *Account
	}{
		os.Getenv("STRIPE_PUBLISHABLE"),
		user.(*Account),
	}
	r.HTML(200, "account", data)
}

func PostAccounts(client *gokiq.ClientConfig, rw http.ResponseWriter, req *http.Request) {
	if err := req.ParseForm(); err != nil {
		panic(err)
	}

	account := NewAccount(req.PostForm["email"][0])
	err := dbmap.Insert(account)
	if err != nil {
		if _, ok := err.(*pq.Error); ok {
			if strings.Index(err.Error(), `duplicate key value violates unique constraint "accounts_email_key"`) > -1 {
				rw.Write([]byte("Email is already taken"))
				return
			}
		}
		panic(err)
	}

	account.SendNewAccountEmail(client)

	template, err := template.ParseFiles("templates/welcome.txt.tmpl")
	if err != nil {
		panic(err)
	}

	var buf bytes.Buffer
	err = template.Execute(&buf, nil)
	if err != nil {
		panic(err)
	}

	fmt.Fprintln(rw, buf.String())
}

func PostAccountBilling(rw http.ResponseWriter, req *http.Request, user sessionauth.User) {<commit_msg>do some basic email validation<commit_after>package readraptor

import (
	"bytes"
	"database/sql"
	"encoding/base64"
	"fmt"
	"net/http"
	"os"
	"strings"
	"text/template"
	"time"

	"github.com/codegangsta/martini"
	"github.com/cupcake/gokiq"
	"github.com/lib/pq"
	"github.com/martini-contrib/render"
	"github.com/martini-contrib/sessionauth"
	"github.com/martini-contrib/sessions"
	"github.com/technoweenie/grohl"
)

func GetAccount(r render.Render, user sessionauth.User) {
	data := struct {
		StripeKey string
		Account   *Account
	}{
		os.Getenv("STRIPE_PUBLISHABLE"),
		user.(*Account),
	}
	r.HTML(200, "account", data)
}

func PostAccounts(client *gokiq.ClientConfig, rw http.ResponseWriter, req *http.Request) {
	if err := req.ParseForm(); err != nil {
		panic(err)
	}

	email := strings.Replace(req.PostForm["email"][0], " ", "", -1)

	if strings.Index(email, "@") == -1 {
		rw.Write([]byte("Email is invalid"))
		return
	}

	account := NewAccount(email)
	err := dbmap.Insert(account)
	if err != nil {
		if _, ok := err.(*pq.Error); ok {
			if strings.Index(err.Error(), `duplicate key value violates unique constraint "accounts_email_key"`) > -1 {
				rw.Write([]byte("Email is already taken"))
				return
			}
		}
		panic(err)
	}

	account.SendNewAccountEmail(client)

	template, err := template.ParseFiles("templates/welcome.txt.tmpl")
	if err != nil {
		panic(err)
	}

	var buf bytes.Buffer
	err = template.Execute(&buf, nil)
	if err != nil {
		panic(err)
	}

	fmt.Fprintln(rw, buf.String())
}

func PostAccountBilling(rw http.ResponseWriter, req *http.Request, user sessionauth.User) {
{'fraction_non_alphanumeric': 0.15981585004932589, 'fraction_numerical': 0.005261427162117725, 'mean_word_length': 4.191126279863481, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6165147', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1136, 'n_words': 219}