-
Notifications
You must be signed in to change notification settings - Fork 7
/
root.go
68 lines (59 loc) · 1.49 KB
/
root.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2014 Tim Shannon. All rights reserved.
// Use of this source code is governed by the MIT license
// that can be found in the LICENSE file.
package main
import (
"net/http"
"text/template"
"bitbucket.org/tshannon/freehold/app"
"bitbucket.org/tshannon/freehold/resource"
"bitbucket.org/tshannon/freehold/setting"
)
func rootGet(w http.ResponseWriter, r *http.Request) {
if firstRun {
t, err := template.New("firstRun").Parse(firstRunAdminPage)
if err != nil {
panic("First Run admin template cannot be parsed!")
}
t.Execute(w, nil)
return
}
_, pth := splitRootAndPath(r.URL.Path)
if pth != "/" {
four04(w, r)
return
}
auth, err := authenticate(w, r)
if errHandled(err, w, auth) {
return
}
if auth.User != nil {
if auth.User.HomeApp != "" {
app, err := app.Get(auth.User.HomeApp)
if errHandled(err, w, auth) {
return
}
if app != nil {
serveApp(w, r, auth.User.HomeApp, auth)
return
}
}
}
serveResource(w, r, resource.NewFile(setting.String("PublicRootFile")), auth)
}
//Only used on first login for creating the first admin
func rootPost(w http.ResponseWriter, r *http.Request) {
if !firstRun {
four04(w, r)
}
usrErr := makeFirstAdmin(r.FormValue("username"), r.FormValue("password"))
if usrErr != nil {
t, err := template.New("firstRun").Parse(firstRunAdminPage)
if err != nil {
panic("First Run admin template cannot be parsed!")
}
t.Execute(w, usrErr.Error())
return
}
http.Redirect(w, r, "/", http.StatusFound)
}