Пример #1
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);
        }
Пример #2
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            _log.Info("Login FormPost Entered");
            _log.Debug("Parameter :"+model);
            try
            {
                RegisterModel AccountData   = null;
                var loginData               = model;
                var Data                    = JsonConvert.DeserializeObject(Utilities.HttpRequest.GetHttpRequest(url + "AccountService.svc/Login", "POST", JsonConvert.SerializeObject(loginData))) as JToken;
                AccountData                 = JsonConvert.DeserializeObject<RegisterModel>(Data["LoginResult"].ToString());

                _log.Debug("Data :"+JsonConvert.SerializeObject(AccountData,Formatting.Indented));

                if (!string.IsNullOrEmpty(AccountData.UserName))
                {

                    FormsAuthenticationTicket Ticket    = new FormsAuthenticationTicket(
                            1,
                            AccountData.UserName,
                            DateTime.Now,
                            DateTime.Now.AddMinutes(5),false,
                            JsonConvert.SerializeObject(AccountData, Formatting.Indented),
                            FormsAuthentication.FormsCookiePath);

                    string EncTicket                    = FormsAuthentication.Encrypt(Ticket);
                    HttpCookie Cookie                   = new HttpCookie(FormsAuthentication.FormsCookieName, EncTicket);

                    if (Ticket.IsPersistent)
                    {
                        Cookie.Expires = Ticket.Expiration;
                    }

                    System.Web.HttpContext.Current.Response.Cookies.Add(Cookie);

                    if (string.IsNullOrEmpty(returnUrl))
                    {
                        return RedirectToAction("Index", "Contact");
                    }
                    else
                    {
                        return Redirect(returnUrl);
                    }
                }
                else
                {
                    _log.Debug("Wrong Username or Password");
                    ViewBag.ErrorMessage = "Wrong Username or Password";
                    return View();
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
                return RedirectToAction("ErrorPage", "Home", new { ex = ex.Message });
            }
            finally
            {
                _log.Info("Login Exited");
            }
        }