mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-28 12:16:17 +01:00
add publickey
This commit is contained in:
parent
d42c194aad
commit
52984f85d5
4 changed files with 24 additions and 9 deletions
|
@ -47,7 +47,7 @@ func GenAuthorizedKey(keyId int64, key string) string {
|
||||||
return fmt.Sprintf(tmplPublicKey, appPath, keyId, key)
|
return fmt.Sprintf(tmplPublicKey, appPath, keyId, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddPublicKey(key *PublicKey, user string) error {
|
func AddPublicKey(key *PublicKey) error {
|
||||||
_, err := orm.Insert(key)
|
_, err := orm.Insert(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -67,11 +67,11 @@ func AddPublicKey(key *PublicKey, user string) error {
|
||||||
|
|
||||||
func SaveAuthorizedKeyFile(key *PublicKey) error {
|
func SaveAuthorizedKeyFile(key *PublicKey) error {
|
||||||
p := filepath.Join(sshPath, "authorized_keys")
|
p := filepath.Join(sshPath, "authorized_keys")
|
||||||
f, err := os.Create(p)
|
f, err := os.OpenFile(p, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
os.Chmod(p, 0600)
|
//os.Chmod(p, 0600)
|
||||||
_, err = f.WriteString(GenAuthorizedKey(key.Id, key.Content))
|
_, err = f.WriteString(GenAuthorizedKey(key.Id, key.Content))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,16 @@ func AddPublickKey(req *http.Request, r render.Render) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
k := &models.PublicKey{}
|
k := &models.PublicKey{OwnerId: 1,
|
||||||
err := models.AddPublicKey(k, "")
|
Name: req.FormValue("keyname"),
|
||||||
r.HTML(403, "status/403", map[string]interface{}{
|
Content: req.FormValue("key_content"),
|
||||||
"Title": fmt.Sprintf("%v", err),
|
}
|
||||||
})
|
err := models.AddPublicKey(k)
|
||||||
|
if err != nil {
|
||||||
|
r.HTML(403, "status/403", map[string]interface{}{
|
||||||
|
"Title": fmt.Sprintf("%v", err),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
r.HTML(200, "user/publickey_added", map[string]interface{}{})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{{template "base/head" .}}
|
{{template "base/head" .}}
|
||||||
{{template "base/navbar" .}}
|
{{template "base/navbar" .}}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<form action="/user/delete" method="post" class="form-horizontal">
|
<form action="/user/publickey/add" method="post" class="form-horizontal">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-md-4 control-label">Name of this public key: </label>
|
<label class="col-md-4 control-label">Name of this public key: </label>
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
|
|
8
templates/user/publickey_added.tmpl
Normal file
8
templates/user/publickey_added.tmpl
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{{template "base/head" .}}
|
||||||
|
{{template "base/navbar" .}}
|
||||||
|
<div class="container">
|
||||||
|
<div class="form-group">
|
||||||
|
publickey added
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{template "base/footer" .}}
|
Loading…
Reference in a new issue