Twitter Has News for You

News is shared all over the internet today. Some of it is accurate and some of it isn’t. With the many different apps around today, blogs and news outlets choosing where to get your news may be…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




A Newsletter Sending System Code Challenge

A 1,000 email test run

I was tasked with a code challenge to create an Elixir/Phoenix app that would be a newsletter sending system. The requirements were simple and I had 48 hours to complete it. I lost a bit of time on the first day which caused me to cut some corners and not use TDD (tsk tsk). I had a deadline and would not miss it.

It was a great opportunity to build another app with Elixir and Phoenix. I learned more about changesets while trying to update users in iex, dove deeper into writing tests, and found that I need to learn a lot more about async and parallel tasks in Elixir. It is always great to learn more while doing.

If you have any suggestions of how I can improve my code, please let me know!

What it should do:

Bonus points if:

Although it was not specified, I ignored how easy it would be to capture email addresses and send a newsletter through any of the number of systems available. SendGrid is an example of one and I utilized their service for sending emails from within the app. The capturing of emails and sending of the newsletter was all handled in the app.

The first task was for a visitor to the site to see a form requesting their email address. It would have been easy to create a simple form to grab the email address and add it to the database. However, I was looking ahead to being able to send an email to confirm the subscription. It seemed to me the easiest way would be to use an authentication system.

When I first ran the Coherence install, I ended up with a user module and migration that looked like this:

After spending way too much time on it, I decided to keep in the password field and much like the name field I kept, set a default value in the migration and schema. This of course also failed because of some of the same reasons as above. There were things Coherence was doing that I did not quite understand.

I eventually decided that I needed to get moving on to the next step. I started passing in a password using a hidden form field as a temporary measure. A terrible approach but sufficient for now until I get the rest of the app finished. Make things work then make things better.

One of the bonus points was an email being sent out to confirm a subscription. Coherence has this baked in and was pretty easy to follow their docs and implement. Putting my app on Heroku allows for a free SendGrid account that allows for 12,000 sent emails a month. I will later make use of a lot of those to test things out. Coherence had instructions for setting up a SendGrid adapter and making sure confirmation emails were going out.

Now, I need to have an admin be able to send out a newsletter to all the subscribers. One problem here is all my users have the same fake password that is passed in by the hidden form field. Anyone that would have inspected the source of the page could see it and use the password to log in and send out emails. That is not something we want.

First step I took was adding a role to all of the users. It would default to subscriber and the admin would have to be changed by using iex to get into the database. Not something you would want in a production app but good enough for the purpose of this code challenge. I was able to add a role and set the default easily enough by tweaking the migration and user.ex to add the extra field.

I signed up for an account with the address I would use as my admin and clicked the email confirmation link to confirm the account. I used iex to update the role to admin and created a page only accessible to those whose role was admin. This would bounce any user who managed to get a hold of their hidden input field password.

The app is not perfect by any means. I would have liked to have the newsletter be able to be scheduled as per one of the bonus points. I also would have liked to have a few more tests for things like invalid data with the signups and log ins.

As I mentioned before, I really want to dive deeper into speeding up the sending of the newsletter. Receiving the confirmation flash message should be basically instant after I click send. No reason it should take five seconds.

I look forward to learning more about it.

Add a comment

Related posts:

Why Study Software Engineering?

The exact same question I was asking myself 8 years ago… I knew I was really into engineering and technology so the answer was quite simple back then: Sure, why not? The truth is… At that moment I…

10 Web Developer Portfolio Tips

Over the course of my career, I’ve seen a lot of developer portfolio sites. I’ve had my own, and I’ve reviewed at least 50 sites on behalf of others. I’ve seen some truly great portfolios… and I’ve…

Week 14

This week I was back to class and I am now blessed with a mountain of readings I have to do at the time of writing. This week was good in continuing prototyping with the glasses. Chris and I made the…