1
0
mirror of https://github.com/go-gitea/gitea synced 2024-12-24 03:35:55 +01:00
This commit is contained in:
Unknown 2014-03-06 13:18:19 -05:00
parent 56a7ab4da5
commit 90223dcfc4
5 changed files with 29 additions and 10 deletions

@ -24,20 +24,26 @@ func Dashboard(r render.Render, data base.TmplData, session sessions.Session) {
r.Redirect("/") r.Redirect("/")
return return
} }
data["IsSigned"] = true data["IsSigned"] = true
data["SignedUserId"] = SignedInId(session) data["SignedUserId"] = SignedInId(session)
data["SignedUserName"] = SignedInName(session) data["SignedUserName"] = SignedInName(session)
data["PageIsUserDashboard"] = true data["PageIsUserDashboard"] = true
data["Avatar"] = SignedInUser(session).Avatar
data["Title"] = "Dashboard" data["Title"] = "Dashboard"
r.HTML(200, "user/dashboard", data) r.HTML(200, "user/dashboard", data)
} }
func Profile(r render.Render) { func Profile(r render.Render, data base.TmplData, session sessions.Session) {
r.HTML(200, "user/profile", map[string]interface{}{ data["Title"] = "Profile"
"Title": "Username",
}) data["IsSigned"] = IsSignedIn(session)
return // 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 { func IsSignedIn(session sessions.Session) bool {
@ -74,6 +80,7 @@ func SignedInUser(session sessions.Session) *models.User {
user, err := models.GetUserById(id) user, err := models.GetUserById(id)
if err != nil { if err != nil {
log.Error("user.SignedInUser: %v", err)
return nil return nil
} }
return user return user
@ -120,6 +127,17 @@ func SignIn(form auth.LogInForm, data base.TmplData, req *http.Request, r render
r.Redirect("/") 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) { func SignUp(form auth.RegisterForm, data base.TmplData, req *http.Request, r render.Render) {
data["Title"] = "Sign Up" data["Title"] = "Sign Up"
data["PageIsSignUp"] = true data["PageIsSignUp"] = true

@ -5,9 +5,9 @@
<a class="gogs-nav-item{{if .PageIsUserDashboard}} active{{end}}" href="#">Dashboard</a> <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="#">Explore</a>
<a class="gogs-nav-item" href="#">Help</a>{{if .IsSigned}} <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}}"> <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>
<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="/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> <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>

@ -4,9 +4,9 @@
<div id="gogs-user-profile" class="col-md-3"> <div id="gogs-user-profile" class="col-md-3">
<div class="profile-avatar text-center"> <div class="profile-avatar text-center">
<a href="#" class="center-block" data-toggle="tooltip" data-placement="bottom" title="Change Avatar"> <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> </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>
<div class="profile-info"> <div class="profile-info">
<ul class="list-group"> <ul class="list-group">

@ -28,7 +28,7 @@
<div class="form-group {{if .Err_RetypePasswd}}has-error has-feedback{{end}}"> <div class="form-group {{if .Err_RetypePasswd}}has-error has-feedback{{end}}">
<label class="col-md-4 control-label">Re-type: </label> <label class="col-md-4 control-label">Re-type: </label>
<div class="col-md-6"> <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>
</div> </div>

1
web.go

@ -59,6 +59,7 @@ func runWeb(*cli.Context) {
// Routers. // Routers.
m.Get("/", routers.Home) m.Get("/", routers.Home)
m.Any("/user/login", binding.BindIgnErr(auth.LogInForm{}), user.SignIn) 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.Any("/user/sign_up", binding.BindIgnErr(auth.RegisterForm{}), user.SignUp)
m.Get("/user/profile", user.Profile) // should be /username m.Get("/user/profile", user.Profile) // should be /username