yesod

Lookup query parameters in Yesod

和自甴很熟 提交于 2021-02-18 10:56:52
问题 I just initialized a Yesod project (no database) using yesod init . My HomeR GET handler looks like this: getHomeR :: Handler Html getHomeR = do (formWidget, formEnctype) <- generateFormPost sampleForm let submission = Nothing :: Maybe (FileInfo, Text) handlerName = "getHomeR" :: Text defaultLayout $ do aDomId <- newIdent setTitle "Welcome To Yesod!" $(widgetFile "homepage") When using yesod devel , I can access the default homepage at http://localhost:3000/ . How can I modify the handler

Handling a collection of data in a Yesod Form

独自空忆成欢 提交于 2021-01-27 20:23:53
问题 Is it possible in Yesod to handle forms that contain a collection of data? I have a form that the user can add multiple people to, on the frontend it currently looks like this: { people.map((person, key) => ( <td> <input type="hidden" name={ `person[${key}][firstName]` } value={person.firstName} /> <input type="hidden" name={ `person[${key}][lastName]` } value={person.lastName} /> { person.firstName } { person.lastName } </td> )) } I then want to be able to translate that over to the backend

Yesod 1.2 CSRF protection

痞子三分冷 提交于 2020-08-07 10:31:53
问题 I'm confused about Yesod's CSRF protection, and how Yesod's forms work in general. It's my understanding that Yesod's form system uses a "token" which is passed into the HTML realization of the form as a hidden field. When the form is processed, the token is compared to one stored (or at least recreated) on the server. I'd like to track that down, because the CSRF protection is being triggered spuriously in my development environment, and I'd like to change my environment so the forms work

Why does this code work with Yesod.Persist's get404 but not getBy404?

天涯浪子 提交于 2020-02-25 05:53:27
问题 Let's say I have a table of dog names and breeds as follows: share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persist| Dog name Text breed Text UniqueDog name |] I have the following routes: mkYesod "DogApp" [parseRoutes| / RootR GET /dog/name/#Text DogNameR GET /dog/id/#DogId DogIdR GET |] And I'm trying to create a page that returns the breed of the dog given it's name. I can do this with the Id in the URL via the getDogIdR route just fine: getDogIdR :: DogId -> Handler RepHtml

Regular Expression on Yesod type Text

家住魔仙堡 提交于 2020-01-25 00:59:08
问题 Currently, I am changing my Text to String then using Text.Regex.Posix to do my matching. Is there a idiomatic and efficient way to do regular expression in Yesod? 回答1: Have you taken a look at the regex-tdfa-text package? It provides backend support for using the regex-base library with Text strings. 来源: https://stackoverflow.com/questions/31160216/regular-expression-on-yesod-type-text

Add nested property to returned record

不打扰是莪最后的温柔 提交于 2020-01-16 23:15:51
问题 I have a Yesod route handler that returns a JSON with the object { id: 1, title: "foo" content: "bar" } I would like to add a _links property with some metadata, that doesn't exist in on the Entity itself, e.g. { id: 1, title: "foo" content: "bar" _links: {self: http://localhost:3000/events/1} } How can I add the _links to the existing Entity record? Here's my handler: getEventR :: EventId -> Handler Value getEventR eid = do event <- runDB $ get404 eid render <- getUrlRender let renderedUrl =

Add nested property to returned record

霸气de小男生 提交于 2020-01-16 23:12:31
问题 I have a Yesod route handler that returns a JSON with the object { id: 1, title: "foo" content: "bar" } I would like to add a _links property with some metadata, that doesn't exist in on the Entity itself, e.g. { id: 1, title: "foo" content: "bar" _links: {self: http://localhost:3000/events/1} } How can I add the _links to the existing Entity record? Here's my handler: getEventR :: EventId -> Handler Value getEventR eid = do event <- runDB $ get404 eid render <- getUrlRender let renderedUrl =

Yesod/Persistent entity deriving Show

别说谁变了你拦得住时间么 提交于 2020-01-14 10:06:21
问题 In the Persistent chapter of the Yesod book, an example is given where this entity {-# LANGUAGE QuasiQuotes, TypeFamilies, GeneralizedNewtypeDeriving, TemplateHaskell, OverloadedStrings, GADTs #-} import Database.Persist import Database.Persist.TH import Database.Persist.Sqlite import Control.Monad.IO.Class (liftIO) mkPersist sqlSettings [persist| Person name String age Int deriving Show |] generates the code {-# LANGUAGE TypeFamilies, GeneralizedNewtypeDeriving, OverloadedStrings, GADTs #-}

Codifying presence/absence of authentication at type level

一曲冷凌霜 提交于 2020-01-11 04:42:08
问题 Context: I'm approaching Haskell from a standpoint of converting runtime errors to compile-time errors. My hypothesis is that this is possible if one can codify business logic within the program's types itself. I'm writing a Telegram bot, which should be accessible by users within my company. To achieve this "restriction", whenever someone starts chatting with the bot it will look up the chat_id in a table and check if a valid oauth_token exists. If not, the user will first be sent a link to

How to build Stack Yesod?

孤街浪徒 提交于 2020-01-07 06:49:46
问题 I've been trying to use stack to start a yesod-simple project, but nothing I do will build this project. I've looked into other similar stackoverflow questions but couldn't get this to work. Can some one help me figure out what I need to do to get started? Error > stack build Populated index cache. yesod-persistent-1.4.0.6: configure yesod-persistent-1.4.0.6: build yesod-persistent-1.4.0.6: copy/register yesod-form-1.4.9: configure yesod-form-1.4.9: build yesod-form-1.4.9: copy/register yesod