mule-deer-2013/JailBirdApp — pull request #2 by Absoludacris06 (2013-10-28 23:30:01+00:00)
Title: Added encryption for user 4-digit pin number and additional validations

Added the attr_encrypted gem to Gemfile. Updated user.rb model file to include new validations and methods for encrypting jailbird pin. Created API helper method to find user by encrypted jailbird pin and phone number. Created migration to encrypt pin column. Added initializer pin_key.rb to incorporate pin encryption key into ENV hash.

Order of operations for application integration:
1. Create a new file called pin_key.yaml in auth folder. This will be treated to client keys for Twilio API. If using Heroku, be sure to set this environment variable in the config.
2. Migrate DB to latest migration.

Using the attr_encrypted gem is kinda tricky. It overwrites the User model instance methods #jailbird_pin & #encrypted_jailbird_pin so that they no longer call the attribute associated with the database. Instead, these become separate encrypted and decrypted attributes only held in session (meaning they go away when between routes). Have to access & set actual database attributes by calling user_instance[:encrypted_jailbird_pin] (post-migration) or user_instance[:jailbird_pin] (pre-migration).