Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Book example of Yesod.Auth.Email needs updating / needs further instructions #241

Open
benjamingoldstein opened this issue Oct 16, 2019 · 3 comments

Comments

@benjamingoldstein
Copy link
Contributor

Hi all.

I'm trying to get basic registration/login working on my main Yesod project, so I am trying to get the Yesod.Auth.Email example running on my machine first

https://www.yesodweb.com/book/authentication-and-authorization#authentication-and-authorization_email

I copied the current code from the book as-is into a new file Email.hs and ran:
stack exec runghc Email.hs

And I got

Email.hs:18:1: error:
    Could not find module ‘Network.Mail.Mime’
    Use -v to see a list of the files searched for.
   |
18 | import           Network.Mail.Mime
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Taking a first stab after googling, I ran stack install mime-mail which seemed to successfully install the library.

Now I get:

Email.hs:102:15: error: Not in scope: ‘partFilename’
    |
102 |             , partFilename = Nothing
    |               ^^^^^^^^^^^^

Has anyone else gotten the tutorial running? Am I missing some setup?

@benjamingoldstein
Copy link
Contributor Author

I found someone else had a crack at this:
https://github.com/ArthurVard/yesod-auth-examples
Diffing their code with the book's code, it seems that they used the tutorial, and they only added SES. This also doesn't compile, it seems out of date too but I got it down to the same error:

Email2.hs:98:15: error: Not in scope: ‘partFilename’
   |
98 |             , partFilename = Nothing
   |               ^^^^^^^^^^^^

So I think that it's either that a) this guy's code didn't work either or b) the world has moved on and some import has been moved / renamed since the book was written.

Can anyone tell me what I need to import to get this part of the book running?

I will do a pull request to fix up the book once I get it working.

@benjamingoldstein
Copy link
Contributor Author

I have found a number of other skeletons on this road, it seems that even if they got Yesod.Auth.Email working, getting custom registration/login forms working in Yesod is just too hard (that seems like a thing that anyone would want though?) They have often resorted to using AJAX (possibly from this example: https://github.com/yesodweb/yesod-cookbook/blob/master/cookbook/yesod-auth-json.md )

I just tried to compile this AJAX code as-is too, and I get the same error:

stack exec runghc Email3.hs 

Email3.hs:116:11: error: Not in scope: ‘partFilename’
    |
116 |         , partFilename = Nothing
    |           ^^^^^^^^^^^^

I think this Part data constructor is from import Mail.Network.Mime

Looking at the documentation for it: http://hackage.haskell.org/package/mime-mail-0.5.0/docs/Network-Mail-Mime.html

It looks like it has been updated since the book was written, because there is no longer a record accessor (I think that terminology is possibly incorrect) called partFilename but there is now something called partDisposition.

I can't find any examples of the new Mail.Network.Mime being used to learn from, so please chime in if this is obvious to you

@benjamingoldstein
Copy link
Contributor Author

I got it working! ✅

I had to update the book's example code to match the updated Mail.Network.Mime library.

diff of the Book's code against working code:

diff BookEmail.hs Email.hs 
102,103c102,103
<             , partFilename = Nothing
<             , partContent = Data.Text.Lazy.Encoding.encodeUtf8
---
>             , partDisposition = DefaultDisposition
>             , partContent = PartContent $ Data.Text.Lazy.Encoding.encodeUtf8
116,117c116,117
<             , partFilename = Nothing
<             , partContent = renderHtml
---
>             , partDisposition = DefaultDisposition
>             , partContent = PartContent $ renderHtml

I will see if I can edit this into the book content somehow, but I'll leave this open, as I may fail to figure it out / not have permission etc.

Now I just have to figure out how to get custom forms working!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant