1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-22 12:54:53 -05:00

signed-in dashboard and navbar changes

This commit is contained in:
FuXiaoHei 2014-03-06 21:33:17 +08:00
parent e878bfb80f
commit 4b912b9ae6
8 changed files with 47 additions and 16 deletions

View file

@ -47,17 +47,17 @@ body {
text-decoration: none; text-decoration: none;
} }
.gogs-nav-item.navbar-right {
margin-top: 3px;
}
.gogs-nav-item.navbar-btn { .gogs-nav-item.navbar-btn {
cursor: pointer; cursor: pointer;
margin-top: 8px; margin-top: 8px;
padding: 5px 15px; padding: 5px 15px;
} }
.gogs-nav-item.navbar-right { .gogs-nav-item.navbar-right .fa {
margin-top: 3px;
}
.gogs-nav-item.navbar-right .fa{
margin: 0; margin: 0;
} }
@ -80,7 +80,7 @@ body {
border-left: 5px solid transparent; border-left: 5px solid transparent;
} }
.gogs-nav .tooltip{ .gogs-nav .tooltip {
border: none; border: none;
} }

View file

@ -5,11 +5,16 @@
package routers package routers
import ( import (
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/routers/user"
"github.com/martini-contrib/render" "github.com/martini-contrib/render"
"github.com/martini-contrib/sessions"
) )
func Dashboard(r render.Render) { func Home(r render.Render, data base.TmplData, session sessions.Session) {
r.HTML(200, "dashboard", map[string]interface{}{ if user.IsSignedIn(session) {
"Title": "Dashboard", user.Dashboard(r, data, session)
}) return
}
r.HTML(200, "home", nil)
} }

View file

@ -18,6 +18,20 @@ import (
"github.com/gogits/gogs/utils/log" "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) { func Profile(r render.Render) {
r.HTML(200, "user/profile", map[string]interface{}{ r.HTML(200, "user/profile", map[string]interface{}{
"Title": "Username", "Title": "Username",
@ -65,10 +79,16 @@ func SignedInUser(session sessions.Session) *models.User {
} }
func SignIn(req *http.Request, r render.Render, session sessions.Session) { 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 ( var (
errString string errString string
account string account string
) )
// if post, do login action
if req.Method == "POST" { if req.Method == "POST" {
account = req.FormValue("account") account = req.FormValue("account")
user, err := models.LoginUserPlain(account, req.FormValue("passwd")) 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 // login fail
errString = fmt.Sprintf("%v", err) errString = fmt.Sprintf("%v", err)
} }
// if get or error post, show login page
r.HTML(200, "user/signin", map[string]interface{}{ r.HTML(200, "user/signin", map[string]interface{}{
"Title": "Log In", "Title": "Log In",
"Error": errString, "Error": errString,

View file

@ -16,7 +16,7 @@
<script src="/js/jquery-1.10.1.min.js"></script> <script src="/js/jquery-1.10.1.min.js"></script>
<script src="/js/bootstrap.min.js"></script> <script src="/js/bootstrap.min.js"></script>
<script src="/js/app.js"></script> <script src="/js/app.js"></script>
<title>{{.Title}} - {{AppName}}</title> <title>{{if .Title}}{{.Title}} - {{end}}{{AppName}}</title>
</head> </head>
<body> <body>
<noscript>Please enable JavaScript in your browser!</noscript> <noscript>Please enable JavaScript in your browser!</noscript>

View file

@ -4,15 +4,14 @@
<a class="gogs-nav-item active" href="/"><img src="/img/favicon.png" alt="Gogs Logo" id="gogs-logo"></a> <a class="gogs-nav-item active" href="/"><img src="/img/favicon.png" alt="Gogs Logo" id="gogs-logo"></a>
<a class="gogs-nav-item" href="#">Dashboard</a> <a class="gogs-nav-item" 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> <a class="gogs-nav-item" href="#">Help</a>{{if .IsSigned}}
<!--<a class="gogs-nav-item navbar-right navbar-btn btn btn-danger" href="/login/">Sign in</a>-->
<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/login/"><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="Username"> <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/x?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>
{{else}}<a id="gogs-nav-signin" class="gogs-nav-item navbar-right navbar-btn btn btn-danger" href="/user/login/">Sign in</a>{{end}}
</nav> </nav>
</div> </div>
</div> </div>

View file

@ -0,0 +1,6 @@
{{template "base/head" .}}
{{template "base/navbar" .}}
<div id="gogs-body" class="container">
Website is still in the progress of building...please come back later! <strong>{{.SignedUserName}}</strong> is logged!
</div>
{{template "base/footer" .}}

2
web.go
View file

@ -57,7 +57,7 @@ func runWeb(*cli.Context) {
m.Use(sessions.Sessions("my_session", store)) m.Use(sessions.Sessions("my_session", store))
// Routers. // Routers.
m.Get("/", routers.Dashboard) m.Get("/", routers.Home)
m.Any("/user/login", user.SignIn) m.Any("/user/login", user.SignIn)
m.Any("/user/sign_up", binding.BindIgnErr(auth.RegisterForm{}), user.SignUp) m.Any("/user/sign_up", binding.BindIgnErr(auth.RegisterForm{}), user.SignUp)