Exemplo n.º 1
0
        public async Task <object> Login(string userName, string password)
        {
            var user = APP.LoginAdmin(userName, password);

            // var user = _userService.Login(userName, password);
            if (user != null)
            {
                var authenticationType = AdminAuthorizeAttribute.CustomerAuthenticationScheme;
                var identity           = new ClaimsIdentity(authenticationType);
                identity.AddClaim(new Claim(ClaimTypes.Sid, userName));
                identity.AddClaim(new Claim(ClaimTypes.Name, userName));
                identity.AddClaim(new Claim(ClaimTypes.Role, "admin"));
                await HttpContext.SignInAsync(authenticationType, new ClaimsPrincipal(identity));

                return(new { isok = true, msg = "" });
            }
            return(new { isok = false, msg = "登录失败,用户名密码不正确" });
        }