//[RequiresPermission(Permission.Login, Permission.NewUserRegistration)]


        public virtual IActionResult UsersCurrentGet()
        {
            SiteMinderAuthOptions siteMinderAuthOptions = new SiteMinderAuthOptions();

            ViewModels.User user = new ViewModels.User();

            // determine if we are a new registrant.
            string       temp         = _httpContextAccessor.HttpContext.Session.GetString("UserSettings");
            UserSettings userSettings = JsonConvert.DeserializeObject <UserSettings>(temp);

            user.id           = userSettings.UserId;
            user.contactid    = userSettings.ContactId;
            user.accountid    = userSettings.AccountId;
            user.businessname = userSettings.BusinessLegalName;
            user.name         = userSettings.UserDisplayName;
            user.UserType     = userSettings.UserType;

            if (userSettings.IsNewUserRegistration)
            {
                user.isNewUser = true;
                // get details from the headers.


                user.lastname  = DynamicsExtensions.GetLastName(user.name);
                user.firstname = DynamicsExtensions.GetFirstName(user.name);
                user.accountid = userSettings.AccountId;

                string siteminderBusinessGuid = _httpContextAccessor.HttpContext.Request.Headers[siteMinderAuthOptions.SiteMinderBusinessGuidKey];
                string siteminderUserGuid     = _httpContextAccessor.HttpContext.Request.Headers[siteMinderAuthOptions.SiteMinderUserGuidKey];

                user.contactid             = string.IsNullOrEmpty(siteminderUserGuid) ? userSettings.ContactId : siteminderUserGuid;
                user.accountid             = string.IsNullOrEmpty(siteminderBusinessGuid) ? userSettings.AccountId : siteminderBusinessGuid;
                user.isEligibilityRequired = true;
            }
            else
            {
                user.lastname              = userSettings.AuthenticatedUser.Surname;
                user.firstname             = userSettings.AuthenticatedUser.GivenName;
                user.email                 = userSettings.AuthenticatedUser.Email;
                user.isNewUser             = false;
                user.isEligibilityRequired = EligibilityController.IsEligibilityCheckRequired(user.accountid, _configuration, _dynamicsClient);
            }


            return(new JsonResult(user));
        }
        //[RequiresPermission(Permission.Login, Permission.NewUserRegistration)]


        public virtual IActionResult UsersCurrentGet()
        {
            SiteMinderAuthOptions siteMinderAuthOptions = new SiteMinderAuthOptions();

            ViewModels.User user = new ViewModels.User();

            // determine if we are a new registrant.

            UserSettings userSettings = UserSettings.CreateFromHttpContext(_httpContextAccessor);

            user.id           = userSettings.UserId;
            user.contactid    = userSettings.ContactId;
            user.accountid    = userSettings.AccountId;
            user.businessname = userSettings.BusinessLegalName;
            user.name         = userSettings.UserDisplayName;
            user.UserType     = userSettings.UserType;

            // if Authenticated User is null, try and fetch it.

            if (userSettings.AuthenticatedUser == null)
            {
                try
                {
                    userSettings.AuthenticatedUser = _dynamicsClient.GetActiveUserBySmGuid(userSettings.SiteMinderGuid);
                    if (userSettings.AuthenticatedUser == null)
                    {
                        userSettings.IsNewUserRegistration = true;
                    }
                }
                catch (Exception)
                {
                    userSettings.IsNewUserRegistration = true;
                }
            }

            if (userSettings.IsNewUserRegistration)
            {
                user.isNewUser = true;
                // get details from the headers.

                user.lastname  = user.name.GetLastName();
                user.firstname = user.name.GetFirstName();
                user.accountid = userSettings.AccountId;

                string siteminderBusinessGuid = _httpContextAccessor.HttpContext.Request.Headers[siteMinderAuthOptions.SiteMinderBusinessGuidKey];
                string siteminderUserGuid     = _httpContextAccessor.HttpContext.Request.Headers[siteMinderAuthOptions.SiteMinderUserGuidKey];

                user.contactid = string.IsNullOrEmpty(siteminderUserGuid) ? userSettings.ContactId : siteminderUserGuid;
                // handle Basic BCeID
                if (string.IsNullOrEmpty(user.contactid))
                {
                    user.contactid = userSettings.SiteMinderGuid;
                }

                user.accountid             = string.IsNullOrEmpty(siteminderBusinessGuid) ? userSettings.AccountId : siteminderBusinessGuid;
                user.isEligibilityRequired = true;
            }
            else
            {
                user.lastname  = userSettings.AuthenticatedUser.Surname;
                user.firstname = userSettings.AuthenticatedUser.GivenName;
                user.email     = userSettings.AuthenticatedUser.Email;
                user.isNewUser = false;
                if (!string.IsNullOrEmpty(user.accountid))
                {
                    user.isEligibilityRequired  = EligibilityController.IsEligibilityCheckRequired(user.accountid, _configuration, _dynamicsClient);
                    user.isPoliceRepresentative = _dynamicsClient.IsAccountSepPoliceRepresentative(user.accountid, _configuration);
                }
            }


            return(new JsonResult(user));
        }