release/v1.15
Unknown 2014-03-06 13:18:19 -05:00
parent 56a7ab4da5
commit 90223dcfc4
5 changed files with 29 additions and 10 deletions

View File

@ -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

View File

@ -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>

View File

@ -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">

View File

@ -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>

1
web.go
View File

@ -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