-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfirm.go
38 lines (30 loc) · 1008 Bytes
/
confirm.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
package gouncer
import (
"net/http"
"strings"
)
type Confirm struct {
*Backend
Handler *ResponseHandler
}
func NewConfirm(h *ResponseHandler) *Confirm {
return &Confirm{Handler: h}
}
// Registration completes the registration process after the user clicks the confirmation link
func (c *Confirm) Registration() {
segs := strings.Split(c.Handler.HttpRequest.URL.Path, "/")
if item, err := c.Backend.Cache.Get(segs[len(segs)-1]); err == nil {
doc := item.Value
couch := NewCouch(c.Backend.Couchdb, c.Backend.Userdb)
if _, err := couch.Post(doc); err == nil {
// If the user object was correctly saved to the backend we delete the cache entry
c.Backend.Cache.Delete(segs[len(segs)-1])
// Respond to the user
c.Handler.NewResponse(http.StatusOK, "Registration successfull. You can now login with your new account.")
} else {
c.Handler.NewError(http.StatusInternalServerError, err.Error())
}
} else {
c.Handler.NewError(http.StatusInternalServerError, err.Error())
}
}