Move long lambda in separate function

The GetAllGroups lambda is very long and need to add somemore stuff for
hostconsole work hence moving it in the separate function.

Tested: Created user.
+ curl -k -X POST https://${bmc}/redfish/v1/AccountService/Accounts \
 -d '{"UserName": "user99", "Password": "0penBmc0", "RoleId": "Operator"}'
{
  "@Message.ExtendedInfo": [
    {
      "@odata.type": "#Message.v1_1_1.Message",
      "Message": "The resource has been created successfully.",
      "MessageArgs": [],
      "MessageId": "Base.1.13.0.Created",
      "MessageSeverity": "OK",
      "Resolution": "None."
    }
  ]
}

Change-Id: If62fa803217e43bdecca7965d16c98d852f0b5be
Signed-off-by: Ninad Palsule <ninadpalsule@us.ibm.com>
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index 8a68aae..b4c9205 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -1594,6 +1594,68 @@
         "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
 }
 
+inline void processAfterCreateUser(
+    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+    const std::string& username, const std::string& password,
+    const boost::system::error_code& ec, sdbusplus::message_t& m)
+{
+    if (ec)
+    {
+        userErrorMessageHandler(m.get_error(), asyncResp, username, "");
+        return;
+    }
+
+    if (pamUpdatePassword(username, password) != PAM_SUCCESS)
+    {
+        // At this point we have a user that's been
+        // created, but the password set
+        // failed.Something is wrong, so delete the user
+        // that we've already created
+        sdbusplus::message::object_path tempObjPath(rootUserDbusPath);
+        tempObjPath /= username;
+        const std::string userPath(tempObjPath);
+
+        crow::connections::systemBus->async_method_call(
+            [asyncResp, password](const boost::system::error_code& ec3) {
+            if (ec3)
+            {
+                messages::internalError(asyncResp->res);
+                return;
+            }
+
+            // If password is invalid
+            messages::propertyValueFormatError(asyncResp->res, password,
+                                               "Password");
+            },
+            "xyz.openbmc_project.User.Manager", userPath,
+            "xyz.openbmc_project.Object.Delete", "Delete");
+
+        BMCWEB_LOG_ERROR << "pamUpdatePassword Failed";
+        return;
+    }
+
+    messages::created(asyncResp->res);
+    asyncResp->res.addHeader("Location",
+                             "/redfish/v1/AccountService/Accounts/" + username);
+}
+
+inline void processAfterGetAllGroups(
+    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+    const std::string& username, const std::string& password,
+    const std::optional<std::string>& roleId, std::optional<bool> enabled,
+    const std::vector<std::string>& allGroupsList)
+
+{
+    crow::connections::systemBus->async_method_call(
+        [asyncResp, username, password](const boost::system::error_code& ec2,
+                                        sdbusplus::message_t& m) {
+        processAfterCreateUser(asyncResp, username, password, ec2, m);
+        },
+        "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
+        "xyz.openbmc_project.User.Manager", "CreateUser", username,
+        allGroupsList, *roleId, *enabled);
+}
+
 inline void handleAccountCollectionPost(
     App& app, const crow::Request& req,
     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
@@ -1642,52 +1704,8 @@
             return;
         }
 
-        crow::connections::systemBus->async_method_call(
-            [asyncResp, username, password](
-                const boost::system::error_code& ec2, sdbusplus::message_t& m) {
-            if (ec2)
-            {
-                userErrorMessageHandler(m.get_error(), asyncResp, username, "");
-                return;
-            }
-
-            if (pamUpdatePassword(username, password) != PAM_SUCCESS)
-            {
-                // At this point we have a user that's been
-                // created, but the password set
-                // failed.Something is wrong, so delete the user
-                // that we've already created
-                sdbusplus::message::object_path tempObjPath(rootUserDbusPath);
-                tempObjPath /= username;
-                const std::string userPath(tempObjPath);
-
-                crow::connections::systemBus->async_method_call(
-                    [asyncResp,
-                     password](const boost::system::error_code& ec3) {
-                    if (ec3)
-                    {
-                        messages::internalError(asyncResp->res);
-                        return;
-                    }
-
-                    // If password is invalid
-                    messages::propertyValueFormatError(asyncResp->res, password,
-                                                       "Password");
-                    },
-                    "xyz.openbmc_project.User.Manager", userPath,
-                    "xyz.openbmc_project.Object.Delete", "Delete");
-
-                BMCWEB_LOG_ERROR << "pamUpdatePassword Failed";
-                return;
-            }
-
-            messages::created(asyncResp->res);
-            asyncResp->res.addHeader(
-                "Location", "/redfish/v1/AccountService/Accounts/" + username);
-            },
-            "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
-            "xyz.openbmc_project.User.Manager", "CreateUser", username,
-            allGroupsList, *roleId, *enabled);
+        processAfterGetAllGroups(asyncResp, username, password, roleId, enabled,
+                                 allGroupsList);
         });
 }