Can you just use the login_required decorator instead of these lines?