Esempio n. 1
0
        public async Task <RpsLoginInfo> AuthUser(ParamLoginInfo loginUser)
        {
            RpsLoginInfo result = new RpsLoginInfo()
            {
                ReturnUrl = loginUser.ReturnUrl,
                Success   = false
            };

            try
            {
                var user = await ValidateUser(loginUser.UserName, loginUser.Password);

                if (user != null)
                {
                    loginUser.Id   = user.Id;
                    loginUser.Name = user.Name;
                    await SignIn(loginUser);

                    result.Success = true;
                    return(result);
                }
                result.Success      = false;
                result.ErrorMessage = "没有该用户";
            }
            catch (Exception e)
            {
                result.ErrorMessage = e.Message;
            }

            return(result);
        }
        public async Task <IActionResult> Login(ParamLoginInfo loginInfo)
        {
            return(await ActionWrapAsync(async() =>
            {
                AuthBll auth = new AuthBll(_userService, HttpContext);
                ResultData <RpsLoginInfo> result = new ResultData <RpsLoginInfo>();
                result.Data = await auth.AuthUser(loginInfo);

                return result;
            }));
        }
Esempio n. 3
0
        private async Task SignIn(ParamLoginInfo loginUser)
        {
            var claims = new List <Claim>()
            {
                new Claim(ClaimTypes.Name, loginUser.Name),
                new Claim("UserId", loginUser.UserName),
                new Claim("Id", loginUser.Id.ToString())
            };                                                                               //init the identity instances
            var userPrincipal = new ClaimsPrincipal(new ClaimsIdentity(claims, "Operator")); //signin

            await _httpContext.SignInAsync("CookieAuth", userPrincipal, new Microsoft.AspNetCore.Authentication.AuthenticationProperties
            {
                ExpiresUtc   = DateTime.UtcNow.AddDays(1),
                IsPersistent = loginUser.IsPersistent,
                AllowRefresh = false
            });
        }