Moritz Schmidt 9 年之前
父節點
當前提交
f1120f7bfa
共有 1 個文件被更改,包括 8 次插入16 次删除
  1. 8 16
      main.go

+ 8 - 16
main.go

@@ -7,7 +7,7 @@ import (
   "git.mmnx.de/Moe/usermanager"
   "git.mmnx.de/Moe/databaseutils"
   "git.mmnx.de/Moe/configutils"
-  "git.mmnx.de/Moe/templatehelpers"
+  "git.mmnx.de/Moe/errorhelpers"
 
   // "errors"
 )
@@ -63,7 +63,7 @@ func main() {
 
   iris.Get("/login", templateHandler) // TODO not when logged in
   iris.Get("/logout", usermanager.AuthHandler, usermanager.LogoutHandler)
-  iris.Get("/register", templateHandler) // TODO not when logged in
+  iris.Get("/register", templateHandler)
 	iris.Get("/", usermanager.AuthHandler, templateHandler)
   iris.Get("/account", usermanager.AuthHandler, templateHandler)
   iris.Get("/help", usermanager.AuthHandler, templateHandler)
@@ -80,13 +80,9 @@ func loginHandler(ctx *iris.Context) {
 
   user := usermanager.User{} // new user
   tokenString, err := user.Login(username, password) // try to login
+  ctx.SetCookieKV("token", tokenString)
 
-  if err != nil {
-    templatehelpers.ShowError(err.Error(), ctx, "login")
-  } else {
-    ctx.SetCookieKV("token", tokenString)
-    templatehelpers.ShowNotification("Login successfull", ctx, "home")
-  }
+  errorhelpers.HandleError(err, ctx, []string{usermanager.SUCCESS_LOGIN, "home"})
 }
 
 func accountUpdateHandler(ctx *iris.Context) {
@@ -94,17 +90,13 @@ func accountUpdateHandler(ctx *iris.Context) {
   password := ctx.FormValueString("password")
   userID := ctx.GetString("userID")
 
-  if err := usermanager.UserUpdateProcessor(username, password, userID); err != nil {
-    templatehelpers.ShowError(err.Error(), ctx, "account")
-    return
-  }
-
-  templatehelpers.ShowNotification("updated successfull", ctx, "account")
+  err := usermanager.UserUpdateProcessor(username, password, userID)
+  errorhelpers.HandleError(err, ctx, []string{usermanager.SUCCESS_UPDATE, "home"})
 }
 
 func adminPostHandler(ctx *iris.Context) {
-  _ = usermanager.GenerateTokens(5) // generate tokens and store in db, we don't need them now
-  templatehelpers.ShowNotification("tokens generated", ctx, "admin")
+  _, err := usermanager.GenerateTokens(5) // generate tokens and store in db, we don't need them now, TODO error handling?
+  errorhelpers.HandleError(err, ctx, []string{usermanager.SUCCESS_TOKENS_GENERATED, "home"})
 }
 
 func templateHandler(ctx *iris.Context) {