diff --git a/routers/user/user.go b/routers/user/user.go index 2e6cb3d596..90494b2834 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -24,20 +24,26 @@ func Dashboard(r render.Render, data base.TmplData, session sessions.Session) { r.Redirect("/") return } + data["IsSigned"] = true data["SignedUserId"] = SignedInId(session) data["SignedUserName"] = SignedInName(session) data["PageIsUserDashboard"] = true + data["Avatar"] = SignedInUser(session).Avatar data["Title"] = "Dashboard" r.HTML(200, "user/dashboard", data) } -func Profile(r render.Render) { - r.HTML(200, "user/profile", map[string]interface{}{ - "Title": "Username", - }) - return +func Profile(r render.Render, data base.TmplData, session sessions.Session) { + data["Title"] = "Profile" + + data["IsSigned"] = IsSignedIn(session) + // TODO: Need to check view self or others. + user := SignedInUser(session) + data["Avatar"] = user.Avatar + data["Username"] = user.Name + r.HTML(200, "user/profile", data) } func IsSignedIn(session sessions.Session) bool { @@ -74,6 +80,7 @@ func SignedInUser(session sessions.Session) *models.User { user, err := models.GetUserById(id) if err != nil { + log.Error("user.SignedInUser: %v", err) return nil } return user @@ -120,6 +127,17 @@ func SignIn(form auth.LogInForm, data base.TmplData, req *http.Request, r render r.Redirect("/") } +func SignOut(r render.Render, session sessions.Session) { + if !IsSignedIn(session) { + r.Redirect("/") + return + } + + session.Delete("userId") + session.Delete("userName") + r.Redirect("/") +} + func SignUp(form auth.RegisterForm, data base.TmplData, req *http.Request, r render.Render) { data["Title"] = "Sign Up" data["PageIsSignUp"] = true diff --git a/templates/base/navbar.tmpl b/templates/base/navbar.tmpl index a52ce6c034..323759ba18 100644 --- a/templates/base/navbar.tmpl +++ b/templates/base/navbar.tmpl @@ -5,9 +5,9 @@ Dashboard Explore Help{{if .IsSigned}} - + - + diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index e7056aa869..09fe4ae5b6 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -4,9 +4,9 @@