Пример #1
0
        public virtual void UpdateAuditFields()
        {
            NTContextModel contextModel = NTContext.Context;

            this.LastModifiedDate = DateTime.UtcNow;
            //this.LastModifiedUserID = contextModel.UserName;
        }
Пример #2
0
        public static async Task <ProfileModel> Get(string userName, SecurityRepository accountRepository)
        {
            int companyId = NTContext.Context.CompanyId;

            ProfileModel profile = await accountRepository.UserProfileGet(userName, companyId);

            // setting all the roles for admin roles
            if (profile.AdminRoles.Length > 0)
            {
                profile.AdminRoles = PageService.AdminRoles.Where(r => profile.AdminRoles.Contains(r.Key)).Select(r => r.Item).ToArray();
            }

            profile.SetMenu();

            // setting the claims on to the context
            NTContextModel model = new NTContextModel()
            {
                UserId    = profile.UserId,
                UserName  = profile.UserName,
                FirstName = profile.FirstName,
                LastName  = profile.LastName,
                CompanyId = profile.CompanyId
            };

            NTContext.Context = model;

            return(profile);
        }
Пример #3
0
        public async Task SetNTContext(HttpContext context)
        {
            var claims = context.User.Claims;

            string companyId = context.Request.Headers[SecurityConstants.HeaderCompanyId];

            companyId = companyId ?? claims.Where(c => c.Type == NTClaimTypes.CompanyId).Select(c => c.Value).FirstOrDefault();
            var userId = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier);

            if (userId is null)
            {
                await this.LoginDevEnvironment();
            }

            NTContextModel model = new NTContextModel()
            {
                UserId    = userId?.Value,
                UserName  = context.User.Identity.Name,
                FirstName = claims.First(c => c.Type == NTClaimTypes.FirstName).Value,
                LastName  = claims.First(c => c.Type == NTClaimTypes.LastName).Value,
                CompanyId = Convert.ToInt32(companyId ?? "0"),
            };

            // setting the Group CompanyId
            model.GroupCompanyId = PageService.CompanyClaims[model.CompanyId]?.ParentCompanyId ?? model.CompanyId;

            NTContext.Context = model;
        }
Пример #4
0
        public void SetNTContext(HttpContext context)
        {
            var claims = context.User.Claims;
            //string companyId = context.Request.Headers[ExtJwtClaimTypes.TenantName];
            //companyId = companyId ?? claims.Where(c => c.Type == ExtJwtClaimTypes.TenantName).Select(c => c.Value).FirstOrDefault();
            //string userName = context.User.Identity.Name;
            //string userId = claims.First(c => c.Type == ExtJwtClaimTypes.sub).Value;
            //string firstName = claims.First(c => c.Type == JwtClaimTypes.Name).Value;
            //string lastName = claims.First(c => c.Type == JwtClaimTypes.FamilyName).Value;
            //string tenantName = claims.First(c => c.Type == ExtJwtClaimTypes.TenantName).Value;
            //int tenantId = Convert.ToInt32(claims.First(c => c.Type == ExtJwtClaimTypes.TenantId).Value);



            //string userId = claims.First(c => c.Type == ExtJwtClaimTypes.sub).Value;
            //string userName = claims.First(c => c.Type == ExtJwtClaimTypes.given_name).Value;
            //string userEmail = claims.First(c => c.Type == ExtJwtClaimTypes.email).Value;
            //string identityUrl = claims.First(c => c.Type == ExtJwtClaimTypes.iss).Value;
            //string identityUserToken = context.GetTokenAsync("access_token").Result;

            NTContextModel model = new NTContextModel()
            {
                UserId            = claims.First(c => c.Type == ExtJwtClaimTypes.sub).Value,
                UserName          = claims.First(c => c.Type == ExtJwtClaimTypes.given_name).Value,
                UserEmail         = claims.First(c => c.Type == ExtJwtClaimTypes.email).Value,
                IdentityUrl       = claims.First(c => c.Type == ExtJwtClaimTypes.iss).Value,
                IdentityUserToken = context.GetTokenAsync("access_token").Result,
            };

            NTContext.Context = model;
        }
Пример #5
0
        public void SetNTContext(HttpContext context)
        {
            var    claims    = context.User.Claims;
            string companyId = context.Request.Headers[ExtJwtClaimTypes.TenantName];

            companyId = companyId ?? claims.Where(c => c.Type == ExtJwtClaimTypes.TenantName).Select(c => c.Value).FirstOrDefault();



            string userName   = context.User.Identity.Name;
            string userId     = claims.First(c => c.Type == JwtClaimTypes.Id).Value;
            string firstName  = claims.First(c => c.Type == JwtClaimTypes.Name).Value;
            string lastName   = claims.First(c => c.Type == JwtClaimTypes.FamilyName).Value;
            string tenantName = claims.First(c => c.Type == ExtJwtClaimTypes.TenantName).Value;
            int    tenantId   = Convert.ToInt32(claims.First(c => c.Type == ExtJwtClaimTypes.TenantId).Value);

            NTContextModel model = new NTContextModel()
            {
                UserId     = userId,
                UserName   = userName,
                FirstName  = firstName,
                LastName   = lastName,
                TenantId   = tenantId,
                TenantName = tenantName,
            };

            // setting the Group CompanyId
            //model.GroupCompanyId = PageService.CompanyClaims[model.CompanyId]?.ParentCompanyId ?? model.CompanyId;

            NTContext.Context = model;
        }
Пример #6
0
        public BaseEntity()
        {
            NTContextModel contextModel = NTContext.Context;

            if (contextModel != null)
            {
                this.CreatedUserId      = contextModel.UserName;
                this.LastModifiedUserId = contextModel.UserName;
                this.CompanyId          = contextModel.CompanyId;
            }

            this.CreatedDate      = DateTime.UtcNow;
            this.LastModifiedDate = DateTime.UtcNow;
            this.DeletedInd       = false;
        }
Пример #7
0
        public static async Task <UserProfileModel> Get(string userName, SecurityRepository accountRepository)
        {
            UserProfileModel profile;
            string           profileContextName = "ProfileContextObject";

            if (NTContext.HttpContext.Items[profileContextName] == null)
            {
                int companyId = NTContext.Context.CompanyId;
                profile = await accountRepository.UserProfileGet(userName, companyId);

                // setting all the roles for admin roles
                if (profile.AdminRoles.Count > 0)
                {
                    profile.AdminRoles = PageService.AdminRoles.Where(r => profile.AdminRoles.Contains(r.Key)).Select(r => r.Item).ToList();
                }

                profile.SetMenu();

                // setting the claims on to the context
                NTContextModel model = new NTContextModel()
                {
                    UserId    = profile.UserId,
                    UserName  = profile.UserName,
                    FirstName = profile.FirstName,
                    LastName  = profile.LastName,
                    CompanyId = profile.CompanyId,
                };
                NTContext.Context = model;

                NTContext.HttpContext.Items[profileContextName] = profile;
            }
            else
            {
                profile = (UserProfileModel)NTContext.HttpContext.Items[profileContextName];
            }

            return(profile);
        }
Пример #8
0
 public BaseRepository()
 {
     this.context = NTContext.Context;
 }
Пример #9
0
 public BaseEntity()
 {
     NTContextModel contextModel = NTContext.Context;
 }