thedjpetersen/subway — pull request #299 by hermansc (2014-02-16 23:05:30+00:00)
Title: Adds cookie based login, also called "remember me"-functionality.

This commit fixes issue #284 by adding cookies/authentication tokens at the
client side and validating these in the DB. When a user either registers or
logs in, without already having a cookie, a sha1-hash is generated using the
username and a secret key. This hash is stored in a DB-table calles 'Session'
and client side using the jquery-cookie plugin. When closing and opening the
application again we check if the users have a 'auth_token' in their cookies,
if this is the case we check its validity in the DB. If everything is OK, we
'jump through the hoops' and sets the user as logged in, restores his/hers
connections and render the chat_application. If it is not valid we delete the
cookie at the client and render the overview page.

As I've never actually implemented a cookie-based login system using javascript
before, I do not know if this solution is optimal and I'm more than happy to
discuss alternative approaches or restructure the code.