Пример #1
0
        public async Task <IActionResult> LoginAsync(string email, string password, string redirect_uri = "/")
        {
            var user = _userRepository.Login(email, password);

            if (user == null)
            {
                return(Json(JsonResponse.RenderFailure("邮箱或密码不正确")));
            }
            if (string.IsNullOrWhiteSpace(redirect_uri))
            {
                redirect_uri = "/";
            }
            var claims = new List <Claim>()
            {
                new Claim(ClaimTypes.Name, user.Id.ToString()),
            };

            //init the identity instances
            var userPrincipal = new ClaimsPrincipal(new ClaimsIdentity(claims, "Customer"));
            //signin
            await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, userPrincipal, new AuthenticationProperties
            {
                ExpiresUtc   = DateTime.UtcNow.AddMinutes(20),
                IsPersistent = false,
                AllowRefresh = false
            });

            return(Json(JsonResponse.RenderData(new {
                url = redirect_uri,
            }, "登录成功!")));
        }
Пример #2
0
 public IActionResult Model(string table, bool preview = false)
 {
     if (preview)
     {
         return(Json(JsonResponse.RenderData(new
         {
             code = _repository.Generate(table)
         })));
     }
     return(Json(JsonResponse.RenderFailure("未实现")));
 }
Пример #3
0
        public async Task <JsonResult> Logout()
        {
            var auth = await HttpContext.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme);

            if (auth.Succeeded)
            {
                var userId = auth.Principal.Identity.Name;
            }
            await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

            return(Json(JsonResponse.RenderData(null, "退出成功")));
        }
Пример #4
0
        public IActionResult Table()
        {
            var data = _repository.AllTableNames();

            return(Json(JsonResponse.RenderData(data)));
        }
Пример #5
0
 public IActionResult Index()
 {
     return(Json(JsonResponse.RenderData(null)));
 }