示例#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)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {

                return RedirectToLocal(returnUrl);
            }

            // Se chegarmos até aqui e houver alguma falha, exibir novamente o formulário
            ModelState.AddModelError("", "O nome de usuário ou a senha fornecido está incorreto.");
            return View(model);
        }
示例#3
0
        public JsonResult _Login(LoginModel model)
        {
            bool userAuthenticated = false;
            string redirectUrl = Url.Action("Index", "Chat");

            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                userAuthenticated = true;

                // setting the online status for user to true
                /*var update = db.UserProfiles.First(x=>x.UserId == (int)WebSecurity.CurrentUserId);
                update.IsOnline = true;
                db.SaveChanges();
                */

                // get id of user
                int intUserId = WebSecurity.GetUserId(model.UserName);

                if (intUserId != -1)
                {
                    // Model method - setting user online status to true - db
                    db.setOnlineStatus(intUserId, true, this.Session.SessionID);
                    signalRJoinAnnounce(model.UserName);
                    signalRShowOnlineUsers();
                }

            }

            return Json(new { userAuthenticated = userAuthenticated, url = redirectUrl });
        }