refactored user authentication in controllers and templates