<commit_before>package main

import (
	"database/sql"
	"github.com/coopernurse/gorp"
	"github.com/go-martini/martini"
	_ "github.com/go-sql-driver/mysql"
	_ "github.com/lib/pq"
	"github.com/martini-contrib/binding"
	"github.com/martini-contrib/cors"
	"github.com/martini-contrib/method"
	"github.com/martini-contrib/render"
	"github.com/martini-contrib/sessions"
	_ "github.com/mattn/go-sqlite3"
	"github.com/pascalj/disgo/handler"
	"github.com/pascalj/disgo/models"
	"github.com/pascalj/disgo/service"
	"github.com/russross/blackfriday"
	"github.com/ungerik/go-gravatar"
	"html/template"
	"log"
	"net/http"
	"strings"
	"time"
)

var (
	m   *martini.ClassicMartini
	cfg models.Config
)

func init() {
	m = martini.Classic()
	cfg = models.LoadConfig()
	m.Map(cfg)
	m.Map(initDb(cfg))
	m.Use(sessions.Sessions("session", sessions.NewCookieStore([]byte("secret"))))
	m.Use(cors.Allow(&cors.Options{
		AllowOrigins:     cfg.General.Origin,
		AllowCredentials: true,
	}))
	m.Use(method.Override())
	m.Use(render.Renderer(render.Options{
		Funcs: viewhelper(),
	}))
	m.Use(handler.MapView)
	m.Map(service.MapNotifier(cfg))
}

func main() {
	r := martini.NewRouter()
	r.Group(`/comments`, func(r martini.Router) {
		r.Get(`/:id`, handler.GetComment)
		r.Post(``, binding.Bind(models.Comment{}), rateLimit, handler.CreateComment)
		r.Get(``, handler.GetComments)
		r.Post(`/approve/:id`, handler.ApproveComment)
		r.Delete(`/:id`, handler.DestroyComment)
	})
	r.Group(`/admin`, func(r martini.Router) {
		r.Get(``, handler.RequireLogin, handler.AdminIndex)
		r.Get(`/unapproved`, handler.RequireLogin, handler.UnapprovedComments)
	})
	r.Get(`/login`, handler.GetLogin)
	r.Post(`/login`, handler.PostLogin)
	r.Post(`/logout`, handler.PostLogout)
	r.Get(`/register`, handler.GetRegister)
	r.Post(`/user`, handler.PostUser)
	r.Get(`/`, getIndex)
	m.Action(r.Handle)
	m.Run()
}

func initDb(cfg models.Config) *gorp.DbMap {<commit_msg>Require login to approve comments<commit_after>package main

import (
	"database/sql"
	"github.com/coopernurse/gorp"
	"github.com/go-martini/martini"
	_ "github.com/go-sql-driver/mysql"
	_ "github.com/lib/pq"
	"github.com/martini-contrib/binding"
	"github.com/martini-contrib/cors"
	"github.com/martini-contrib/method"
	"github.com/martini-contrib/render"
	"github.com/martini-contrib/sessions"
	_ "github.com/mattn/go-sqlite3"
	"github.com/pascalj/disgo/handler"
	"github.com/pascalj/disgo/models"
	"github.com/pascalj/disgo/service"
	"github.com/russross/blackfriday"
	"github.com/ungerik/go-gravatar"
	"html/template"
	"log"
	"net/http"
	"strings"
	"time"
)

var (
	m   *martini.ClassicMartini
	cfg models.Config
)

func init() {
	m = martini.Classic()
	cfg = models.LoadConfig()
	m.Map(cfg)
	m.Map(initDb(cfg))
	m.Use(sessions.Sessions("session", sessions.NewCookieStore([]byte("secret"))))
	m.Use(cors.Allow(&cors.Options{
		AllowOrigins:     cfg.General.Origin,
		AllowCredentials: true,
	}))
	m.Use(method.Override())
	m.Use(render.Renderer(render.Options{
		Funcs: viewhelper(),
	}))
	m.Use(handler.MapView)
	m.Map(service.MapNotifier(cfg))
}

func main() {
	r := martini.NewRouter()
	r.Group(`/comments`, func(r martini.Router) {
		r.Get(`/:id`, handler.GetComment)
		r.Post(``, binding.Bind(models.Comment{}), rateLimit, handler.CreateComment)
		r.Get(``, handler.GetComments)
		r.Post(`/approve/:id`, handler.RequireLogin, handler.ApproveComment)
		r.Delete(`/:id`, handler.DestroyComment)
	})
	r.Group(`/admin`, func(r martini.Router) {
		r.Get(``, handler.RequireLogin, handler.AdminIndex)
		r.Get(`/unapproved`, handler.RequireLogin, handler.UnapprovedComments)
	})
	r.Get(`/login`, handler.GetLogin)
	r.Post(`/login`, handler.PostLogin)
	r.Post(`/logout`, handler.PostLogout)
	r.Get(`/register`, handler.GetRegister)
	r.Post(`/user`, handler.PostUser)
	r.Get(`/`, getIndex)
	m.Action(r.Handle)
	m.Run()
}

func initDb(cfg models.Config) *gorp.DbMap {
{'fraction_non_alphanumeric': 0.18467078189300412, 'fraction_numerical': 0.00051440329218107, 'mean_word_length': 4.813153961136024, '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': '2687211', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1563, 'n_words': 197}