public async Task <ActionResult> LogOn(LogOnViewModel model, string returnUrl) { if (!ModelState.IsValid) { model.LanguageSelectList = GetLanguageSelectList(); model.CurrentLanguage = CultureManager.GetCulture(Thread.CurrentThread).Name; return(View(model)); } DateTime loginAttempUtc = DateTime.UtcNow; var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, false, shouldLockout : true).ConfigureAwait(false); switch (result) { case SignInStatus.Success: ApplicationUser applicationUser = await UserManager.FindByNameAsync(model.UserName).ConfigureAwait(false); PerfilUsuario perfilUsuario = _uow.PerfilUsuarioRepository.GetByUserId(applicationUser.Id); if (perfilUsuario.Ativo) { if (_uow.EmpresaRepository.RetornarEmpresaPrincipal(applicationUser.Id) > 0) { await CreateApplicationSession(model.UserName).ConfigureAwait(false); return(RedirectToLocal(returnUrl)); } else { model.ErrorMessage = Res.UserEmpresaError; } } else { model.ErrorMessage = "O usuário informado não está ativo no sistema."; } break; case SignInStatus.LockedOut: model.ErrorMessage = await GetLogOnLockoutMessageAsync(loginAttempUtc, model.UserName).ConfigureAwait(false); break; case SignInStatus.RequiresVerification: model.ErrorMessage = Res.SignInRequiresVerificationMessage; break; case SignInStatus.Failure: default: model.ErrorMessage = Res.InvalidUserMessage; break; } model.LanguageSelectList = GetLanguageSelectList(); model.CurrentLanguage = CultureManager.GetCulture(Thread.CurrentThread).Name; model.Password = string.Empty; return(View(model)); }
public static MessageBoxResult Handle(CultureManager cm, AppException cause, string title = "Error") { List <Error> errorMessages = cause.GetErrorMessage(cm.GetCulture(CultureType.Message.ToString())); StringBuilder messages = new StringBuilder(); string errorType = string.Empty; foreach (Error exceptionData in errorMessages) { messages.Append("\n"); if (exceptionData.Data == null || exceptionData.Data.Count == 0) { messages.Append(exceptionData.Code); } else { foreach (string errorData in exceptionData.Data) { messages.Append(errorData); if (exceptionData.Data.Count > 1) { messages.Append("\n"); } } } } return(MessageBox.Show(messages.ToString(), title, MessageBoxButton.OK)); }
public ActionResult LogOn(string l = null) { if (!string.IsNullOrEmpty(l)) { CultureManager.SetCulture(Thread.CurrentThread, HttpContext, l); } var model = new LogOnViewModel { LanguageSelectList = GetLanguageSelectList(), CurrentLanguage = CultureManager.GetCulture(Thread.CurrentThread).Name }; return(View(model)); }