Use POST on a /delete URL instead of DELETE (which does not work)
Getty Ritter
7 years ago
| 25 | 25 |
|
| 26 | 26 |
instance SQL.ToField User where
|
| 27 | 27 |
toField = SQL.toField . userName
|
| 28 | |
|
| 29 | 28 |
|
| 30 | 29 |
-- | A 'PostRef' is just the information needed to identify a post
|
| 31 | 30 |
-- internally, including when it was posted and its title and slug
|
| 107 | 107 |
DB.runDB (DB.submitPost (User u) rp) c
|
| 108 | 108 |
Web.redirect (postURL oldPost)
|
| 109 | 109 |
|
| 110 | |
("DELETE", [y, m, s]) ->
|
| 111 | |
case user of
|
| 112 | |
Nothing -> Web.redirect "/"
|
| 113 | |
Just _ -> do
|
| 114 | |
Log.warn [ "deleting post!" ]
|
| 115 | |
flip DB.runDB c $ do
|
| 116 | |
post <- DB.postByDateAndSlug y m s
|
| 117 | |
DB.deletePost (postToRawPost post)
|
| 118 | |
Web.redirect "/"
|
| 119 | |
|
| 120 | 110 |
("GET", [y, m, s, "edit"]) ->
|
| 121 | 111 |
case user of
|
| 122 | 112 |
Nothing -> do
|
|
| 126 | 116 |
oldPost <- DB.runDB (DB.postByDateAndSlug y m s) c
|
| 127 | 117 |
contents <- Template.edit (postURL oldPost) (postToRawPost oldPost)
|
| 128 | 118 |
Web.ok user (T.fromStrict (postTitle oldPost)) contents
|
| 119 |
|
| 120 |
("POST", [y, m, s, "delete"]) ->
|
| 121 |
case user of
|
| 122 |
Nothing -> Web.redirect "/"
|
| 123 |
Just _ -> do
|
| 124 |
Log.warn [ "deleting post:", show (y, m, s) ]
|
| 125 |
flip DB.runDB c $ do
|
| 126 |
post <- DB.postByDateAndSlug y m s
|
| 127 |
DB.deletePost (postToRawPost post)
|
| 128 |
Web.redirect "/"
|
| 129 | 129 |
|
| 130 | 130 |
("GET", [y, m, s, "delete"]) ->
|
| 131 | 131 |
case user of
|
| 2 | 2 |
<p>Are you sure you want to delete this post?</p>
|
| 3 | 3 |
<p>
|
| 4 | 4 |
<a href="{{post_url}}">No</a>
|
| 5 | |
<form name="delpost" action="{{post_url}}" method="DELETE">
|
| 5 |
<form name="delpost" action="{{post_url}}/delete" method="POST">
|
| 6 | 6 |
<input type="submit" value="yes" />
|
| 7 | 7 |
</form>
|
| 8 | 8 |
</p>
|