mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-22 17:34:03 +03:00
ssh keys operation page ui
This commit is contained in:
parent
0d9b2f3860
commit
46687f391c
@ -14,7 +14,7 @@ DB_TYPE = mysql
|
||||
HOST =
|
||||
NAME = gogs
|
||||
USER = root
|
||||
PASSWD =
|
||||
PASSWD = fuxiaohei
|
||||
PASSWD_jiahua = root
|
||||
|
||||
[security]
|
||||
|
@ -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;
|
||||
}
|
@ -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() {
|
||||
|
54
routers/user/setting.go
Normal file
54
routers/user/setting.go
Normal file
@ -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)
|
||||
}
|
@ -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>
|
||||
|
62
templates/user/publickey.tmpl
Normal file
62
templates/user/publickey.tmpl
Normal file
@ -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">×</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" .}}
|
19
templates/user/setting.tmpl
Normal file
19
templates/user/setting.tmpl
Normal file
@ -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" .}}
|
8
web.go
8
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)
|
||||
|
Loading…
Reference in New Issue
Block a user