Exemplo n.º 1
0
        public void SignOut(SignOutOption signOutOption = SignOutOption.ValidLogout)
        {
            _serviceAuthentication.SignOut(signOutOption);
            var principal = (CustomPrincipal)Thread.CurrentPrincipal;

            HttpContext.User = principal;
        }
Exemplo n.º 2
0
        public void SignOut(SignOutOption signOutOption)
        {
            var identity = (CustomIdentity)Thread.CurrentPrincipal?.Identity;

            //       var cacheKeyProfile = CacheKeyOption.Profile + "-" + identity.UserId;

            var sessions = _repositorySession.Get().Where(e => e.Creator.Id == identity.UserId).ToList();

            if (sessions.Count > 0)
            {
                foreach (var session in sessions)
                {
                    _repositorySessionHistory.Add(new SessionHistory
                    {
                        Id                   = GuidHelper.NewGuid(),
                        Creator              = session.Creator,
                        CreationTime         = session.CreationTime,
                        LastModificationTime = DateTime.Now,
                        LogoutType           = signOutOption.ToString(),
                    }, true);

                    _repositorySession.Delete(session, true);
                }
            }

            // Kimlik nesnesi boşaltılıp yeniden oluşturuluyor
            identity = new CustomIdentity();
            identity.AddClaims(new[]
            {
                new Claim("UserId", Guid.Empty.ToString()),
                new Claim("Username", string.Empty),
                new Claim("Password", string.Empty),
                new Claim("FirstName", string.Empty),
                new Claim("LastName", string.Empty),
                new Claim("DisplayName", string.Empty),
                new Claim("Email", string.Empty),
                new Claim("LanguageId", Guid.Empty.ToString()),
                new Claim("IsAuthenticated", false.ToString()),
            });

            var principal = new CustomPrincipal(identity);

            // Thread geçerli kimlik bilgisi ayarlanıyor
            Thread.CurrentPrincipal = principal;
            //     _cacheService.Remove(cacheKeyProfile);
        }