aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2015-12-27 20:29:50 (UTC)
committerjan <jan@ruken.pw>2015-12-27 20:29:50 (UTC)
commit0746d945a61ca3dc7588a1f7a2c320ca8a06e198 (patch)
tree0e05e25e640d2e13fee39a713f2373649b5732f4
parentccf10c8d425b28c75cb9ce66c50c943f8825b783 (diff)
dashboard auch für nicht eingeloggte benutzer
-rw-r--r--dashboard.go6
-rw-r--r--main.go6
-rw-r--r--modules/lists/lists.go20
-rw-r--r--views/navbar.html3
4 files changed, 16 insertions, 19 deletions
diff --git a/dashboard.go b/dashboard.go
index 63dcdfc..0ca38ef 100644
--- a/dashboard.go
+++ b/dashboard.go
@@ -7,11 +7,7 @@ import (
7) 7)
8 8
9func viewDashboard(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { 9func viewDashboard(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
10 user, err := app.Charakterin.GetUserFromRequest(r) 10 user, _ := app.Charakterin.GetUserFromRequest(r)
11 if err != nil {
12 http.Redirect(w, r, "/", 302)
13 return
14 }
15 11
16 var categories []grilist.DashboardCategory 12 var categories []grilist.DashboardCategory
17 13
diff --git a/main.go b/main.go
index dacdfe1..6dec94c 100644
--- a/main.go
+++ b/main.go
@@ -19,12 +19,6 @@ import (
19var app *grilist.Grilist 19var app *grilist.Grilist
20 20
21func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { 21func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
22 _, err := app.Charakterin.GetUserFromRequest(r)
23 if err != nil {
24 http.Redirect(w, r, "/login", 302)
25 return
26 }
27
28 http.Redirect(w, r, "/dashboard", 302) 22 http.Redirect(w, r, "/dashboard", 302)
29} 23}
30 24
diff --git a/modules/lists/lists.go b/modules/lists/lists.go
index a7e822a..154bf74 100644
--- a/modules/lists/lists.go
+++ b/modules/lists/lists.go
@@ -177,29 +177,33 @@ func rowsToCard(rows *sql.Rows) []frontend.Card {
177func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory { 177func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory {
178 var categories []grilist.DashboardCategory 178 var categories []grilist.DashboardCategory
179 179
180 // Listen des Benutzers 180 // Neue Listen
181 rows, err := m.g.DB.Query(`SELECT id, name, description FROM grilist.lists WHERE user_id = $1`, user.ID) 181 rows, err := m.g.DB.Query(`SELECT id, name, description FROM grilist.lists ORDER BY id DESC LIMIT 5`)
182 if err != nil { 182 if err != nil {
183 log.Println(err) 183 log.Println(err)
184 return []grilist.DashboardCategory{} 184 return categories
185 } 185 }
186 defer rows.Close() 186 defer rows.Close()
187 187
188 categories = append(categories, grilist.DashboardCategory{ 188 categories = append(categories, grilist.DashboardCategory{
189 Title: "Meine Listen", 189 Title: "Neueste Listen",
190 Cards: rowsToCard(rows), 190 Cards: rowsToCard(rows),
191 }) 191 })
192 192
193 // Neue Listen 193 if user == nil {
194 rows, err = m.g.DB.Query(`SELECT id, name, description FROM grilist.lists ORDER BY id DESC LIMIT 5`) 194 return categories
195 }
196
197 // Listen des Benutzers
198 rows, err = m.g.DB.Query(`SELECT id, name, description FROM grilist.lists WHERE user_id = $1`, user.ID)
195 if err != nil { 199 if err != nil {
196 log.Println(err) 200 log.Println(err)
197 return categories 201 return []grilist.DashboardCategory{}
198 } 202 }
199 defer rows.Close() 203 defer rows.Close()
200 204
201 categories = append(categories, grilist.DashboardCategory{ 205 categories = append(categories, grilist.DashboardCategory{
202 Title: "Neueste Listen", 206 Title: "Meine Listen",
203 Cards: rowsToCard(rows), 207 Cards: rowsToCard(rows),
204 }) 208 })
205 209
diff --git a/views/navbar.html b/views/navbar.html
index c4bbace..70911e4 100644
--- a/views/navbar.html
+++ b/views/navbar.html
@@ -6,6 +6,9 @@
6 {{ if .user }} 6 {{ if .user }}
7 <li><a href="/">{{ .user.Name }}</a></li> 7 <li><a href="/">{{ .user.Name }}</a></li>
8 <li><a href="/logout">Ausloggen</a></li> 8 <li><a href="/logout">Ausloggen</a></li>
9 {{ else }}
10 <li><a href="/login">Einloggen</a></li>
11 <li><a href="/register">Registrieren</a></li>
9 {{ end }} 12 {{ end }}
10 </ul> 13 </ul>
11 </div> 14 </div>