protected void SetCurrentLanguage(string language)
 {
     if (!string.IsNullOrWhiteSpace(language))
     {
         LanguagesManager.SetLanguage(language);
         ViewBag.Culture = language;
     }
 }
 public ActionResult SetLanguage(string lang, string returnUrl)
 {
     LanguagesManager.SetLanguage(lang);
     if (Url.IsLocalUrl(returnUrl))
     {
         return(Redirect(returnUrl));
     }
     return(RedirectToAction("Index", "Home"));
 }
Example #3
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                var user = await UserManager.FindByNameAsync(model.UserName);

                if (user != null)
                {
                    LanguagesManager.SetLanguage(user.Language);
                    user.LastLoginTime = DateTime.Now;
                    await UserManager.UpdateAsync(user);
                }
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", Lexicon.InvalidLoginAttempt);
                return(View(model));
            }
        }