SSH key deletion button

This commit is contained in:
fr33domlover 2016-05-13 21:41:46 +00:00
parent 4d16203e5d
commit 298bbc57e4
4 changed files with 29 additions and 5 deletions

View file

@ -63,7 +63,7 @@ an overview of more-or-less what's left to do before the first release.
[/] Web [/] Web
[ ] SSH [ ] SSH
[ ] Delete repo [ ] Delete repo
[ ] Web [/] Web
[ ] SSH [ ] SSH
[/] Clone [/] Clone
[/] HTTP [/] HTTP
@ -82,7 +82,7 @@ an overview of more-or-less what's left to do before the first release.
[/] Web [/] Web
[ ] SSH [ ] SSH
[ ] Delete repo [ ] Delete repo
[ ] Web [/] Web
[ ] SSH [ ] SSH
[ ] Clone [ ] Clone
[ ] HTTP [ ] HTTP

View file

@ -38,7 +38,7 @@
/u/#Text/k KeysR GET POST /u/#Text/k KeysR GET POST
/u/#Text/k/!new KeyNewR GET /u/#Text/k/!new KeyNewR GET
/u/#Text/k/#Text KeyR GET /u/#Text/k/#Text KeyR GET DELETE POST
/u/#Text/r ReposR GET POST /u/#Text/r ReposR GET POST
/u/#Text/r/!new RepoNewR GET /u/#Text/r/!new RepoNewR GET

View file

@ -18,6 +18,8 @@ module Vervis.Handler.Key
, postKeysR , postKeysR
, getKeyNewR , getKeyNewR
, getKeyR , getKeyR
, deleteKeyR
, postKeyR
) )
where where
@ -31,7 +33,7 @@ import Data.Text.Encoding.Error (lenientDecode)
import Database.Persist import Database.Persist
import Text.Blaze.Html (Html, toHtml) import Text.Blaze.Html (Html, toHtml)
import Yesod.Core (defaultLayout) import Yesod.Core (defaultLayout)
import Yesod.Core.Handler (setMessage, redirectUltDest) import Yesod.Core.Handler
import Yesod.Core.Widget (setTitle) import Yesod.Core.Widget (setTitle)
import Yesod.Form.Functions (runFormPost) import Yesod.Form.Functions (runFormPost)
import Yesod.Form.Types (FormResult (..)) import Yesod.Form.Types (FormResult (..))
@ -65,7 +67,7 @@ postKeysR user = do
FormSuccess key -> do FormSuccess key -> do
runDB $ insert_ key runDB $ insert_ key
setMessage "Key added." setMessage "Key added."
redirectUltDest HomeR redirect $ KeysR user
FormMissing -> do FormMissing -> do
setMessage "Field(s) missing" setMessage "Field(s) missing"
defaultLayout $(widgetFile "key/key-new") defaultLayout $(widgetFile "key/key-new")
@ -96,3 +98,20 @@ getKeyR user tag = do
setTitle $ toHtml $ setTitle $ toHtml $
intercalate " > " ["Vervis", "People", user, "Keys", tag] intercalate " > " ["Vervis", "People", user, "Keys", tag]
$(widgetFile "key/key") $(widgetFile "key/key")
deleteKeyR :: Text -> Text -> Handler Html
deleteKeyR user tag = do
runDB $ do
Entity sid _s <- getBy404 $ UniqueSharerIdent user
Entity pid _p <- getBy404 $ UniquePersonIdent sid
Entity kid _k <- getBy404 $ UniqueSshKey pid tag
delete kid
setMessage "Key deleted."
redirect $ KeysR user
postKeyR :: Text -> Text -> Handler Html
postKeyR user tag = do
mmethod <- lookupPostParam "_method"
case mmethod of
Just "DELETE" -> deleteKeyR user tag
_ -> notFound

View file

@ -12,6 +12,11 @@ $# You should have received a copy of the CC0 Public Domain Dedication along
$# with this software. If not, see $# with this software. If not, see
$# <http://creativecommons.org/publicdomain/zero/1.0/>. $# <http://creativecommons.org/publicdomain/zero/1.0/>.
<p>
<form method=POST action=@{KeyR user tag}>
<input type=hidden name=_method value=DELETE>
<input type=submit value="Delete this key">
<table> <table>
<tr> <tr>
<td>Algorithm <td>Algorithm