forked from Luzifer/cloudkeys-go
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoverview.go
More file actions
32 lines (25 loc) · 789 Bytes
/
overview.go
File metadata and controls
32 lines (25 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main
import (
"context"
"net/http"
"github.com/flosch/pongo2"
"github.com/gorilla/sessions"
)
func overviewHandler(c context.Context, res http.ResponseWriter, r *http.Request, session *sessions.Session, ctx *pongo2.Context) (*string, error) {
user, _ := checkLogin(c, r, session)
if user == nil || !storage.IsPresent(c, user.UserFile) {
http.Redirect(res, r, "../../login", http.StatusFound)
return nil, nil
}
frontendAccounts := []string{}
idx := -1
for i, v := range session.Values["authorizedAccounts"].(authorizedAccounts) {
frontendAccounts = append(frontendAccounts, v.Name)
if v.Name == user.Name {
idx = i
}
}
(*ctx)["authorized_accounts"] = frontendAccounts
(*ctx)["current_user_index"] = idx
return stringPointer("overview.html"), nil
}