public ActionResult Login(string returnUrl)
        {
            ViewBag.ReturnUrl = returnUrl;
            LoginViewModel model = new LoginViewModel();
            model.ForgotPassword = new ForgotPasswordViewModel();
            var cookie = Request.Cookies["UserCookie"];
            if (cookie != null)
            {
                model.Username = cookie.Value;
                model.Password = string.Empty;
                model.RememberMe = true;
            }

            return View(model);
        }
        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var user = await _userManager.FindAsync(model.Username, model.Password);
                    if (user != null)
                    {
                        if (Role.Admin.Equals(user.Role))
                        {
                            await SignInAsync(user, model.RememberMe);
                            return Redirect("/Admin/Management/ParametricBusinessRules");
                        }

                        if (user.Status.Equals((int)Status.InActive)
                            || user.Status.Equals((int)Status.Active)
                            || user.Status.Equals((int)Status.NULL)
							|| user.Status.Equals((int)Status.Expired))
                        {
                            await SignInAsync(user, model.RememberMe);
                            if (!string.IsNullOrWhiteSpace(returnUrl))
                            {
                                return RedirectToLocal(returnUrl);
                            }
                            return RedirectToAction("ListBooking", "Booking");
                        }
                        else
                        {
                            ModelState.AddModelError("", "Your account has been disabled.");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Invalid email/username or password");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("AccountController_Login_Error:" + ex.ToString());
                ModelState.AddModelError("", NotificationMessage.SystemUnavailable);
            }
            model.ForgotPassword = new ForgotPasswordViewModel();
            return View(model);
        }
        public async Task<IHttpActionResult> Login(LoginViewModel user)
        {
            if (string.IsNullOrEmpty(user.Username) || string.IsNullOrEmpty(user.Password))
            {
                return null;
            }

            string userName = EncryptDecryptHelper.Decrypt(user.Username);
            string password = EncryptDecryptHelper.Decrypt(user.Password);

            try
            {
                var appUser = await _userManager.FindAsync(userName, password);
                if (appUser != null)
                {
                    string token = LoginHelper.TokenMaker();

                    if (appUser.IsEmailConfirmed || appUser.IsPhoneConfirmed)
                    {
                        Services.Users.UpdateTokenById(appUser.Id, token);

                        appUser.Status = (int)LoginStatus.PhoneConfirmed;
                        appUser.Token = token;

                        await SignInAsync(appUser, user.RememberMe);
                        LoginHelper.PushLogoutForDevice(appUser.UserName, token);
                        return Json(LoginHelper.RemoveUnusedAttr(Services.Users.GetUserById(appUser.Id)));
                    }
                    Services.Users.UpdateTokenById(appUser.Id, token);
                    return Json(LoginHelper.RemoveUnusedAttr(Services.Users.GetUserById(appUser.Id)));
                }
                else
                {
                    return Json(new UserDto { UserName = user.Username });
                }
            }
            catch (Exception e)
            {
                Log.Error("Login", e);
                return Json(new { Status = HttpStatusCode.InternalServerError });
            }
        }