Try something like this. Haven't checked it in ghc but should give you the idea.
handleFormSubmit = do
exists <- usernameExists "someUserName"
case exists of
True -> writeBS "The username already exists"
False -> do
createUser "someUserName" "password"
redirect' "/" 301
You can't return a value after using redirect
because that routes the client to a new page. Since createUser
throws a DuplicateLogin
error if the user already exists it may be better to just catch that error than doing a check because it is still possible between the check and the insert the same username got inserted elsewhere. Unlikely but possible. Also, you should use redirect'
because this signifies a permanent redirect.