func HandleInventoryUpdate(w http.ResponseWriter, r *http.Request, ctx *parser.Context) {
	ctx.Title = "Ingress Inventory"
	ctx.AddJavascript("/js/update-inventory.js")
	if err := parser.Render(w, ctx, "update-inventory.html"); err != nil {
		log.Println(err)
	}
}
예제 #2
0
func HandleIndex(w http.ResponseWriter, r *http.Request) {
	ctx := &parser.Context{
		Title:       "Ingress Inventory",
		Description: "Track your inventory",
	}
	if err := parser.Render(w, ctx, "index.html"); err != nil {
		log.Println(err)
	}
}
예제 #3
0
func HandleTrouble(w http.ResponseWriter, r *http.Request) {
	ctx := &parser.Context{
		Title:       "Uh-oh",
		Description: "Something went wrong",
	}
	if err := parser.Render(w, ctx, "trouble.html"); err != nil {
		log.Println(err)
	}
}
예제 #4
0
func HandleSetupThanks(w http.ResponseWriter, r *http.Request) {
	// Grab Profile from cookie set in HandleLoginOAuth
	p := profile.Profile{}
	if cookie, err := r.Cookie("Profile"); err == nil {
		if err = sCookie.Decode(cookie.Name, cookie.Value, &p); err != nil {
			log.Print(err)
		}
	}

	ctx := &parser.Context{
		Title:       "Thank You for Setting Up Your Account",
		Description: "",
		Profile:     p,
	}

	if err := parser.Render(w, ctx, "setup-thanks.html"); err != nil {
		log.Println(err)
	}
}
예제 #5
0
func HandleSetup(w http.ResponseWriter, r *http.Request) {
	// Grab Profile from cookie set in HandleLoginOAuth
	p := profile.Profile{}
	if cookie, err := r.Cookie("Profile"); err == nil {
		if err = sCookie.Decode(cookie.Name, cookie.Value, &p); err != nil {
			log.Print(err)
		}
	}
	// Make sure we got the profile out of the cookie
	if p.GoogleId == "" {
		http.Redirect(w, r, "/cannotGetCookie", http.StatusTemporaryRedirect)
		return
	}

	p.Communities = communities.All()

	e := newExtra()

	if r.Method == "POST" {
		if err := r.ParseForm(); err != nil {
			log.Println(err)
		}
		// Fill the profile communities with all, filter out falses later
		if err := setupDecoder.Decode(&p, r.PostForm); err != nil {
			log.Println(err)
		}
		if err := validateUsername(&p); err != "" {
			e.Errors["DisplayUsername"] = err
		}
		if err := validateCommunities(&p); err != "" {
			e.Errors["Communities"] = err
		}
		// Insert new profile
		if len(e.Errors) == 0 {
			if err := db.SaveProfile(&p); err != nil {
				e.Errors["Overall"] = err.Error()
			}
		}

		if len(e.Errors) == 0 {
			encoded, err := sCookie.Encode("Profile", p)
			if err != nil {
				log.Print(err)
				http.Redirect(w, r, "/cannotSetCookie", http.StatusTemporaryRedirect)
				return
			}
			http.SetCookie(w, &http.Cookie{
				Name:  "Profile",
				Value: encoded,
				Path:  "/",
			})
			http.Redirect(w, r, "/setupThanks", http.StatusTemporaryRedirect)
			return
		}
	}

	ctx := &parser.Context{
		Title:       "Setup Your Account",
		Description: "Establish your account details",
		Profile:     p,
		Extra:       e,
	}

	if err := parser.Render(w, ctx, "setup.html"); err != nil {
		log.Println(err)
	}
}
func HandleInventoryAdd(w http.ResponseWriter, r *http.Request, ctx *parser.Context) {
	ctx.Title = "Ingress Inventory"
	if err := parser.Render(w, ctx, "update-inventory.html"); err != nil {
		log.Println(err)
	}
}