Skip to content

Commit

Permalink
bug fix: disallow empty name and content
Browse files Browse the repository at this point in the history
  • Loading branch information
Mast3rwaf1z committed Sep 24, 2024
1 parent ebbc45f commit d5cfbf2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/Api/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ import Data.Aeson (encode, decode, Value (String))
import Data.ByteString.Lazy (fromStrict, toStrict)
import Database.SQLite.Simple (query, Only (Only))
import Data.Password.Bcrypt (PasswordCheck(PasswordCheckSuccess, PasswordCheckFail), mkPassword, checkPassword, PasswordHash (PasswordHash))
import Data.Text (pack)
import Data.Text (pack, unpack)
import Crypto.Random (getRandomBytes)
import Data.Text.Array (Array(ByteArray))
import Text.StringRandom (stringRandomIO)
import Data.Text (unpack)



handleGuestbookEntry :: GuestbookEntry -> IO (Status, String)
handleGuestbookEntry (GuestbookEntry "" _ _) = return (status400, "Error, name cannot be empty")
handleGuestbookEntry (GuestbookEntry _ "" _) = return (status400, "Error, content cannot be empty")
handleGuestbookEntry (GuestbookEntry name content parentId) = do
time <- fmap round getPOSIXTime :: IO Int
insert "INSERT INTO guestbook (name, timestamp, content, parentId) values (?, ?, ?, ?)" (name :: String, time :: Int, content :: String, parentId :: Int)
Expand Down
3 changes: 3 additions & 0 deletions app/Pages/Guestbook/Guestbook.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ guestbook = do
if(response.status == 200){
window.location.reload()
}
else response.text().then(text => {
alert(response.status + "\n" + text)
})
})
}
</script>
Expand Down

0 comments on commit d5cfbf2

Please sign in to comment.