From c6df1d768240d14e8129b51d6916931f1c4f35db Mon Sep 17 00:00:00 2001 From: rtz12 Date: Sun, 13 Nov 2016 03:47:19 +0100 Subject: Anilist-API in Grilist implementiert diff --git a/assets_src/css/materialize_extend.css b/assets_src/css/materialize_extend.css new file mode 100644 index 0000000..f06d042 --- /dev/null +++ b/assets_src/css/materialize_extend.css @@ -0,0 +1,3 @@ +span.badge.new.no-caption::after { + content: ""; +} diff --git a/assets_src/js/user.js b/assets_src/js/user.js new file mode 100644 index 0000000..c697780 --- /dev/null +++ b/assets_src/js/user.js @@ -0,0 +1,22 @@ +import * as dom from './lib/dom'; + +function externalServiceClick(e) { + var row = dom.closest(e.target, (el) => el.classList.contains('authorizable')); + if (row === null) { + alert('nada'); + return; + } + var authType = row.getAttribute('data-auth-type'), + authUrl = row.getAttribute('data-auth-url'), + coupleUrl = row.getAttribute('data-couple-url'); + switch (authType) { + case 'copy-paste': + window.open(authUrl); + location.href = coupleUrl; + break; + } +} + +dom.ready(() => { + document.getElementById('external-service-list').addEventListener('click', externalServiceClick, true); +}); diff --git a/frontend/renderer.go b/frontend/renderer.go index d39dfe1..3fb79bf 100644 --- a/frontend/renderer.go +++ b/frontend/renderer.go @@ -118,3 +118,7 @@ func (r *Renderer) RenderRegistrationPage(w http.ResponseWriter, data map[string func (r *Renderer) RenderUserSettingsPage(w http.ResponseWriter, data map[string]interface{}) { r.RenderPage("user_settings", w, data) } + +func (r *Renderer) RenderAPICouplePage(w http.ResponseWriter, data map[string]interface{}) { + r.RenderPage("api_couple", w, data) +} diff --git a/grilist/config.go b/grilist/config.go index c69c873..3d41bcc 100644 --- a/grilist/config.go +++ b/grilist/config.go @@ -17,7 +17,11 @@ type Config struct { Password string `toml:"password"` SSLEnabled bool `toml:ssl_enabled"` } `toml:"database"` - EnableNSA bool `toml:"enable_nsa"` + EnableNSA bool `toml:"enable_nsa"` + AnilistAPI struct { + ClientID string `toml:"client_id"` + ClientSecret string `toml:"client_secret"` + } `toml:"anilist_api"` } func (c *Config) DBConnectionString() string { diff --git a/main.go b/main.go index ad3dd84..240ca1a 100644 --- a/main.go +++ b/main.go @@ -66,6 +66,9 @@ func main() { renderer := frontend.New("views") login := charakterin.New(db) login.UseRenderer(renderer) + if config.AnilistAPI.ClientID != "" && config.AnilistAPI.ClientSecret != "" { + login.EnableAnilistAPI(config.AnilistAPI.ClientID, config.AnilistAPI.ClientSecret) + } router := httprouter.New() @@ -87,6 +90,8 @@ func main() { router.HandlerFunc("GET", "/logout", login.Logout) router.HandlerFunc("GET", "/register", login.DisplayRegistration) router.HandlerFunc("POST", "/register", login.Register) + router.GET("/settings/api/:type/couple", login.DisplayAPICouplePage) + router.POST("/settings/api/:type/couple", login.CoupleAPI) fs := http.FileServer(http.Dir("assets")) http.Handle("/assets/", http.StripPrefix("/assets/", fs)) diff --git a/views/includes/materialize.html b/views/includes/materialize.html index ab95286..100b4be 100644 --- a/views/includes/materialize.html +++ b/views/includes/materialize.html @@ -1,5 +1,6 @@ {{define "materialize"}} + -{{end}} \ No newline at end of file +{{end}} diff --git a/views/pages/api_couple.html b/views/pages/api_couple.html new file mode 100644 index 0000000..b21d349 --- /dev/null +++ b/views/pages/api_couple.html @@ -0,0 +1,28 @@ +{{ define "api_couple" }} + + + {{ template "materialize" }} + {{ .name }} - grilist + + + + {{ template "navbar" . }} +
+ {{ if .error }} +
+ {{ .error }} +
+ {{ end }} +
+
+ {{ .name }} wurde in einem neuen Tab/Fenster geöffnet. Bitte bestätige dort Grilist und kopiere den Code in das unten stehende Feld. +
+ + +
+
+ + +{{ end }} diff --git a/views/pages/user.html b/views/pages/user.html index 2cf9c54..e654d96 100644 --- a/views/pages/user.html +++ b/views/pages/user.html @@ -1,4 +1,5 @@ {{ define "user" }} +{{ $isCurrentUser := (and .user (eq .DisplayUser.ID .user.ID)) }} {{ template "materialize" }} @@ -10,13 +11,33 @@
{{ .DisplayUser.GetName }} - {{ if .user }} - {{ if eq .DisplayUser.ID .user.ID }} -   Einstellungen - {{ end }} + {{ if $isCurrentUser }} +   Einstellungen {{ end }}
zuletzt gesehen: {{ .DisplayUser.LastActivity.Format "Mon Jan _2 15:04:05 2006" }}

+ {{ if (and (or $isCurrentUser .DisplayUser.HasExternalServices) .DisplayUser.ExternalServices) }} +
+

Externe Dienste

+
+ {{ $model := . }} + {{ range .DisplayUser.ExternalServices }} + {{ if (or .IsEnabled $isCurrentUser) }} + + + {{ if not .IsEnabled }} + Hinzufügen! + {{ else }} + {{ .UserName }} + {{ end }} + + {{ .Name }} + + {{ end }} + {{ end }} +
+
+ {{ end }}

Listen von {{ .DisplayUser.GetName }}

{{ range .Lists }} @@ -24,6 +45,7 @@ {{ end }}
+ {{ end }} -- cgit v0.10.1