Ejemplo n.º 1
0
        public async Task <IHttpActionResult> Authorize(LoginMoodel model)
        {
            if (model != null)
            {
                using (var scope = DependencyConfig.Container.BeginLifetimeScope())
                {
                    var service    = scope.Resolve <IUserService>();
                    var authResult = await service.Auth(model.Email, model.Password);

                    if (authResult != null)
                    {
                        HttpContext.Current.GetOwinContext().Authentication.SignIn(new Microsoft.Owin.Security.AuthenticationProperties {
                            IsPersistent = true
                        }, authResult);
                        return(Ok(authResult.GetUserId().Replace("-", "")));
                    }
                }
            }
            return(Content(HttpStatusCode.BadRequest, new { ErrorMessage = "Incorrect data." }));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Login(LoginMoodel model)
        {
            await Task.Delay(1000);

            using (var scope = DependencyConfig.Container.BeginLifetimeScope())
            {
                var service = scope.Resolve <IUserService>();
                var result  = await service.Auth(model.Email, model.Password);

                if (result != null)
                {
                    System.Web.HttpContext.Current.GetOwinContext().Authentication.SignIn(new Microsoft.Owin.Security.AuthenticationProperties
                    {
                        IsPersistent = true
                    }, result);
                    // ;

                    return(JavaScript("var waitAuth=true;window.location.pathname='/Account/Index';"));
                }
            }
            ModelState.AddModelError("Password", "Incorrect data.");

            return(PartialView("_LoginContainer", model));
        }