Guest User

Untitled

a guest
Aug 24th, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. userRoutes.POST("/login", ensureNotLoggedIn(), performLogin)
  2.  
  3. func performLogin(c *gin.Context) {
  4. username := c.PostForm("username")
  5. password := c.PostForm("password")
  6. if isUserValid(username, password) {
  7. token := generateSessionToken()
  8. c.SetCookie("token", token, 3600, "", "", false, true)
  9. //is_logged_in is not working in template
  10. c.Set("is_logged_in", true)
  11. render(c, gin.H{"title": "Successful Login"}, "login-successful.html")
  12. } else {
  13. c.HTML(http.StatusBadRequest, "login.html", gin.H{
  14. "ErrorTitle": "Login Failed",
  15. "ErrorMessage": "Invalid credentials provided",
  16. })
  17. }
  18. }
  19.  
  20. {{ if .is_logged_in }}
  21. <li><a href="/article/create">Create Article</a></li>
  22. {{ end }}
  23. {{ if not .is_logged_in }}
  24. <li><a href="/u/register">Register</a></li>
  25. {{end}}
  26.  
  27. render(c, gin.H{"title": "Successful Login", "is_logged_in": c.MustGet("is_logged_in").(bool)}, "login-successful.html")
Add Comment
Please, Sign In to add comment