コード例 #1
0
ファイル: AccountController.cs プロジェクト: ryiskate/Tuiter
        public ActionResult Entrar(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (ValidarUsuario(model.Email, model.Senha))
                {
                    FormsAuthentication.SetAuthCookie(model.Email, model.Lembrar);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "O e-mail ou senha estão incorretos");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: ryiskate/Tuiter
        public JsonResult JsonEntrar(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (ValidarUsuario(model.Email, model.Senha))
                {
                    FormsAuthentication.SetAuthCookie(model.Email, model.Lembrar);
                    return Json(new { success = true, redirect = returnUrl });
                }
                else
                {
                    ModelState.AddModelError("", "O e-mail ou senha estão incorretos");
                }
            }

            // If we got this far, something failed
            return Json(new { errors = ModelState.ToArray() });
        }
コード例 #3
0
ファイル: AccountController.cs プロジェクト: vov4uk/uit
        public ActionResult Login(LogOnModel model, string returnUrl)
        {
            if (this.ModelState.IsValid)
            {

                var client = this.Request.Browser.Browser;
                var response = MvcApp.HttpRequest.GetHttpRequest("jsonLoginCheck/" + model.UserName + "-" + model.Password + "-" + client);
                var res = JsonConvert.DeserializeAnonymousType(response, new { JsonLoginCheckResult = "" });

                if (res.JsonLoginCheckResult != null)
                {

                    // check if cookie exists and if yes update
                    HttpCookie existingCookie = this.Request.Cookies["JsonLoginCheckResult"];
                    if (existingCookie != null)
                    {
                        // force to expire it
                        existingCookie.Value = res.JsonLoginCheckResult;
                        existingCookie.Expires = DateTime.Now.AddHours(-20);
                    }

                    // create a cookie
                    var newCookie = new HttpCookie("JsonLoginCheckResult", res.JsonLoginCheckResult);

                    this.Response.Cookies.Add(newCookie);

                    //         Session.Add("JsonLoginCheckResult", res.JsonLoginCheckResult);
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (this.Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return this.Redirect(returnUrl);
                    }
                    return this.RedirectToAction("Index", "Home");
                }
                this.ModelState.AddModelError("", "Імя користувача або пароль невірні.");
            }

            // If we got this far, something failed, redisplay form
            return this.View(model);
        }
コード例 #4
0
ファイル: AccountController.cs プロジェクト: mcseiu05/m_cseiu
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #5
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }