/
credentials.go
36 lines (29 loc) · 902 Bytes
/
credentials.go
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
33
34
35
36
package browser
import (
"net/http"
"google.golang.org/appengine"
"google.golang.org/appengine/log"
"github.com/julienschmidt/httprouter"
)
func handleCredentials(res http.ResponseWriter, req *http.Request, _ httprouter.Params) {
err := tpl.ExecuteTemplate(res, "credentials", nil)
if err != nil {
ctx := appengine.NewContext(req)
http.Error(res, "Server Error", http.StatusInternalServerError)
log.Errorf(ctx, err.Error())
return
}
}
func handleLogin(res http.ResponseWriter, req *http.Request, _ httprouter.Params) {
ctx := appengine.NewContext(req)
s := getSession(ctx, req)
s.Bucket = req.FormValue("bucket")
s.Credentials = req.FormValue("credentials")
err := putSession(ctx, res, s)
if err != nil {
http.Error(res, "Server Error", http.StatusInternalServerError)
log.Errorf(ctx, err.Error())
return
}
http.Redirect(res, req, "/browse/", http.StatusSeeOther)
}