/
myprofile.go
36 lines (28 loc) · 1015 Bytes
/
myprofile.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 handlers
import (
"log"
"net/http"
"github.com/EngineerKamesh/gofullstack/volume3/section5/gopherface/common/authenticate"
"go.isomorphicgo.org/go/isokit"
"github.com/EngineerKamesh/gofullstack/volume3/section5/gopherface/common"
"github.com/EngineerKamesh/gofullstack/volume3/section5/gopherface/forms"
)
func MyProfileHandler(env *common.Env) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
formParams := isokit.FormParams{ResponseWriter: w, Request: r}
myProfileForm := forms.NewMyProfileForm(&formParams)
gfSession, err := authenticate.SessionStore.Get(r, "gopherface-session")
if err != nil {
log.Print(err)
}
uuid := gfSession.Values["uuid"]
u, err := env.DB.GetUserProfile(uuid.(string))
if err != nil {
log.Print(err)
}
u.Username = gfSession.Values["username"].(string)
u.Form = myProfileForm
u.PageTitle = "My Profile"
env.TemplateSet.Render("myprofile_page", &isokit.RenderParams{Writer: w, Data: u})
})
}