-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandle_user.go
96 lines (82 loc) · 2.04 KB
/
handle_user.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"log"
"net/http"
"github.com/julienschmidt/httprouter"
"github.com/gwd/session-scheduler/event"
"github.com/gwd/session-scheduler/sessions"
)
func HandleUserNew(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
RenderTemplate(w, r, "user/new", map[string]interface{}{
"DefaultLocation": DefaultLocation,
"Locations": TimezoneList,
})
}
func parseProfile(r *http.Request, user *event.User) {
user.RealName = r.FormValue("RealName")
user.Company = r.FormValue("Company")
user.Email = r.FormValue("Email")
user.Description = r.FormValue("Description")
if loc := r.FormValue("Location"); loc != "" {
tzl, err := event.LoadLocation(loc)
if err == nil {
user.Location = tzl
}
}
}
func HandleUserCreate(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
var e string
var err error
var uid event.UserID
var user event.User
user.Username = r.FormValue("Username")
parseProfile(r, &user)
{
evcode, err := kvs.Get(VerificationCode)
if err != nil {
log.Printf("INTERNAL ERROR: Couldn't get event verification code: %v", err)
e = "Internal error"
goto fail
}
vcode := r.FormValue("Vcode")
if vcode == evcode {
user.IsVerified = true
} else if kvs.GetBoolDef(FlagRequireVerification) {
log.Printf("New user failed: Bad vcode %s", vcode)
e = "Incorrect Verification Code"
goto fail
}
}
uid, err = event.NewUser(r.FormValue("Password"), &user)
if err != nil {
if event.IsValidationError(err) {
e = err.Error()
goto fail
}
panic(err)
return
}
if err != nil {
panic(err)
return
}
// Create a new session
_, err = sessions.NewSession(w, string(uid))
if err != nil {
panic(err)
}
http.Redirect(w, r, "/?flash=User+created", http.StatusFound)
return
fail:
RenderTemplate(w, r, "user/new", map[string]interface{}{
"Error": e,
"Username": user.Username,
"Profile": map[string]string{
"RealName": user.RealName,
"Email": user.Email,
"Company": user.Company,
"Description": user.Description,
},
})
return
}