Beispiel #1
0
        public async Task<ActionResult> Login(LoginModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            try
            {
                var result = await AdminService.Instance.AuthenticateAsync<LoginResult>(model.UserName, model.Password);
                var authTicket = new FormsAuthenticationTicket(
                  2,
                  model.UserName,
                  result.Issued.UtcDateTime,
                  result.Expires.UtcDateTime,
                  model.RememberMe,
                  JsonConvert.SerializeObject(result));
                var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket));
                if (model.RememberMe)
                    authCookie.Expires = DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes);
                Response.AppendCookie(authCookie);
                if (string.IsNullOrWhiteSpace(returnUrl))
                    return RedirectToAction("Index", "Vendor");
                else
                    return Redirect(returnUrl);
            }
            catch (ApiException ex)
            {
                ModelState.AddModelError(string.Empty, "Username or password is incorrect!");
                return View(model);
            }
        }
Beispiel #2
0
 public ActionResult Login(string returnUrl)
 {
     ViewBag.ReturnUrl = returnUrl;
     ViewBag.Title = "Log in";
     LoginModel model = new LoginModel();
     model.UserName = "******";
     model.Password = "******";
     return View(model);
 }