Moritz Schmidt 9 anos atrás
pai
commit
fb37efc18e
1 arquivos alterados com 11 adições e 2 exclusões
  1. 11 2
      usermanager.go

+ 11 - 2
usermanager.go

@@ -90,9 +90,14 @@ func LogoutHandler(ctx *iris.Context) {
   user, err := GetUserFromDB(userID)
   errorhelpers.HandleError(err, ctx)
 
-  user.Logout(userID);
+  user.Logout(userID)
   ctx.SetCookieKV("token", "")
 
+  params := ctx.Get("params").(map[string]string) // TODO cleaner way? outsource to user.logout?
+  params["username"] = ""
+  params["admin"] = ""
+  ctx.Set("params", params)
+
   err = errors.New(errorhelpers.SUCCESS_LOGOUT)
   errorhelpers.HandleError(err, ctx)
 }
@@ -105,7 +110,7 @@ func (user *User) Update() error {
   err := databaseutils.DBUtil.UpdateRow("users", "id", string(user.ID), colsVals)
 
   if err != nil {
-    fmt.Println("ERROOR UPDATING: " + err.Error())
+    fmt.Println("ERROOR UPDATING: " + err.Error()) // TODO error habndling
   }
 
   return nil
@@ -161,6 +166,10 @@ func VerifyUserLoggedIn(tokenString string) (bool, string, error) { // TODO rene
 
 func AuthHandler(ctx *iris.Context) {
   tokenString := ctx.GetCookie("token")
+  if tokenString == "" { // when coming from login form cookie doesn't work yet
+    tokenString = ctx.GetString("token")
+  }
+
   isAuthed, userID, err := VerifyUserLoggedIn(tokenString)
 
   if isAuthed {