예제 #1
0
        // POST: Registration/ValidateHomeMailingAddress
        //[HttpPost]
        //public ActionResult ValidateHomeMailingAddress(MailingAddressViewModel mailingAddress)
        //{
        //    return Json(CheckHomeMailingAddress(mailingAddress));
        //}

        //// POST: Registration/ValidateWorkMailingAddress
        //[HttpPost]
        //public ActionResult ValidateWorkMailingAddress(MailingAddressViewModel mailingAddress)
        //{
        //    return Json(CheckWorkMailingAddress(mailingAddress));
        //}

        //private MailingAddressEnvelope CheckHomeMailingAddress(MailingAddressViewModel mailingAddress)
        //{
        //    var targetMailingAddress = mailingAddress;
        //    var isKnownAddress = false;
        //    if (mailingAddress.Street1.ToLower().Contains("123 main st") &&
        //        string.IsNullOrEmpty(mailingAddress.Street2) &&
        //        string.IsNullOrEmpty(mailingAddress.Street3) &&
        //        mailingAddress.City.ToLower().Contains("small town") &&
        //        mailingAddress.State.ToUpper().Equals("NC") &&
        //        mailingAddress.ZIP.Contains("55555") &&
        //        string.IsNullOrEmpty(mailingAddress.Province) &&
        //        mailingAddress.Country.ToLower().Equals("united states"))
        //    {
        //        targetMailingAddress = new MailingAddressViewModel()
        //        {
        //            Type = "Home",
        //            Street1 = "123 Main St",
        //            City = "Small Town",
        //            State = "NC",
        //            ZIP = "55555-5555",
        //            Country = "United States"
        //        };
        //        isKnownAddress = true;
        //    }
        //    return new MailingAddressEnvelope()
        //    {
        //        MailingAddress = targetMailingAddress,
        //        IsKnownAddress = isKnownAddress
        //    };
        //}


        //private MailingAddressEnvelope CheckWorkMailingAddress(MailingAddressViewModel mailingAddress)
        //{
        //    var targetMailingAddress = mailingAddress;
        //    var isKnownAddress = false;
        //    if (mailingAddress.Street1.ToLower().Contains("220 leigh farm") &&
        //        string.IsNullOrEmpty(mailingAddress.Street2) &&
        //        string.IsNullOrEmpty(mailingAddress.Street3) &&
        //        mailingAddress.City.ToLower().Contains("durham") &&
        //        mailingAddress.State.ToUpper().Equals("NC") &&
        //        mailingAddress.ZIP.Contains("27707") &&
        //        string.IsNullOrEmpty(mailingAddress.Province) &&
        //        mailingAddress.Country.ToLower().Equals("united states"))
        //    {
        //        targetMailingAddress = new MailingAddressViewModel()
        //        {
        //            Street1 = "220 Leigh Farm Rd",
        //            City = "Durham",
        //            State = "NC",
        //            ZIP = "27707-8110"
        //        };
        //        isKnownAddress = true;
        //    }
        //    return new MailingAddressEnvelope()
        //    {
        //        MailingAddress = targetMailingAddress,
        //        IsKnownAddress = isKnownAddress
        //    };
        //}


        private CustomUser VerifyIdentity(RegistrationViewModel registration)
        {
            logger.Debug("VerifyIdentity");

            //primary search check registration email verses okta login
            CustomUser customUser = null;

            customUser = oktaUserMgmt.GetCustomUser(registration.Email);
            if (customUser != null && customUser.Id != null)
            {
                //if user exists
                //return user info
                return(customUser);
            }
            else
            {
                //note: more sophistcated logic cann be inserted to check for duplicates
                //ie lastname, primaryPhone, mailing address, etc
                //use extended search criteria to search for possible duplicate user
                System.Text.StringBuilder buildFilter = null;
                // build buildFilter
                //pagelimit cannot exceed 200
                buildFilter = new System.Text.StringBuilder();
                //buildFilter.Append("created lt \"" + formatTime + "\"");
                //buildFilter.Append("status eq \"ACTIVE\"");
                buildFilter.Append("profile.customId eq \"" + registration.customId + "\"");

                //buildFilter.Append("&limit=20");

                PagedResults <CustomUser> pagedCustomUser;
                //CustomUserProfile customUserProfile = new CustomUserProfile();
                Uri  myNextPage     = null;
                bool isThisLastPage = true;
                do
                {
                    if (isThisLastPage)
                    {
                        pagedCustomUser = oktaUserMgmt.ListCustomUsersExtended(searchType: "search", criteria: buildFilter.ToString());
                    }
                    else
                    {
                        pagedCustomUser = oktaUserMgmt.ListCustomUsersExtended(searchType: "search", criteria: buildFilter.ToString(), nextPage: myNextPage);
                    }


                    isThisLastPage = pagedCustomUser.IsLastPage;
                    myNextPage     = pagedCustomUser.NextPage;
                    int rspCount = pagedCustomUser.Results.Count;
                    foreach (var customUser1 in pagedCustomUser.Results)
                    {
                        logger.Debug("oktaId= " + customUser1.Id + " customId= " + customUser1.Profile.customId + " lastName= " + customUser1.Profile.LastName);
                    }
                    if (rspCount == 1)
                    {
                        logger.Debug("found single user ");
                        customUser = pagedCustomUser.Results[0];
                        return(customUser);
                    }
                    else if (rspCount > 1)
                    {
                        logger.Error("found " + rspCount.ToString() + " users matching criteria");
                        //picking first member of list, since any return more than empty processes the same
                        customUser = pagedCustomUser.Results[0];
                        return(customUser);
                    }
                    else
                    {
                        customUser = null;
                        return(customUser);
                    }
                } while (!isThisLastPage);
            }//end if else
        }
        public ActionResult CheckForUser(ForgotUsernameViewModel forgotUsernameViewModel)
        {
            logger.Debug("CheckForUser");
            CustomUser customUser = null;

            ViewBag.IsNotFound = false;
            if (!ModelState.IsValid)
            {
                return(View("Index", forgotUsernameViewModel));
            }

            //need to check against custom user profile since aicpaId is part of criteria
            //ajc debug
            //this implementation contains support for multiple return users
            //for now, returned records greater than 1 is considered an error

            System.Text.StringBuilder buildFilter = null;
            // build buildFilter
            //pagelimit cannot exceed 200
            buildFilter = new System.Text.StringBuilder();
            buildFilter.Append("status eq \"ACTIVE\" and ");
            buildFilter.Append("profile.lastName eq \"" + forgotUsernameViewModel.LastName + "\" and ");
            buildFilter.Append("profile.policyNumber eq \"" + forgotUsernameViewModel.policyNumber + "\"");
            //buildFilter.Append("&limit=8");

            PagedResults <CustomUser> pagedCustomUser;
            //CustomUserProfile customUserProfile = new CustomUserProfile();
            Uri  myNextPage     = null;
            bool isThisLastPage = true;

            do
            {
                if (isThisLastPage)
                {
                    pagedCustomUser = oktaUserMgmt.ListCustomUsersExtended(searchType: "search", criteria: buildFilter.ToString());
                }
                else
                {
                    pagedCustomUser = oktaUserMgmt.ListCustomUsersExtended(searchType: "search", criteria: buildFilter.ToString(), nextPage: myNextPage);
                }


                isThisLastPage = pagedCustomUser.IsLastPage;
                myNextPage     = pagedCustomUser.NextPage;
                int rspCount = pagedCustomUser.Results.Count;
                foreach (var customUser1 in pagedCustomUser.Results)
                {
                    logger.Debug("oktaId= " + customUser1.Id + " customId= " + customUser1.Profile.customId + " lastName= " + customUser1.Profile.LastName);
                }
                if (rspCount == 1)
                {
                    logger.Debug("successful; found single user ");
                    //send email with userName/email
                    customUser            = pagedCustomUser.Results[0];
                    TempData["firstName"] = customUser.Profile.FirstName;
                    TempData["userName"]  = customUser.Profile.Login;
                    SendEmail(customUser);
                    var routeValues = new RouteValueDictionary();
                    routeValues.Add("login", pagedCustomUser.Results[0].Profile.Login);
                    routeValues.Add("email", pagedCustomUser.Results[0].Profile.Email);
                    return(RedirectToAction("UserFound", routeValues));
                }
                else
                {
                    logger.Error("Error found " + rspCount.ToString() + " users matching criteria");
                    return(RedirectToAction("UserNOTFound"));
                }
            } while (!isThisLastPage);
        }