예제 #1
0
        public IActionResult Search([FromQuery] Rep rep, [FromQuery] string isActive)
        {
            try
            {
                IEnumerable <Rep> reps = repManager.Find(x =>
                                                         x.Username == rep.Username &&
                                                         x.FirstName == rep.FirstName &&
                                                         x.LastName == rep.LastName);

                if (!string.IsNullOrWhiteSpace(isActive))
                {
                    bool isAct;
                    bool.TryParse(isActive, out isAct);

                    reps = reps.Where(x => x.IsActive == isAct);
                }

                return(Ok(reps));
            }
            catch (Exception ex)
            {
                logger.LogError($"Failed to find rep(s): {ex}");
                return(BadRequest(config["Error:Default"]));
            }
        }
예제 #2
0
        private async Task <SurveySecurityProfile> LogIn()
        {
            var securityProfile = new SurveySecurityProfile(UserName, config);

            if (securityProfile.Role == "NotAuthorized")
            {
                return(null);
            }

            string issuer = Environment.GetEnvironmentVariable("Domain");

            Rep rep = repManager.Find(x => x.Username == securityProfile.UserName).SingleOrDefault();

            var claims = new List <Claim> {
                new Claim("Username", securityProfile.UserName, ClaimValueTypes.String, issuer),
                new Claim(ClaimTypes.Role, securityProfile.Role, ClaimValueTypes.String, issuer),
                new Claim("RepId", Convert.ToString(rep?.RepId ?? 0), ClaimValueTypes.Integer),
                new Claim("UserType", Convert.ToString(securityProfile.UserType), ClaimValueTypes.Integer)
            };

            var claimsIdentity = new ClaimsIdentity(claims, "SuperSecureLogin");

            await HttpContext.SignInAsync(
                CookieAuthenticationDefaults.AuthenticationScheme,
                new ClaimsPrincipal(claimsIdentity),
                new AuthenticationProperties
            {
                ExpiresUtc   = DateTime.UtcNow.AddMinutes(20),
                IsPersistent = false,
                AllowRefresh = false
            });

            return(securityProfile);
        }