|
@@ -90,9 +90,14 @@ func LogoutHandler(ctx *iris.Context) {
|
|
|
user, err := GetUserFromDB(userID)
|
|
user, err := GetUserFromDB(userID)
|
|
|
errorhelpers.HandleError(err, ctx)
|
|
errorhelpers.HandleError(err, ctx)
|
|
|
|
|
|
|
|
- user.Logout(userID);
|
|
|
|
|
|
|
+ user.Logout(userID)
|
|
|
ctx.SetCookieKV("token", "")
|
|
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)
|
|
err = errors.New(errorhelpers.SUCCESS_LOGOUT)
|
|
|
errorhelpers.HandleError(err, ctx)
|
|
errorhelpers.HandleError(err, ctx)
|
|
|
}
|
|
}
|
|
@@ -105,7 +110,7 @@ func (user *User) Update() error {
|
|
|
err := databaseutils.DBUtil.UpdateRow("users", "id", string(user.ID), colsVals)
|
|
err := databaseutils.DBUtil.UpdateRow("users", "id", string(user.ID), colsVals)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- fmt.Println("ERROOR UPDATING: " + err.Error())
|
|
|
|
|
|
|
+ fmt.Println("ERROOR UPDATING: " + err.Error()) // TODO error habndling
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
return nil
|
|
@@ -161,6 +166,10 @@ func VerifyUserLoggedIn(tokenString string) (bool, string, error) { // TODO rene
|
|
|
|
|
|
|
|
func AuthHandler(ctx *iris.Context) {
|
|
func AuthHandler(ctx *iris.Context) {
|
|
|
tokenString := ctx.GetCookie("token")
|
|
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)
|
|
isAuthed, userID, err := VerifyUserLoggedIn(tokenString)
|
|
|
|
|
|
|
|
if isAuthed {
|
|
if isAuthed {
|