From 96b08bfa8906e3d9b0c8f98186c6b21906685be5 Mon Sep 17 00:00:00 2001 From: jan Date: Sun, 13 Nov 2016 13:04:54 +0100 Subject: wir wollen nur eingebaute services erlauben diff --git a/charakterin.go b/charakterin.go index 2878f1f..413d698 100644 --- a/charakterin.go +++ b/charakterin.go @@ -24,6 +24,11 @@ const ( EmailAlreadyRegistered = "pq: email_already_registered" ) +// external services +const ( + ANILIST = "Anilist" +) + // Renderer wird verwendet, um die Routen (bspw. Login-Route) zu rendern. Damit bleibt Charakterin selbst ohne Template. type Renderer interface { RenderLoginPage(w http.ResponseWriter, data map[string]interface{}) @@ -401,9 +406,15 @@ func (c *Charakterin) DisplayAPICouplePage(w http.ResponseWriter, r *http.Reques http.Error(w, "403", http.StatusForbidden) return } + + service := ps.ByName("type") + if service != ANILIST { + http.Error(w, "Ungueltiger Service", http.StatusNotFound) + return + } data := make(map[string]interface{}) data["user"] = user - data["name"] = ps.ByName("type") + data["name"] = service c.renderer.RenderAPICouplePage(w, data) } @@ -419,8 +430,11 @@ func (c *Charakterin) CoupleAPI(w http.ResponseWriter, r *http.Request, ps httpr return } switch ps.ByName("type") { - case "Anilist": + case ANILIST: err = user.AnilistClient.CoupleByPin(body["code"][0]) + break + default: + err = errors.New("Ungueltiger Service") } if err != nil { data := make(map[string]interface{}) -- cgit v0.10.1