Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- userRoutes.POST("/login", ensureNotLoggedIn(), performLogin)
- func performLogin(c *gin.Context) {
- username := c.PostForm("username")
- password := c.PostForm("password")
- if isUserValid(username, password) {
- token := generateSessionToken()
- c.SetCookie("token", token, 3600, "", "", false, true)
- //is_logged_in is not working in template
- c.Set("is_logged_in", true)
- render(c, gin.H{"title": "Successful Login"}, "login-successful.html")
- } else {
- c.HTML(http.StatusBadRequest, "login.html", gin.H{
- "ErrorTitle": "Login Failed",
- "ErrorMessage": "Invalid credentials provided",
- })
- }
- }
- {{ if .is_logged_in }}
- <li><a href="/article/create">Create Article</a></li>
- {{ end }}
- {{ if not .is_logged_in }}
- <li><a href="/u/register">Register</a></li>
- {{end}}
- 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