summaryrefslogtreecommitdiff
path: root/app/handler.go
diff options
context:
space:
mode:
authorHorus32015-02-25 16:41:52 +0100
committerHorus32015-02-25 16:41:52 +0100
commit49ffcba2c3c4a19d147dd792d7f6c99b7545a491 (patch)
tree4fbd8a283ef7ab13f92e11e5030ad5c362be4524 /app/handler.go
parent9e1d8d0fb2b57903b1c6c0c2765b7808655c74a0 (diff)
downloadstatuspage-49ffcba2c3c4a19d147dd792d7f6c99b7545a491.tar.gz
UX on front end.
Diffstat (limited to 'app/handler.go')
-rw-r--r--app/handler.go94
1 files changed, 92 insertions, 2 deletions
diff --git a/app/handler.go b/app/handler.go
index 3f30c9f..cdf8421 100644
--- a/app/handler.go
+++ b/app/handler.go
@@ -106,12 +106,13 @@ func AddNewJobHandler(w http.ResponseWriter, r *http.Request) {
log.Println("Scheme neither http nor https.", u.Scheme)
session.AddFlash("Unsurportted scheme. Only http:// and https:// is valid.", "error")
session.Save(r, w)
- http.Redirect(w, r, "/new", 302)
+ http.Redirect(w, r, "/admin", 302)
// http.Error(w, "Scheme neither http nor https.", http.StatusInternalServerError)
return
}
host.Monitored = true
+ host.Host = u.Host
log.Printf("%v", host)
Db.Debug().Save(&host)
@@ -123,12 +124,13 @@ func AddNewJobHandler(w http.ResponseWriter, r *http.Request) {
for k, _ := range h {
Db.Debug().Save(&h[k])
}
+ CacheHosts(cache_prefix+"database", h)
}()
session.AddFlash("Job added!", "success")
session.Save(r, w)
- http.Redirect(w, r, "/new", 302)
+ http.Redirect(w, r, "/admin", 302)
}
@@ -139,3 +141,91 @@ func ShowJobHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Job: %v, Schedule: %v; Next %v; Prev %v \n", i.Job, i.Schedule, i.Next, i.Prev)
}
}
+
+func LoginHandler(w http.ResponseWriter, r *http.Request) {
+ session, err := store.Get(r, "_SID")
+ if err != nil {
+ log.Println(err)
+ }
+ u := User{}
+ err = r.ParseForm()
+ if err != nil {
+ log.Println(err)
+ }
+ err = decoder.Decode(&u, r.PostForm)
+ if err != nil {
+ log.Println(err)
+ }
+ log.Println(u)
+ login := login(u.Name, u.Password, session)
+ if !login {
+ session.AddFlash("Login failed.", "error")
+ session.Save(r, w)
+ log.Println("Login failed.")
+ log.Println(u.Name, u.Password)
+ http.Redirect(w, r, "/login", 302)
+ return
+ }
+ session.Values["login"] = true
+ session.Save(r, w)
+ http.Redirect(w, r, "/admin", 301)
+}
+
+func PrintLoginHandler(w http.ResponseWriter, r *http.Request) {
+ session, err := store.Get(r, "_SID")
+ if err != nil {
+ log.Println(err)
+ }
+ if session.Values["login"] == true {
+ log.Println("Schon erfolgreich eingeloggt!")
+ // http.Redirect(w, r, "/", 301)
+ } else {
+ log.Println("Nicht eingeloggt.")
+ }
+ m := FlashMessages{}
+ m.Success = session.Flashes("success")
+ m.Error = session.Flashes("error")
+ session.Save(r, w)
+ templ := mainTempl.Lookup("login.html")
+
+ err = templ.ExecuteTemplate(w, "login.html", m)
+ if err != nil {
+ log.Panic(err)
+ }
+}
+
+func LogoutHandler(w http.ResponseWriter, r *http.Request) {
+ session, _ := store.Get(r, "_SID")
+ session.Values["login"] = false
+ session.Save(r, w)
+ http.Redirect(w, r, "/", 301)
+}
+
+func AdminHandler(w http.ResponseWriter, r *http.Request) {
+ session, err := store.Get(r, "_SID")
+ if err != nil {
+ log.Println(err)
+ }
+ if session.Values["login"] != true {
+ // http.Redirect(w, r, "/login", 401)
+ PrintLoginHandler(w, r)
+ return
+ }
+ hosts := []Host{}
+ Db.Find(&hosts)
+
+ a := Admin{}
+ a.Success = session.Flashes("success")
+ a.Error = session.Flashes("error")
+ a.Hosts = hosts
+ session.Save(r, w)
+
+ index := mainTempl.Lookup("admin.html")
+
+ err = index.ExecuteTemplate(w, "admin.html", a)
+ if err != nil {
+ log.Println(err)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+}