Convert the raw SQL queries to ActiveRecord.

Done for ease of further development and more practice. Still needs functionality for adding new users, and some more validations.