github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume4/section2/gopherface/handlers/myprofile.go (about)

     1  package handlers
     2  
     3  import (
     4  	"log"
     5  	"net/http"
     6  
     7  	"github.com/EngineerKamesh/gofullstack/volume4/section2/gopherface/common/authenticate"
     8  
     9  	"go.isomorphicgo.org/go/isokit"
    10  
    11  	"github.com/EngineerKamesh/gofullstack/volume4/section2/gopherface/common"
    12  	"github.com/EngineerKamesh/gofullstack/volume4/section2/gopherface/forms"
    13  )
    14  
    15  func MyProfileHandler(env *common.Env) http.HandlerFunc {
    16  	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    17  
    18  		formParams := isokit.FormParams{ResponseWriter: w, Request: r}
    19  		myProfileForm := forms.NewMyProfileForm(&formParams)
    20  		gfSession, err := authenticate.SessionStore.Get(r, "gopherface-session")
    21  		if err != nil {
    22  			log.Print(err)
    23  		}
    24  
    25  		uuid := gfSession.Values["uuid"]
    26  		u, err := env.DB.GetUserProfile(uuid.(string))
    27  		if err != nil {
    28  			log.Print(err)
    29  		}
    30  		u.Username = gfSession.Values["username"].(string)
    31  		u.Form = myProfileForm
    32  		u.PageTitle = "My Profile"
    33  
    34  		env.TemplateSet.Render("myprofile_page", &isokit.RenderParams{Writer: w, Data: u})
    35  	})
    36  }