summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFuXiaoHei <fuxiaohei@hexiaz.com>2014-03-10 16:54:52 +0800
committerFuXiaoHei <fuxiaohei@hexiaz.com>2014-03-10 16:54:52 +0800
commit46687f391c4e81fd17f7ecac22d3587c711e07d5 (patch)
tree96b3486af84c634647dc03b2e7849d5618c0f42c
parent0d9b2f38600325e3a8d87526061efbe9e3b78b91 (diff)
downloadgitea-46687f391c4e81fd17f7ecac22d3587c711e07d5.tar.gz
gitea-46687f391c4e81fd17f7ecac22d3587c711e07d5.zip
ssh keys operation page ui
-rw-r--r--conf/app.ini2
-rwxr-xr-xpublic/css/gogs.css74
-rw-r--r--public/js/app.js27
-rw-r--r--routers/user/setting.go54
-rw-r--r--templates/base/navbar.tmpl2
-rw-r--r--templates/user/publickey.tmpl62
-rw-r--r--templates/user/setting.tmpl19
-rw-r--r--web.go8
8 files changed, 237 insertions, 11 deletions
diff --git a/conf/app.ini b/conf/app.ini
index 72c968b3e5..acfea5ce1c 100644
--- a/conf/app.ini
+++ b/conf/app.ini
@@ -14,7 +14,7 @@ DB_TYPE = mysql
HOST =
NAME = gogs
USER = root
-PASSWD =
+PASSWD = fuxiaohei
PASSWD_jiahua = root
[security]
diff --git a/public/css/gogs.css b/public/css/gogs.css
index 6580d907a6..9205178f4d 100755
--- a/public/css/gogs.css
+++ b/public/css/gogs.css
@@ -28,6 +28,10 @@ body {
margin: 0 .5em;
}
+.list-group .list-group-item {
+ background-color: transparent;
+}
+
/* gogits nav header */
.gogs-masthead {
background-color: #428bca;
@@ -222,4 +226,74 @@ body {
#gogs-repo-create textarea[name=desc] {
height: 8em;
+}
+
+/* gogits user setting */
+
+#gogs-user-setting-nav > h4, #gogs-user-setting-container > h4 ,#gogs-ssh-keys > h4{
+ padding-bottom: 18px;
+ margin-bottom: 18px;
+ border-bottom: 1px solid #CCC;
+}
+
+#gogs-user-setting-nav .list-group .list-group-item a {
+ margin-left: 0;
+ padding: .6em;
+ font-size: 14px;
+ color: #3B73AF;
+}
+
+#gogs-user-setting-nav .list-group .list-group-item {
+ background-color: transparent;
+}
+
+#gogs-user-setting-nav .list-group .list-group-item-success a {
+ font-weight: bold;
+ color: #444;
+}
+
+/* gogits user ssh keys */
+
+#gogs-ssh-keys .list-group-item {
+ line-height: 48px;
+ border-bottom: 1px solid #DDD;
+}
+
+#gogs-ssh-keys .list-group-item:after{
+ clear: both;
+}
+
+#gogs-ssh-keys .list-group-item:hover a.delete{
+ display: block;
+}
+
+#gogs-ssh-keys .name {
+ font-size: 14px;
+ font-weight: bold;
+}
+
+#gogs-ssh-keys .list-group-item a.delete {
+ float: right;
+ color: white;
+ cursor: pointer;
+ margin-top: 10px;
+ border-radius: 3px;
+ display: none;
+}
+
+#gogs-ssh-keys .print {
+ padding-left: 1em;
+ color: #888;
+}
+
+#gogs-ssh-add {
+ display: inline-block;
+ color: white;
+ cursor: pointer;
+ margin-left: 0;
+ border-radius: 3px;
+}
+
+#gogs-ssh-form textarea{
+ height: 16em;
} \ No newline at end of file
diff --git a/public/js/app.js b/public/js/app.js
index 6a4c72bd78..59d521090c 100644
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -3,12 +3,7 @@ var Gogits = {
};
(function ($) {
- Gogits.showTooltips = function () {
- $("body").tooltip({
- selector: "[data-toggle=tooltip]"
- //container: "body"
- });
- };
+
Gogits.showTab = function (selector, index) {
if (!index) {
index = 0;
@@ -27,11 +22,29 @@ var Gogits = {
};
$form.validate(options);
};
+
+ // ----- init elements
+ Gogits.initModals = function () {
+ var modals = $("[data-toggle=modal]");
+ if (modals.length < 1) {
+ return;
+ }
+ $.each(modals, function (i, item) {
+ $(item).modal("hide");
+ });
+ };
+ Gogits.initTooltips = function () {
+ $("body").tooltip({
+ selector: "[data-toggle=tooltip]"
+ //container: "body"
+ });
+ };
})(jQuery);
function initCore() {
- Gogits.showTooltips();
+ Gogits.initTooltips();
+ Gogits.initModals();
}
function initRegister() {
diff --git a/routers/user/setting.go b/routers/user/setting.go
new file mode 100644
index 0000000000..84be138170
--- /dev/null
+++ b/routers/user/setting.go
@@ -0,0 +1,54 @@
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package user
+
+import (
+ "github.com/gogits/gogs/models"
+ "github.com/gogits/gogs/modules/auth"
+ "github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/log"
+ "github.com/martini-contrib/render"
+ "github.com/martini-contrib/sessions"
+ "net/http"
+)
+
+func Setting(r render.Render, data base.TmplData, session sessions.Session) {
+ data["Title"] = "Setting"
+ data["PageIsUserSetting"] = true
+ r.HTML(200, "user/setting", data)
+}
+
+func SettingSSHKeys(r render.Render, data base.TmplData, req *http.Request, session sessions.Session) {
+ // add ssh key
+ if req.Method == "POST" {
+ k := &models.PublicKey{OwnerId: auth.SignedInId(session),
+ Name: req.FormValue("keyname"),
+ Content: req.FormValue("key_content"),
+ }
+ err := models.AddPublicKey(k)
+ if err != nil {
+ data["ErrorMsg"] = err
+ log.Error("ssh.AddPublicKey: %v", err)
+ r.HTML(200, "base/error", data)
+ return
+ } else {
+ data["AddSSHKeySuccess"] = true
+ }
+ }
+ // get keys
+ keys, err := models.ListPublicKey(auth.SignedInId(session))
+ if err != nil {
+ data["ErrorMsg"] = err
+ log.Error("ssh.ListPublicKey: %v", err)
+ r.HTML(200, "base/error", data)
+ return
+ }
+
+ // set to template
+ data["Title"] = "SSH Keys"
+ data["PageIsUserSetting"] = true
+ data["Keys"] = keys
+ r.HTML(200, "user/publickey", data)
+}
diff --git a/templates/base/navbar.tmpl b/templates/base/navbar.tmpl
index 12434dad22..e78f6bb221 100644
--- a/templates/base/navbar.tmpl
+++ b/templates/base/navbar.tmpl
@@ -10,7 +10,7 @@
<img src="http://1.gravatar.com/avatar/{{.SignedAvatar}}?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="/user/publickey/list" data-toggle="tooltip" data-placement="bottom" title="Setting"><i class="fa fa-cogs fa-lg"></i></a>
+ <a class="navbar-right gogs-nav-item{{if .PageIsUserSetting}} active{{end}}" href="/user/setting" 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>
</div>
diff --git a/templates/user/publickey.tmpl b/templates/user/publickey.tmpl
new file mode 100644
index 0000000000..fbd12adbd0
--- /dev/null
+++ b/templates/user/publickey.tmpl
@@ -0,0 +1,62 @@
+{{template "base/head" .}}
+{{template "base/navbar" .}}
+<div id="gogs-body" class="container">
+ <div id="gogs-user-setting-nav" class="col-md-3">
+ <h4>Account Setting</h4>
+ <ul class="list-group">
+ <li class="list-group-item"><a href="/user/setting">Account Profile</a></li>
+ <li class="list-group-item"><a href="#">Emails and Password</a></li>
+ <li class="list-group-item"><a href="#">Notifications</a></li>
+ <li class="list-group-item list-group-item-success"><a href="/user/setting/ssh/">SSH Keys</a></li>
+ <li class="list-group-item"><a href="#">Security</a></li>
+ <li class="list-group-item"><a href="#">Kill Myself</a></li>
+ </ul>
+ </div>
+ <div id="gogs-user-setting-container" class="col-md-9">
+ <div id="gogs-ssh-keys">
+ <h4>SSH Keys</h4>{{if .AddSSHKeySuccess}}
+ <p class="alert alert-success">New SSH Key is added !</p>{{end}}
+ <ul id="gogs-ssh-keys-list" class="list-group">
+ <li class="list-group-item"><span class="name">SSH Key's name</span></li>{{range .Keys}}
+ <li class="list-group-item">
+ <span class="name">{{.Name}}</span>
+ <span class="print">(print code)</span>
+ <a href="#" class="btn btn-link btn-danger right delete" rel="{{.Id}}" data-del="{{.Id}}">Delete</a>
+ </li>{{end}}
+ <li class="list-group-item">
+ <a class="btn btn-link btn-primary" href="#ssh-add-modal" id="gogs-ssh-add" data-toggle="modal">Add SSH Key</a>
+ </li>
+ </ul>
+ <div class="modal fade" id="ssh-add-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
+ <div class="modal-dialog">
+ <form class="modal-content form-horizontal" id="gogs-ssh-form" method="post" action="/user/setting/ssh/">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
+ <h4 class="modal-title" id="myModalLabel">Add SSH Key</h4>
+ </div>
+ <div class="modal-body">
+ <div class="form-group">
+ <label class="col-md-3 control-label">The name of key<strong class="text-danger">*</strong></label>
+ <div class="col-md-8">
+ <input name="keyname" class="form-control" placeholder="Type your preferred name" required="required">
+ </div>
+ </div>
+ <div class="form-group">
+ <label class="col-md-3 control-label">SSH Key<strong class="text-danger">*</strong></label>
+ <div class="col-md-8">
+ <textarea name="key_content" class="form-control" placeholder="Type your key content" required="required"></textarea>
+ </div>
+ </div>
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
+ <button type="submit" class="btn btn-primary">Save changes</button>
+ </div>
+ </form>
+ </div>
+ </div>
+ <p><strong>Need help?</strong> Check out our guide to <a href="https://help.github.com/articles/generating-ssh-keys" target="_blank">generating SSH keys</a> or troubleshoot <a href="https://help.github.com/ssh-issues/" target="_blank">common SSH Problems</a></p>
+ </div>
+ </div>
+</div>
+{{template "base/footer" .}} \ No newline at end of file
diff --git a/templates/user/setting.tmpl b/templates/user/setting.tmpl
new file mode 100644
index 0000000000..b2b595ffe2
--- /dev/null
+++ b/templates/user/setting.tmpl
@@ -0,0 +1,19 @@
+{{template "base/head" .}}
+{{template "base/navbar" .}}
+<div id="gogs-body" class="container">
+ <div id="gogs-user-setting-nav" class="col-md-3">
+ <h4>Account Setting</h4>
+ <ul class="list-group">
+ <li class="list-group-item list-group-item-success"><a href="/user/setting">Account Profile</a></li>
+ <li class="list-group-item"><a href="#">Emails and Password</a></li>
+ <li class="list-group-item"><a href="#">Notifications</a></li>
+ <li class="list-group-item"><a href="/user/setting/ssh/">SSH Keys</a></li>
+ <li class="list-group-item"><a href="#">Security</a></li>
+ <li class="list-group-item"><a href="#">Kill myself</a></li>
+ </ul>
+ </div>
+ <div id="gogs-user-setting-container" class="col-md-9">
+ setting container
+ </div>
+</div>
+{{template "base/footer" .}} \ No newline at end of file
diff --git a/web.go b/web.go
index 1b61ca0e1b..7c030af082 100644
--- a/web.go
+++ b/web.go
@@ -64,10 +64,14 @@ func runWeb(*cli.Context) {
m.Any("/user/logout", auth.SignInRequire(true), user.SignOut)
m.Any("/user/sign_up", auth.SignOutRequire(), binding.BindIgnErr(auth.RegisterForm{}), user.SignUp)
m.Any("/user/delete", auth.SignInRequire(true), user.Delete)
+
+ m.Any("/user/setting",auth.SignInRequire(true),user.Setting)
+ m.Any("/user/setting/ssh",auth.SignInRequire(true),user.SettingSSHKeys)
+
m.Get("/user/:username", auth.SignInRequire(false), user.Profile)
- m.Any("/user/publickey/add", auth.SignInRequire(true), user.AddPublicKey)
- m.Any("/user/publickey/list", auth.SignInRequire(true), user.ListPublicKey)
+ //m.Any("/user/publickey/add", auth.SignInRequire(true), user.AddPublicKey)
+ //m.Any("/user/publickey/list", auth.SignInRequire(true), user.ListPublicKey)
m.Any("/repo/create", auth.SignInRequire(true), binding.BindIgnErr(auth.CreateRepoForm{}), repo.Create)
m.Any("/repo/delete", auth.SignInRequire(true), repo.Delete)