Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions handlers.user.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ func performLogin(c *gin.Context) {
username := c.PostForm("username")
password := c.PostForm("password")

var sameSiteCookie http.SameSite;

// Check if the username/password combination is valid
if isUserValid(username, password) {
// If the username/password is valid set the token in a cookie
token := generateSessionToken()
c.SetCookie("token", token, 3600, "", "", sameSiteCookie, false, true)
c.SetCookie("token", token, 3600, "", "", false, true)
c.Set("is_logged_in", true)

render(c, gin.H{
Expand All @@ -52,10 +50,8 @@ func generateSessionToken() string {

func logout(c *gin.Context) {

var sameSiteCookie http.SameSite;

// Clear the cookie
c.SetCookie("token", "", -1, "", "", sameSiteCookie, false, true)
c.SetCookie("token", "", -1, "", "", false, true)

// Redirect to the home page
c.Redirect(http.StatusTemporaryRedirect, "/")
Expand All @@ -72,12 +68,10 @@ func register(c *gin.Context) {
username := c.PostForm("username")
password := c.PostForm("password")

var sameSiteCookie http.SameSite;

if _, err := registerNewUser(username, password); err == nil {
// If the user is created, set the token in a cookie and log the user in
token := generateSessionToken()
c.SetCookie("token", token, 3600, "", "", sameSiteCookie, false, true)
c.SetCookie("token", token, 3600, "", "", false, true)
c.Set("is_logged_in", true)

render(c, gin.H{
Expand Down