Commits

Dobrosław Żybort committed 99caedb

Add some more info flashes

  • Participants
  • Parent commits ed644ba

Comments (0)

Files changed (3)

handlers_paste.go

 
 	paste.Data = pasteData.Data
 	if paste.Data == "" {
-		http.Redirect(wri, req, reverse("index"), http.StatusNoContent)
+		ctx.Session.AddFlash("Paste code cannot be empty", "flash_alert")
+		http.Redirect(wri, req, reverse("index"), http.StatusSeeOther)
 		return
 	}
 
 	}
 
 	ctx.Session.Values["user"] = user.ID
+	ctx.Session.AddFlash("Welcome back "+user.Name, "flash_success")
 	http.Redirect(wri, req, reverse("index"), http.StatusSeeOther)
 	return nil
 }
 
 func logout(wri http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
 	delete(ctx.Session.Values, "user")
+	ctx.Session.AddFlash("You have been logged out", "flash_success")
 	http.Redirect(wri, req, reverse("index"), http.StatusSeeOther)
 	return nil
 }
 	}
 
 	ctx.Session.Values["user"] = user.ID
+	ctx.Session.AddFlash("You are now registered and logged in", "flash_success")
 	http.Redirect(wri, req, reverse("index"), http.StatusSeeOther)
 	return nil
 }

templates/index.html

 <!-- Main Content -->
 
 <div class="nine columns" role="content">
+
+  <div class="eight columns offset-by-two">
+    {{ range .ctx.Session.Flashes "flash_success" }}
+      <div class="alert-box success">
+        {{ . }}
+        <a href="" class="close">&times;</a>
+      </div>
+    {{ end }}
+    {{ range .ctx.Session.Flashes "flash_alert" }}
+      <div class="alert-box alert">
+        {{ . }}
+        <a href="" class="close">&times;</a>
+      </div>
+    {{ end }}
+  </div>
+	
 	<form action="{{ reverse "addPaste" }}" method="POST">
 
     <div class="row">