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 @@ <a class="gogs-nav-item{{if .PageIsUserDashboard}} active{{end}}" href="#">Dashboard</a> <a class="gogs-nav-item" href="#">Explore</a> <a class="gogs-nav-item" href="#">Help</a>{{if .IsSigned}} - <a id="gogs-nav-out" class="gogs-nav-item navbar-right navbar-btn btn btn-danger" href="/user/login/"><i class="fa fa-power-off fa-lg"></i></a> + <a id="gogs-nav-out" class="gogs-nav-item navbar-right navbar-btn btn btn-danger" href="/user/logout/"><i class="fa fa-power-off fa-lg"></i></a> <a id="gogs-nav-avatar" class="gogs-nav-item navbar-right" href="/user/profile" data-toggle="tooltip" data-placement="bottom" title="{{.SignedUserName}}"> - <img src="http://1.gravatar.com/avatar/x?s=28" alt="user-avatar" title="username"/> + <img src="http://1.gravatar.com/avatar/{{.Avatar}}?s=28" alt="user-avatar" title="username"/> </a> <a class="navbar-right gogs-nav-item" href="/repo/create" data-toggle="tooltip" data-placement="bottom" title="New Repository"><i class="fa fa-plus fa-lg"></i></a> <a class="navbar-right gogs-nav-item" href="#" data-toggle="tooltip" data-placement="bottom" title="Setting"><i class="fa fa-cogs fa-lg"></i></a> 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 @@ <div id="gogs-user-profile" class="col-md-3"> <div class="profile-avatar text-center"> <a href="#" class="center-block" data-toggle="tooltip" data-placement="bottom" title="Change Avatar"> - <img id="gogs-user-avatar" src="http://1.gravatar.com/avatar/x?s=200" alt="user-avatar" title="username"/> + <img id="gogs-user-avatar" src="http://1.gravatar.com/avatar/{{.Avatar}}?s=200" alt="user-avatar" title="username"/> </a> - <span id="gogs-user-name" class="center-block" href="#">Username</span> + <span id="gogs-user-name" class="center-block" href="#">{{.Username}}</span> </div> <div class="profile-info"> <ul class="list-group"> diff --git a/templates/user/signup.tmpl b/templates/user/signup.tmpl index 03e5bd3440..cfbf27fd93 100644 --- a/templates/user/signup.tmpl +++ b/templates/user/signup.tmpl @@ -28,7 +28,7 @@ <div class="form-group {{if .Err_RetypePasswd}}has-error has-feedback{{end}}"> <label class="col-md-4 control-label">Re-type: </label> <div class="col-md-6"> - <input name="re-passwd" type="password" class="form-control" placeholder="Re-type your password" required="required" title="Re-type Password must be same to Password"> + <input name="retypepasswd" type="password" class="form-control" placeholder="Re-type your password" required="required" title="Re-type Password must be same to Password"> </div> </div> diff --git a/web.go b/web.go index 6f8b902a68..47b9b14de8 100644 --- a/web.go +++ b/web.go @@ -59,6 +59,7 @@ func runWeb(*cli.Context) { // Routers. m.Get("/", routers.Home) m.Any("/user/login", binding.BindIgnErr(auth.LogInForm{}), user.SignIn) + m.Any("/user/logout", user.SignOut) m.Any("/user/sign_up", binding.BindIgnErr(auth.RegisterForm{}), user.SignUp) m.Get("/user/profile", user.Profile) // should be /username