Ejemplo n.º 1
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                try
                {

                    var authService = ServiceStack.WebHost.Endpoints.AppHostBase.Resolve<ServiceStack.ServiceInterface.Auth.AuthService>();
                    authService.RequestContext = System.Web.HttpContext.Current.ToRequestContext();
                    var response = authService.Authenticate(new ServiceStack.ServiceInterface.Auth.Auth
                    {
                        UserName = model.UserName,
                        Password = model.Password,
                        RememberMe = model.RememberMe
                    });

                    // add ASP.NET auth cookie
                    System.Web.Security.FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);

                    //Get the ServicestackSession Object
                    ServiceStack.ServiceInterface.Auth.AuthUserSession sss = base.SessionAs<ServiceStack.ServiceInterface.Auth.AuthUserSession>();

                    returnUrl = sss.ReferrerUrl;

                    return RedirectToLocal(returnUrl);
                }
                catch (ServiceStack.Common.Web.HttpError)
                {
                }
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "El nombre de usuario o password que introdujo es incorrecto.");
            return View(model);
        }
Ejemplo n.º 2
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }