我试图在相当长的一段时间里 环绕着我的大脑 如何在消化式杀菌剂形式字段中使用验证, 这需要访问另一个monad 。 简略地说, 我有一个< hackage. hasskell. org/ packages/archives/ archive/ digestive- functors/ 0. 4. 0.0/ doc/ html/ Text- Digestive. html" rel= “ nofolpol” >digestive a> form like this
studentRegistrationForm :: Monad m => Form Text m StudentRegistrationData
studentRegistrationForm = StudentRegistrationData
<$> "school" .: choice schools Nothing
<*> "studentId" .: check studentIdErrMsg (not . T.null) (text Nothing)
<*> "firstName" .: check firstNameErrMsg (not . T.null) (text Nothing)
<*> "lastName" .: check lastNameErrMsg (not . T.null) (text Nothing)
<*> "email" .: check emailErrMsg (E.isValid . T.unpack) (text Nothing)
(学生Id基本上是用户名)
并使用的 usernameexists
< a href="http://hackage.haskell.org/packages/archives/archive/snap/ 0.7/doc/html/Snap-Snaplet-Auth.html" rel=“nofollow”>Snap.Snaplet.Auth 的函数,检查输入用户名是否独一无二。
为了完整起见,这里是相应的数据类型:
data StudentRegistrationData = StudentRegistrationData
{ school :: School -- ^ school the student is enroled
, studentId :: Text -- ^ matriculation number of the student
, firstName :: Text -- ^ first name of the student
, lastName :: Text -- ^ last name of the student
, email :: Text -- ^ email for sending password
} deriving (Show)
我创造我的形式 在一个处理器像:
studentRegistrationHandler :: AppHandler ()
studentRegistrationHandler = do
(view, registrationData) <- runForm "form" SRF.studentRegistrationForm
maybe (showForm "registration" view) createUser registrationData
showForm :: String -> View Text -> AppHandler ()
showForm name view =
heistLocal (bindDigestiveSplices view) $ render template
where
template = BS.pack $ "student-" ++ name ++ "-form"
所以,我现在的问题是如何理解 如何在窗体中访问 auuth spnillet 状态。 它已经通过还是我必须亲自通过? checkM
分别在 validateM
我发现了一些如何使用消化杀菌剂和折断授体和会话的例子,例如:
但没有人能显示Snap.Snaplet.Adex和消化带菌者直接一起工作,
我可以在刺青上上传一个独立的例子, 说明我的问题, 如果有助于说明这一点的话。 任何提示、 指示和建议都是非常欢迎的!!!!
汉内斯
add on: I created an example application demonstrating basic authentication functionality, you may have a look here: digestive-functors-snap-auth-example enjoy!