尝试将HSP和Acid-state以Happstack的形式结合在一起



我遵循Happstack速成班,现在我正试图把不同的东西结合在一起:

从"使用改革的类型安全表单处理"(http://happstack.com/docs/crashcourse/Reform.html#reform)我已经编码了这个注册表单:

register :: AcidState UserBase -> ServerPart Response
register acid = unXMLGenT $
  appTemplate "register" () $
        reform (form "/register") "register" (insertAndRenderUser acid) Nothing registerForm
insertAndRenderUser :: (Monad m) => AcidState UserBase -> User -> AppT m XML
insertAndRenderUser acid user = 
    <dl>
      <dt>lastname:</dt>    <dd><% lastName user    %></dd>
      <dt>firstname:</dt>   <dd><% firstName user   %></dd>
      <dt>email:</dt> <dd><% email user %></dd>
      <dt>birthday:</dt> <dd><% show (birthday user) %></dd>
    </dl>

registerForm :: SimpleForm User
registerForm =
    User (UserId 0)
     <$> (errorList ++> label "Last name:"  ++>  (inputText "" `transformEither` required) <++ br)
     <*> (errorList ++> label "First name:" ++> (inputText "" `transformEither` required) <++ br)
     <*> (errorList ++> label "E-mail:"     ++> (inputText "" `transformEither` required) <++ br)
     <*> (errorList ++> label "Birthday:"   ++> (inputText "" `transformEither` requireDate) <++ br)
     <*  inputSubmit "Register"

现在我想在表单成功时添加注册用户。我已经编码了这个UserBase与帮助酸状态(http://happstack.com/docs/crashcourse/AcidState.html#ixset)

insertUser :: MonadIO m => AcidState (EventState InsertUserIntern) -> User -> m (EventResult InsertUserIntern)  
insertUser acid user = do
  update' acid (InsertUserIntern user)

片段单独工作,但我在哪里可以在insertAndRenderUser中插入insertUser acid user ?

我希望你能帮助我。
由于
弗洛

我自己买的

insertAndRenderUser acid user = do
  insertUser acid user 
  appTemplate "Your Registration" () $
    <dl>
      <dt>lastname:</dt>    <dd><% lastName user    %></dd>
      <dt>firstname:</dt>   <dd><% firstName user   %></dd>
      <dt>email:</dt> <dd><% email user %></dd>
      <dt>birthday:</dt> <dd><% show (birthday user) %></dd>
    </dl>

相关内容

  • 没有找到相关文章