Posts

Showing posts from April, 2009

Adding Authentication to the Blog App

In the last post, we developed a very basic blog application using Happstack. Now that we have a simple application without an authentication mechanism, let's see how much effort it takes to add authentication using the Happstack-Auth module mentioned here . First let's make an outline of what needs to be done. We need the following pieces of functionality: Pages for login/registration Routines to handle the POSTed form data from the above A page to log the user out Blog posts should contain the name of the author Only authenticated users should be able to create new posts. The first thing we have to do is import the auth module. > import Happstack.Auth Let's start by looking at the first three bullets of functionaliy mentioned above. I'll implement the login/registration pages in pretty much the same way they were implemented in my old posts. A single login.html file will have a form for both registration and login. This suggests the following cod...

Basic Happstack Blog App

Happstack is improving, and my old blog posts on HAppS are now out of date. So we're in need of a bare-bones app to demonstrate functionality. I also wanted a simple app without authentication capability to demonstrate how to integrate Happstack-Auth into a project. Blog apps seem to be one of the canonical beginner's examples in the web framework world, so I thought that would be a good choice to start with. As usual, this post is literate haskell and should compile as Main.lhs. > {-# OPTIONS -fglasgow-exts #-} > {-# LANGUAGE TemplateHaskell , FlexibleInstances, > FlexibleContexts, UndecidableInstances, OverlappingInstances, > MultiParamTypeClasses, GeneralizedNewtypeDeriving #-} > > module Main where > > import Control.Concurrent > import Control.Monad > import Control.Monad.Reader > import Control.Monad.State (modify,put,get,gets,MonadState) > import Data.Generics hiding ((:+:)) > import Happstack.Serv...

A Standalone Auth Framework for Happstack

It's been awhile since my series of posts outlining some of the basic ideas behind the HAppS Haskell web framework (which is since been renamed Happstack ). Ever since I started developing it I envisioned a standalone library, perhaps shipped as a part of happstack, that would make it trivial for anyone to add robust authentication to their application. After doing some more work on Happs(tack) applications I've finally gotten around to working on the auth framework. I have created a github repository for the auth framework. It still needs a lot more work, but hopefully it will demonstrate some of the potential of Haskell and Happstack as a web development framework, and motivate some more improvement in this area. Comments, suggestions, or code contributions would be greatly apprectiated.