aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets_src/css/materialize_extend.css3
-rw-r--r--assets_src/js/user.js22
-rw-r--r--frontend/renderer.go4
-rw-r--r--grilist/config.go6
-rw-r--r--main.go5
-rw-r--r--views/includes/materialize.html3
-rw-r--r--views/pages/api_couple.html28
-rw-r--r--views/pages/user.html30
8 files changed, 95 insertions, 6 deletions
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 @@
1span.badge.new.no-caption::after {
2 content: "";
3}
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 @@
1import * as dom from './lib/dom';
2
3function externalServiceClick(e) {
4 var row = dom.closest(e.target, (el) => el.classList.contains('authorizable'));
5 if (row === null) {
6 alert('nada');
7 return;
8 }
9 var authType = row.getAttribute('data-auth-type'),
10 authUrl = row.getAttribute('data-auth-url'),
11 coupleUrl = row.getAttribute('data-couple-url');
12 switch (authType) {
13 case 'copy-paste':
14 window.open(authUrl);
15 location.href = coupleUrl;
16 break;
17 }
18}
19
20dom.ready(() => {
21 document.getElementById('external-service-list').addEventListener('click', externalServiceClick, true);
22});
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
118func (r *Renderer) RenderUserSettingsPage(w http.ResponseWriter, data map[string]interface{}) { 118func (r *Renderer) RenderUserSettingsPage(w http.ResponseWriter, data map[string]interface{}) {
119 r.RenderPage("user_settings", w, data) 119 r.RenderPage("user_settings", w, data)
120} 120}
121
122func (r *Renderer) RenderAPICouplePage(w http.ResponseWriter, data map[string]interface{}) {
123 r.RenderPage("api_couple", w, data)
124}
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 {
17 Password string `toml:"password"` 17 Password string `toml:"password"`
18 SSLEnabled bool `toml:ssl_enabled"` 18 SSLEnabled bool `toml:ssl_enabled"`
19 } `toml:"database"` 19 } `toml:"database"`
20 EnableNSA bool `toml:"enable_nsa"` 20 EnableNSA bool `toml:"enable_nsa"`
21 AnilistAPI struct {
22 ClientID string `toml:"client_id"`
23 ClientSecret string `toml:"client_secret"`
24 } `toml:"anilist_api"`
21} 25}
22 26
23func (c *Config) DBConnectionString() string { 27func (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() {
66 renderer := frontend.New("views") 66 renderer := frontend.New("views")
67 login := charakterin.New(db) 67 login := charakterin.New(db)
68 login.UseRenderer(renderer) 68 login.UseRenderer(renderer)
69 if config.AnilistAPI.ClientID != "" && config.AnilistAPI.ClientSecret != "" {
70 login.EnableAnilistAPI(config.AnilistAPI.ClientID, config.AnilistAPI.ClientSecret)
71 }
69 72
70 router := httprouter.New() 73 router := httprouter.New()
71 74
@@ -87,6 +90,8 @@ func main() {
87 router.HandlerFunc("GET", "/logout", login.Logout) 90 router.HandlerFunc("GET", "/logout", login.Logout)
88 router.HandlerFunc("GET", "/register", login.DisplayRegistration) 91 router.HandlerFunc("GET", "/register", login.DisplayRegistration)
89 router.HandlerFunc("POST", "/register", login.Register) 92 router.HandlerFunc("POST", "/register", login.Register)
93 router.GET("/settings/api/:type/couple", login.DisplayAPICouplePage)
94 router.POST("/settings/api/:type/couple", login.CoupleAPI)
90 95
91 fs := http.FileServer(http.Dir("assets")) 96 fs := http.FileServer(http.Dir("assets"))
92 http.Handle("/assets/", http.StripPrefix("/assets/", fs)) 97 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 @@
1{{define "materialize"}} 1{{define "materialize"}}
2 <link rel="stylesheet" href="/assets/css/materialize.css"> 2 <link rel="stylesheet" href="/assets/css/materialize.css">
3 <link rel="stylesheet" href="/assets/css/material_icons.css"> 3 <link rel="stylesheet" href="/assets/css/material_icons.css">
4 <link rel="stylesheet" href="/assets/css/materialize_extend.css">
4 <meta name="viewport" content="width=device_width, initial-scale=1.0" /> 5 <meta name="viewport" content="width=device_width, initial-scale=1.0" />
5{{end}} \ No newline at end of file 6{{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 @@
1{{ define "api_couple" }}
2<html>
3 <head>
4 {{ template "materialize" }}
5 <title>{{ .name }} - grilist</title>
6 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
7 </head>
8 <body>
9 {{ template "navbar" . }}
10 <div class="container">
11 {{ if .error }}
12 <div class="card-panel red darken-4">
13 <span class="white-text">{{ .error }}</span>
14 </div>
15 {{ end }}
16 <form method="POST" action="couple">
17 <blockquote>
18 {{ .name }} wurde in einem neuen Tab/Fenster geöffnet. Bitte bestätige dort Grilist und kopiere den Code in das unten stehende Feld.
19 </blockquote>
20 <input name="code" placeholder="Code" type="text" class="validate">
21 <button class="btn waves-effect waves-light purple lighten-2" type="submit">
22 {{ .name }} verbinden <i class="material-icons right">send</i>
23 </button>
24 </form>
25 </div>
26 </body>
27</html>
28{{ 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 @@
1{{ define "user" }} 1{{ define "user" }}
2{{ $isCurrentUser := (and .user (eq .DisplayUser.ID .user.ID)) }}
2<html> 3<html>
3 <head> 4 <head>
4 {{ template "materialize" }} 5 {{ template "materialize" }}
@@ -10,13 +11,33 @@
10 <div class="container"> 11 <div class="container">
11 <div class="row" style="margin-top: 50px; line-height: 500%; "> 12 <div class="row" style="margin-top: 50px; line-height: 500%; ">
12 <span style="font-size: 4.2rem; margin: 2.1rem 1rem 1.68rem 0;">{{ .DisplayUser.GetName }}</span> 13 <span style="font-size: 4.2rem; margin: 2.1rem 1rem 1.68rem 0;">{{ .DisplayUser.GetName }}</span>
13 {{ if .user }} 14 {{ if $isCurrentUser }}
14 {{ if eq .DisplayUser.ID .user.ID }} 15 &nbsp;&nbsp;<a class="btn waves-effect waves-light indigo lighten-5 black-text" style="margin-top: -1.68rem" href="/settings">Einstellungen</a>
15 &nbsp;&nbsp;<a class="btn waves-effect waves-light indigo lighten-5 black-text" style="margin-top: -1.68rem" href="/settings">Einstellungen</a>
16 {{ end }}
17 {{ end }} 16 {{ end }}
18 </div> 17 </div>
19 <blockquote>zuletzt gesehen: {{ .DisplayUser.LastActivity.Format "Mon Jan _2 15:04:05 2006" }}</blockquote><br /> 18 <blockquote>zuletzt gesehen: {{ .DisplayUser.LastActivity.Format "Mon Jan _2 15:04:05 2006" }}</blockquote><br />
19 {{ if (and (or $isCurrentUser .DisplayUser.HasExternalServices) .DisplayUser.ExternalServices) }}
20 <div class="row">
21 <h3>Externe Dienste</h3>
22 <div class="collection" id="external-service-list">
23 {{ $model := . }}
24 {{ range .DisplayUser.ExternalServices }}
25 {{ if (or .IsEnabled $isCurrentUser) }}
26 <a href="#" {{ if not .IsEnabled }} data-auth-type="{{ .AuthType }}" data-auth-url="{{ .AuthorizeURL }}" data-couple-url="{{ .CoupleURL }}" {{ end }} class="collection-item {{ if not .IsEnabled }} authorizable {{ end }}">
27 <span class="badge {{ if not .IsEnabled }} new no-caption {{ end }}">
28 {{ if not .IsEnabled }}
29 Hinzufügen!
30 {{ else }}
31 {{ .UserName }}
32 {{ end }}
33 </span>
34 {{ .Name }}
35 </a>
36 {{ end }}
37 {{ end }}
38 </div>
39 </div>
40 {{ end }}
20 <div class="row"> 41 <div class="row">
21 <h3>Listen von {{ .DisplayUser.GetName }}</h3> 42 <h3>Listen von {{ .DisplayUser.GetName }}</h3>
22 {{ range .Lists }} 43 {{ range .Lists }}
@@ -24,6 +45,7 @@
24 {{ end }} 45 {{ end }}
25 </div> 46 </div>
26 </div> 47 </div>
48 <script src="/assets/js/user.js"></script>
27 </body> 49 </body>
28</html> 50</html>
29{{ end }} 51{{ end }}