示例#1
0
        //ToDo: Need to update Populating the AppContextUser.
        internal static async Task <bool> InitSessionContext()
        {
            var claimsPrincipal = Thread.CurrentPrincipal
                                  as ClaimsPrincipal;

            var identity = claimsPrincipal?.Identity
                           as ClaimsIdentity;

            var memberRole = claimsPrincipal?.Claims.FirstOrDefault(
                x => x.Type == "role");

            if (memberRole?.Value != null)
            {
                if (memberRole?.Value == "Primary Member")
                {
                    if (SignOutIdentity())
                    {
                        ChallengeIdentity();
                    }
                    return(false);
                }
            }

            var claimRID = claimsPrincipal?.Claims.FirstOrDefault(
                x => x.Type == "RID");

            if (claimRID?.Value != null)
            {
                await Instance.LoadAuthenticateUser(
                    Convert.ToInt64(claimRID?.Value));

                if (!Instance.IsAuthenticated || !string.IsNullOrEmpty(
                        Instance.AuthTokenJsonString))
                {
                    return(false);
                }

                var authPayload = new LG.Owin.Security.Models.IdentityUserPractioner()
                {
                    AuthGuid        = Guid.NewGuid(),
                    RolodexItemID   = Instance.RolodexItemID,
                    DateCreated     = DateTime.Now,
                    IsAuthenticated = true,
                    DateExpiry      = DateTime.Now.AddMinutes(15),
                    Name            = new LG.Owin.Security.Models.NameEntity()
                    {
                        FirstName   = Instance.Info.MedicalPractitioner.PersonInfo.FName,
                        LastName    = Instance.Info.MedicalPractitioner.PersonInfo.LName,
                        PrintedName = Instance.Info.MedicalPractitioner.PrintedName
                    }
                };

                Instance.AuthTokenJsonString
                    = Newtonsoft.Json.JsonConvert.SerializeObject(authPayload);

                var item = new HttpCookie("PortalID")
                {
                    Value     = "Doctors",
                    Expires   = DateTime.Now.AddDays(1),
                    Shareable = false,
                    HttpOnly  = false,
                    Secure    = true
                };

                var item2 = new HttpCookie("IsAuthenticatedCookie")
                {
                    Values =
                    {
                        {
                            "A", "true"
                        },
                        {
                            "R", Instance.RolodexItemID.ToString()
                        },
                        {
                            "P", "DOCTOR"
                        }
                    },
                    Expires   = DateTime.Now.AddDays(1),
                    Shareable = false,
                    HttpOnly  = false,
                    Secure    = true
                };

                var cookie = new Cookie();
                HttpContext.Current.Response.Cookies.Add(item);
                HttpContext.Current.Response.Cookies.Add(item2);

                HttpContext.Current.Response.Redirect(
                    "Default");
                return(true);
            }
            else
            {
                return(false);
            }
            return(true);
        }
        //ToDo: Need to update Populating the AppContextUser.
        internal static async Task<bool> InitSessionContext()
        {

            var claimsPrincipal = Thread.CurrentPrincipal
                as ClaimsPrincipal;

            var identity = claimsPrincipal?.Identity
                as ClaimsIdentity;

            var memberRole = claimsPrincipal?.Claims.FirstOrDefault(
                x => x.Type == "role");

            if (memberRole?.Value != null)
            {
                if (memberRole?.Value == "Primary Member")
                {
                    if (SignOutIdentity())
                    {
                        ChallengeIdentity();
                    }
                    return false;
                }
            }

            var claimRID = claimsPrincipal?.Claims.FirstOrDefault(
              x => x.Type == "RID");

            if (claimRID?.Value != null)
            {
                await Instance.LoadAuthenticateUser(
                    Convert.ToInt64(claimRID?.Value));

                if (!Instance.IsAuthenticated || !string.IsNullOrEmpty(
                    Instance.AuthTokenJsonString)) return false;

                var authPayload = new LG.Owin.Security.Models.IdentityUserPractioner()
                {
                    AuthGuid = Guid.NewGuid(),
                    RolodexItemID = Instance.RolodexItemID,
                    DateCreated = DateTime.Now,
                    IsAuthenticated = true,
                    DateExpiry = DateTime.Now.AddMinutes(15),
                    Name = new LG.Owin.Security.Models.NameEntity()
                    {
                        FirstName = Instance.Info.MedicalPractitioner.PersonInfo.FName,
                        LastName = Instance.Info.MedicalPractitioner.PersonInfo.LName,
                        PrintedName = Instance.Info.MedicalPractitioner.PrintedName
                    }
                };

                Instance.AuthTokenJsonString
                    = Newtonsoft.Json.JsonConvert.SerializeObject(authPayload);

                var item = new HttpCookie("PortalID")
                {
                    Value = "Doctors",
                    Expires = DateTime.Now.AddDays(1),
                    Shareable = false,
                    HttpOnly = false,
                    Secure = true
                };

                var item2 = new HttpCookie("IsAuthenticatedCookie")
                {
                    Values = {
                        {
                            "A", "true"
                        },
                        {
                            "R", Instance.RolodexItemID.ToString()
                        },
                        {
                            "P", "DOCTOR"
                        }
                    },
                    Expires = DateTime.Now.AddDays(1),
                    Shareable = false,
                    HttpOnly = false,
                    Secure = true
                };

                var cookie = new Cookie();
                HttpContext.Current.Response.Cookies.Add(item);
                HttpContext.Current.Response.Cookies.Add(item2);

                HttpContext.Current.Response.Redirect(
                    "Default");
                return true;
            }
            else
            {
                return false;
            }
            return true;
        }