コード例 #1
0
        public ActionResult Login(UserLoginViewModel userModel)
        {
            if (!ModelState.IsValid)
            { // re-render the view when validation failed.
                return(View("UserLogin", userModel));
            }
            var user = userService.LoginUser(new UserDTO()
            {
                EMail = userModel.Email, Password = userModel.Password
            });

            if (user != null)
            {
                user.Role = roleService.GetById((int)user.RoleID);
                var userClaims = new List <Claim>()
                {
                    new Claim("UserDTO", OOPSConvert.OOPSJsonSerialize(user))
                };

                var userIdentity = new ClaimsIdentity(userClaims, "User Identity");

                var userPrincipal = new ClaimsPrincipal(new[] { userIdentity });
                HttpContext.SignInAsync(userPrincipal);

                return(RedirectToAction("Index", "Home"));
            }

            return(View("UserLogin", userModel));
        }
コード例 #2
0
        public IViewComponentResult Invoke()
        {
            var userDTO = OOPSConvert.OOPSJsonDeSerializeUserDTO(HttpContext.User.Claims.FirstOrDefault(z => z.Type == "UserDTO").Value);

            return(View(userDTO));
        }