Example #1
0
        private IActionResult SetSession(UserViewModel result)
        {
            var identity = new ClaimsIdentity(new[] {
                new Claim(ClaimTypes.Email, result.Email),
                new Claim(ClaimTypes.Role, result.RoleName)
            }, CookieAuthenticationDefaults.AuthenticationScheme);

            var principal = new ClaimsPrincipal(identity);

            HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);

            if (!string.IsNullOrEmpty(result.PasswordExpirayDate) && DateTime.Now.Date <= Convert.ToDateTime(result.PasswordExpirayDate))
            {
                //Handled if image url exist in db but not available physically
                string picpath = hostingEnviroment.WebRootPath + result.ProfilePic;
                if (!System.IO.File.Exists(picpath))
                {
                    string fName = $@"\ProfilePic\" + "Avatar.jpg";
                    result.ProfilePic = fName;
                }
                HttpContext.Session.Set <UserViewModel>(Constants.SessionKeyUserInfo, result);
                authHandler.LogActiveUsers(HttpContext.Session.Id, result);
                authHandler.UserActivity(result.UserId);
                return(GoAhead(result.RoleName, result.UserId));
            }
            else
            {
                return(View("CreateNewPassword"));
            }
        }