public IActionResult Login(UserModel userLogin) { try { var user = _userRest.Find(new UserFilter { Login = userLogin.Login, Password = userLogin.Password }); if (!user.Success) { ModelState.AddModelError("Login", "Login ou senha incorretos"); return(View("Index", userLogin)); } var employee = _employeeRest.Find(new EmployeeFilter { Id = user.Model.EmployeeId }); if (!employee.Success) { ModelState.AddModelError("Login", "Funcionário não encontrado"); return(View("Index", userLogin)); } SingIn(employee.Model); return(RedirectToAction("Index")); } catch (Exception error) { ModelState.AddModelError("Login", error.GetBaseException().Message); return(RedirectToAction("Index")); } }
public IActionResult AddUser(long id) { var result = _userRest.Find(new UserFilter { EmployeeId = id }); if (result.Model != null) { ViewBag.Error = new List <string> { "Esse funcionário já tem um usuário e senha cadastrado." }; var employees = _employeeRest.FindPaginated(new EmployeeFilter()); return(View("Index", employees)); } return(RedirectToAction("Register", "User", new { employeeId = id })); }
public IActionResult Update(UserModel userModel) { if (userModel.NewPassword != userModel.NewPasswordConfirmation) { ViewBag.Error = new List <string> { "A nova senha e a confirmação da nova senha devem ser idênticas." }; return(View(new UserModel())); } var currentUser = _userService.GetCurrentUser(); userModel.Login = currentUser.Login; var user = _userRest.Find(new UserFilter { Login = userModel.Login, Password = userModel.Password }); if (!user.Success) { ViewBag.Error = new List <string> { "A senha atual está incorreta." }; return(View(new UserModel())); } user.Model.Password = userModel.NewPassword; var result = _userRest.Update(user.Model); if (!result.Success) { ViewBag.Error = new List <string> { "Erro ao alterar a senha do usuário.." }; return(View(userModel)); } ViewBag.Error = new List <string> { "Nova senha cadastrada com sucesso." }; return(View(new UserModel())); }