Ejemplo n.º 1
0
func RenderRegister(w http.ResponseWriter, r *http.Request, title string) {
	data := mod.Page{
		Title: title,
		CSS:   []string{"register", "style"},
	}
	if r.Method == "POST" {
		err := con.Register(w, r) // checks username isnt taken then registers the user
		if err != nil {
			errorString := []string{err.Error(), "Error 2"}
			data.Message = append(data.Message, errorString...)
		} else {
			http.Redirect(w, r, "/account", 302)
		}
	}
	t, _ := template.ParseFiles("templates/_front.html", "templates/register.html")
	if err := t.Execute(w, data); err != nil {
		fmt.Println(err)
		return
	}
}
Ejemplo n.º 2
0
func RenderLogin(w http.ResponseWriter, r *http.Request, title string) {
	t, _ := template.ParseFiles("templates/_front.html", "templates/login.html")
	data := mod.Page{
		Title: title,
		CSS:   []string{"login"}}
	if r.Method == "POST" {
		err := con.Login(w, r)
		if err != nil {
			errorString := []string{err.Error(), "There was a problem logging in"}
			data.Message = append(data.Message, errorString...)
			t.Execute(w, data)
		} else {
			fmt.Println("success") // DEV
			http.Redirect(w, r, "/account", 302)
		}
	}
	if err := t.Execute(w, data); err != nil {
		fmt.Println(err)
		return
	}
}