Eddited login and register controller to be more modular and respond with JSON after ajax request