controller

How to implement user authentication in a Play Framework application

Table of Contents1 - Resources2 - A custom user authentication action3 - Use that action in your controller methods4 - A sample form5 - Setting the user login cookie6 - Discussion

This past week I started working with the Play Framework (version 2.6), and this is a quick look at how to implement user authentication in a Play application. Specifically this blog post focuses on how to create a custom action so you can secure your Play controllers methods, where you’ll implement those methods using this new, custom action.

A Play Framework data entry form example

Table of Contents1 - Define the routes2 - Create a controller3 - Create the template/form4 - What the form looks like5 - Play form input helpers6 - Form resources

If you’d like an example of how to create a data entry form using the Play Framework v2.6, here’s a complete example.

A terrific Model View Controller (MVC) diagram

Every once in a while when something hits you, you really remember it; it stands out in your mind as an “Aha” moment. One of those moments for me was when I saw a particular “Model/View/Controller” (MVC) diagram, and the light bulb went on. This diagram made the MVC pattern very simple, and I’ve never forgotten it.

A list of Play Framework controller action results (result types)

When you’re writing Play Framework controller actions, you’re typically going to be returning a Play Results, with the most common result being Ok. However, your controller actions can return many different result types. This table shows some of the most common result types that you can use instead of Ok:

Sample Play Framework controller forms (form mappings)

Just some quick notes on Play Framework controller form field mappings ... I’ll add more here as I have more time, but right now this is a reference page for my Cato application.

1) The ResearchLink form from my “Finance” application:

Play Framework async controller method examples

If you want to write “async” Play Framework controller methods, I hope the following example code will help you get started. I’ll offer it here without much description today, other than to say that the list and add methods are written to work asynchronously by invoking Action.async and using a Scala Future:

How to print content-type, headers, and body to debug a Play Framework controller

There are times when you’re debugging a Play Framework controller that you’ll want to print certain information, such as the request content-type, headers, content body, and query string. As a quick example, the code below shows how to print this information from a Play Framework controller method: