From 4b912b9ae6e087271c0c98b6e444384555ea3e84 Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Thu, 6 Mar 2014 21:33:17 +0800 Subject: signed-in dashboard and navbar changes --- public/css/gogs.css | 12 ++++++------ routers/dashboard.go | 13 +++++++++---- routers/user/user.go | 21 +++++++++++++++++++++ templates/base/head.tmpl | 2 +- templates/base/navbar.tmpl | 7 +++---- templates/dashboard.tmpl | 6 ------ templates/home.tmpl | 6 ++++++ templates/user/dashboard.tmpl | 6 ++++++ web.go | 2 +- 9 files changed, 53 insertions(+), 22 deletions(-) delete mode 100644 templates/dashboard.tmpl create mode 100644 templates/home.tmpl create mode 100644 templates/user/dashboard.tmpl diff --git a/public/css/gogs.css b/public/css/gogs.css index c08c1e3b..471c796d 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -47,17 +47,17 @@ body { text-decoration: none; } +.gogs-nav-item.navbar-right { + margin-top: 3px; +} + .gogs-nav-item.navbar-btn { cursor: pointer; margin-top: 8px; padding: 5px 15px; } -.gogs-nav-item.navbar-right { - margin-top: 3px; -} - -.gogs-nav-item.navbar-right .fa{ +.gogs-nav-item.navbar-right .fa { margin: 0; } @@ -80,7 +80,7 @@ body { border-left: 5px solid transparent; } -.gogs-nav .tooltip{ +.gogs-nav .tooltip { border: none; } diff --git a/routers/dashboard.go b/routers/dashboard.go index 8c370027..c1546238 100644 --- a/routers/dashboard.go +++ b/routers/dashboard.go @@ -5,11 +5,16 @@ package routers import ( + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/routers/user" "github.com/martini-contrib/render" + "github.com/martini-contrib/sessions" ) -func Dashboard(r render.Render) { - r.HTML(200, "dashboard", map[string]interface{}{ - "Title": "Dashboard", - }) +func Home(r render.Render, data base.TmplData, session sessions.Session) { + if user.IsSignedIn(session) { + user.Dashboard(r, data, session) + return + } + r.HTML(200, "home", nil) } diff --git a/routers/user/user.go b/routers/user/user.go index ccbbd01b..9e4e30bb 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -18,6 +18,20 @@ import ( "github.com/gogits/gogs/utils/log" ) +func Dashboard(r render.Render, data base.TmplData, session sessions.Session) { + if !IsSignedIn(session) { + // todo : direct to logout + r.Redirect("/") + return + } + data["IsSigned"] = true + data["SignedUserId"] = SignedInId(session) + data["SignedUserName"] = SignedInName(session) + + data["Title"] = "Dashboard" + r.HTML(200, "user/dashboard", data) +} + func Profile(r render.Render) { r.HTML(200, "user/profile", map[string]interface{}{ "Title": "Username", @@ -65,10 +79,16 @@ func SignedInUser(session sessions.Session) *models.User { } func SignIn(req *http.Request, r render.Render, session sessions.Session) { + // if logged, do not show login page + if IsSignedIn(session) { + r.Redirect("/") + return + } var ( errString string account string ) + // if post, do login action if req.Method == "POST" { account = req.FormValue("account") user, err := models.LoginUserPlain(account, req.FormValue("passwd")) @@ -82,6 +102,7 @@ func SignIn(req *http.Request, r render.Render, session sessions.Session) { // login fail errString = fmt.Sprintf("%v", err) } + // if get or error post, show login page r.HTML(200, "user/signin", map[string]interface{}{ "Title": "Log In", "Error": errString, diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index 0294ba49..e881e7f5 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -16,7 +16,7 @@ - {{.Title}} - {{AppName}} + {{if .Title}}{{.Title}} - {{end}}{{AppName}} \ No newline at end of file diff --git a/templates/base/navbar.tmpl b/templates/base/navbar.tmpl index 00112c03..82fc3ae1 100644 --- a/templates/base/navbar.tmpl +++ b/templates/base/navbar.tmpl @@ -4,15 +4,14 @@ Dashboard Explore - Help - - + Help{{if .IsSigned}} - + user-avatar + {{else}}Sign in{{end}} diff --git a/templates/dashboard.tmpl b/templates/dashboard.tmpl deleted file mode 100644 index 8cbb29eb..00000000 --- a/templates/dashboard.tmpl +++ /dev/null @@ -1,6 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -
- Website is still in the progress of building...please come back later! -
-{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/home.tmpl b/templates/home.tmpl new file mode 100644 index 00000000..8cbb29eb --- /dev/null +++ b/templates/home.tmpl @@ -0,0 +1,6 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +
+ Website is still in the progress of building...please come back later! +
+{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/user/dashboard.tmpl b/templates/user/dashboard.tmpl new file mode 100644 index 00000000..bde541a6 --- /dev/null +++ b/templates/user/dashboard.tmpl @@ -0,0 +1,6 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +
+ Website is still in the progress of building...please come back later! {{.SignedUserName}} is logged! +
+{{template "base/footer" .}} \ No newline at end of file diff --git a/web.go b/web.go index 90551510..8f5c6c81 100644 --- a/web.go +++ b/web.go @@ -57,7 +57,7 @@ func runWeb(*cli.Context) { m.Use(sessions.Sessions("my_session", store)) // Routers. - m.Get("/", routers.Dashboard) + m.Get("/", routers.Home) m.Any("/user/login", user.SignIn) m.Any("/user/sign_up", binding.BindIgnErr(auth.RegisterForm{}), user.SignUp) -- cgit v1.2.3