Chapter 8. User Management

Managing user accounts is one of the main features of any real application. We would like Birdy users to sign up with their email first, and then be able to sign in.

To create an account, the user will sign up with his email and create his username and password. He will then receive an account activation link via email. After he activates his account, the user will be able to sign in and start posting messages.

Usually, the “Sign in” link for accounts is placed in the top-right corner of the top bar, so that’s what we’ll do here. We will place the “Sign up” button in the center of the home page. Both links will activate a modal window that contains the login or registration form.

In this chapter you will:

  • Create a modal window for registration and learn how to quickly handle Bootstrap components
  • Create a registration form and learn how to handle forms
  • Create new user accounts
  • Send registration code via email and learn how to send emails
  • Handle account activation links and learn how to handle data encoded in URLs
  • Track a logged-in user throughout the site and learn how to handle user-associated data

Setting Up the View

Before we jump into proper login/registration features, let’s take a moment to slightly customize the default view to better suit the needs of our application.

First, take a look at the code of the view part of the application, as it was generated by opa create. You will find it in src/view/page.opa and it should look as follows:

module Page ...

Get Opa: Up and Running now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.