Example #1
0
// NotepadUpdateGET displays the note update page
func NotepadUpdateGET(w http.ResponseWriter, r *http.Request) {
	// Get session
	sess := session.Instance(r)

	// Get the note id
	var params httprouter.Params
	params = context.Get(r, "params").(httprouter.Params)
	noteID := params.ByName("id")

	userID := fmt.Sprintf("%s", sess.Values["id"])

	// Get the note
	note, err := model.NoteByID(userID, noteID)
	if err != nil { // If the note doesn't exist
		log.Println(err)
		sess.AddFlash(view.Flash{"An error occurred on the server. Please try again later.", view.FlashError})
		sess.Save(r, w)
		http.Redirect(w, r, "/notepad", http.StatusFound)
		return
	}

	// Display the view
	v := view.New(r)
	v.Name = "notepad/update"
	v.Vars["token"] = csrfbanana.Token(w, r, sess)
	v.Vars["note"] = note.Content
	v.Render(w)
}
Example #2
0
// ClockinsByStudentIdJsonGET displays the note update page
func ClockinsByStudentIdGET(w http.ResponseWriter, r *http.Request) {
	// Get session
	sess := session.Instance(r)

	// Get the Student id
	var params httprouter.Params
	params = context.Get(r, "params").(httprouter.Params)
	studentID := params.ByName("student_id")

	// Get the clockins of a particular Student
	_, err := model.StudentBySID(html.EscapeString(studentID))

	if err != nil { // If the note doesn't exist
		log.Println(err)
		sess.AddFlash(view.Flash{"An error occurred on the server. Please try again later.", view.FlashError})
		sess.Save(r, w)
		http.Redirect(w, r, "/list", http.StatusFound)
		return
	}

	// Display the view
	v := view.New(r)
	v.Name = "clockins/student"
	v.Vars["token"] = csrfbanana.Token(w, r, sess)
	//v.Vars["student_id"] = studentID
	v.Render(w)
}
Example #3
0
// NotepadCreateGET displays the note creation page
func NotepadCreateGET(w http.ResponseWriter, r *http.Request) {
	// Get session
	sess := session.Instance(r)

	// Display the view
	v := view.New(r)
	v.Name = "notepad/create"
	v.Vars["token"] = csrfbanana.Token(w, r, sess)
	v.Render(w)
}
Example #4
0
func LoginGET(w http.ResponseWriter, r *http.Request) {
	// Get session
	sess := session.Instance(r)

	// Display the view
	v := view.New(r)
	v.Name = "login"
	v.Vars["token"] = csrfbanana.Token(w, r, sess)
	// Refill any form fields
	view.Repopulate([]string{"email"}, r.Form, v.Vars)
	v.Render(w)
}
Example #5
0
func RegisterGET(w http.ResponseWriter, r *http.Request) {
	// Get session
	sess := session.Instance(r)

	// Only allow authenticated user
	if sess.Values["id"] != nil {
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}

	// Display the view
	v := view.New(r)
	v.Name = "register"
	v.Vars["token"] = csrfbanana.Token(w, r, sess)
	// Refill any form fields
	view.Repopulate([]string{"first_name", "last_name", "email"}, r.Form, v.Vars)
	v.Render(w)
}
Example #6
0
// Login handles GET and POST
func routeLogin(w http.ResponseWriter, r *http.Request) {

	// Get session
	sess := Session(r, SessionName)

	// Create a map for the template
	vars := make(map[string]string)

	// Store the CSRF token
	vars["token"] = csrfbanana.Token(w, r, sess)

	// If a POST operation
	if r.Method == "POST" {
		// Store the name to a template variable
		vars["name"] = r.FormValue("name")
	}

	// Show the template
	templ.Execute(w, vars)
}