<commit_before>package main

import (
	"flag"
	"log"
	"net/http"
	"text/template"

	"github.com/satori/go.uuid"
)


//////////////////////
//MAIN
/////////////////////

type user struct {
	UserName string
	Pass     string
}

var dbUsers = map[string]user{}
var dbSessions = map[string]string{}
var tpl *template.Template

func init() {
	tpl = template.Must(template.ParseGlob("templates/*"))
	dbUsers["Test"] = user{"Test", "<PASSWORD>"}
}

func homeHandler(tpl *template.Template) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		tpl.Execute(w, r)
	})
}


func sign_up(w http.ResponseWriter, req *http.Request) {
	c, err := req.Cookie("session")
	if err != nil {
		sID := uuid.NewV4()
		c = &http.Cookie{
			Name:  "session",
			Value: sID.String(),
		}
		http.SetCookie(w, c)
	}

	//Check form submission
	var u user
	if req.Method == http.MethodPost {
		un := req.FormValue("username")
		p := req.FormValue("password")

		c.Value = un
		u = user{un, p}

		dbUsers[c.Value] = u
		http.Redirect(w, req, "/login", http.StatusSeeOther)

		log.Println(dbUsers)
		return
	}

	//Executes Template
	tpl.ExecuteTemplate(w, "signup.gohtml", nil)
}

func login(w http.ResponseWriter, req *http.Request) {
	if req.Method == http.MethodPost {
		un := req.FormValue("username")
		p := req.FormValue("password")
		//Does this user exist?? Using comma ok idiom
		u, ok:= dbUsers[un]
		if !ok {
			http.Error(w, "Forbidden", http.StatusForbidden)
			//http.Redirect(w, req, "/login", http.StatusForbidden)
			return
		}
		//does the username/password combo match at all??
		if u.Pass != p {
			http.Error(w, "Forbidden", http.StatusForbidden)
			//http.Redirect(w, req, "/login", http.StatusForbidden)
			return
		}
		//Create a session
		sID := uuid.NewV4()
		c := &http.Cookie{
			Name:     "session",
			Value:    sID.String(),
			HttpOnly: true,
		}
		http.SetCookie(w, c)
		dbSessions[c.Value] = un
		http.Redirect(w, req, "/chat", http.StatusSeeOther)
		return
	}

	tpl.ExecuteTemplate(w, "login.gohtml", nil)
}



func main() {
	flag.Parse()
	tpl := template.Must(template.ParseFiles("templates/chat.gohtml"))
	h := newHub()
	router := http.NewServeMux()
	router.HandleFunc("/", sign_up)
	router.HandleFunc("/login", login)
	router.Handle("/chat", homeHandler(tpl))
	router.Handle("/ws", wsHandler{h: h})
	log.Println("serving on port 8080")
	log.Println("Users:", dbUsers)
	//log.Println("Sessions: ", dbSessions)
	log.Fatal(http.ListenAndServe(":8080", router))
}<commit_msg>Full functionality has been restored<commit_after>package main

import (
	"flag"
	"log"
	"net/http"
	"text/template"
	"github.com/EthanG78/golang_chat/lib"
	"github.com/satori/go.uuid"
)


//////////////////////
//MAIN
/////////////////////

type user struct {
	UserName string
	Pass     string
}

var dbUsers = map[string]user{}
var dbSessions = map[string]string{}
var tpl *template.Template

func init() {
	tpl = template.Must(template.ParseGlob("templates/*"))
	dbUsers["Test"] = user{"Test", "eth787878"}
}

func homeHandler(tpl *template.Template) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		tpl.Execute(w, r)
	})
}


func sign_up(w http.ResponseWriter, req *http.Request) {
	c, err := req.Cookie("session")
	if err != nil {
		sID := uuid.NewV4()
		c = &http.Cookie{
			Name:  "session",
			Value: sID.String(),
		}
		http.SetCookie(w, c)
	}

	//Check form submission
	var u user
	if req.Method == http.MethodPost {
		un := req.FormValue("username")
		p := req.FormValue("password")

		c.Value = un
		u = user{un, p}

		dbUsers[c.Value] = u
		http.Redirect(w, req, "/login", http.StatusSeeOther)

		log.Println(dbUsers)
		return
	}

	//Executes Template
	tpl.ExecuteTemplate(w, "signup.gohtml", nil)
}

func login(w http.ResponseWriter, req *http.Request) {
	if req.Method == http.MethodPost {
		un := req.FormValue("username")
		p := req.FormValue("password")
		//Does this user exist?? Using comma ok idiom
		u, ok:= dbUsers[un]
		if !ok {
			http.Error(w, "Forbidden", http.StatusForbidden)
			//http.Redirect(w, req, "/login", http.StatusForbidden)
			return
		}
		//does the username/password combo match at all??
		if u.Pass != p {
			http.Error(w, "Forbidden", http.StatusForbidden)
			//http.Redirect(w, req, "/login", http.StatusForbidden)
			return
		}
		//Create a session
		sID := uuid.NewV4()
		c := &http.Cookie{
			Name:     "session",
			Value:    sID.String(),
			HttpOnly: true,
		}
		http.SetCookie(w, c)
		dbSessions[c.Value] = un
		http.Redirect(w, req, "/chat", http.StatusSeeOther)
		return
	}

	tpl.ExecuteTemplate(w, "login.gohtml", nil)
}



func main() {
	flag.Parse()
	tpl := template.Must(template.ParseFiles("templates/chat.gohtml"))
	H := lib.NewHub()
	router := http.NewServeMux()
	router.HandleFunc("/", sign_up)
	router.HandleFunc("/login", login)
	router.Handle("/chat", homeHandler(tpl))
	router.Handle("/ws", lib.WsHandler{H:H})
	log.Println("serving on port 8080")
	log.Println("Users:", dbUsers)
	//log.Println("Sessions: ", dbSessions)
	log.Fatal(http.ListenAndServe(":8080", router))
}
{'fraction_non_alphanumeric': 0.18242579123255356, 'fraction_numerical': 0.00550422645960291, 'mean_word_length': 3.5307212822796084, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 4, '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': '2661227', 'n_tokens_mistral': 2005, 'n_tokens_neox': 1880, 'n_words': 402}