public void ObterUsuario() { // Arrange var usuarioService = new UsuarioService(); // Act var usuario = usuarioService.Find(1); // Assert Assert.AreEqual("JOSE", usuario.Nome); }
public void ListarUsuarios() { // Arrange var listar = new UsuarioService(); // Act var usuarios = listar.Listar().ToList(); // Assert Assert.AreEqual(1, usuarios.Count); }
public void AlterarUsuario() { // Arrange var service = new UsuarioService(); var usuario = service.Find(3); // Act int id = service.Gravar(usuario); // Assert Assert.AreEqual(3, id); }
public void IncluirUsuario() { // Arrange var usuario = new Usuario { Email = "*****@*****.**", Nome = "JOSE", Login = "******", Senha = "b8c7p2c6" }; // Act var idUsuario = new UsuarioService().Gravar(usuario); // Assert Assert.AreEqual(idUsuario, 1); }
public ActionResult Index() { ViewBag.Title = Resources.Resource.PainelControle_Titulo; var auth = FormsAuthenticationUtil.UserAuthenticated; var isPrimeiroAcesso = new UsuarioService().IsPrimeiroAcesso(auth.Email); ViewBag.IsPrimeiroAcesso = isPrimeiroAcesso; //if (SecurityHelper.GainSystemUserIsAuthenticated() && FormsAuthenticationUtil.UserAuthenticated != null && FormsAuthenticationUtil.UserAuthenticated.IdGrupo == 4) //{ // var promoterComissao = new PromoterController().ValidateCommissions(); // ViewBag.PromoterComissao = promoterComissao; //} //else //{ // ViewBag.PromoterComissao = false; //} return View(); }
public ActionResult LogIn(LogOnModel model, String returnUrl) { if (ModelState.IsValid) { var senha = Encryption.EncryptMd5(String.Format("{1}@{0}", model.Senha.Trim(), model.Login.Trim())); if (new UsuarioService().Validate(model.Login.Trim(), senha)) { // Get Information of the User is Logged var usuario = new UsuarioService().GetRecords(usu => usu.Login == model.Login.Trim()).FirstOrDefault(); if (usuario != null && !usuario.IsAtivo)// Inativo { ModelState.AddModelError("", Constants._msgInactiveUser); } else if (usuario != null) // Ativo { // Serialize Model var serializeModel = new CustomPrincipalSerializeModel { IdUsuario = usuario.IdUsuario, NomeUsuario = usuario.NomeUsuario, Login = usuario.Login, Email = usuario.Email, IdGrupo = usuario.IdGrupo }; var userData = new JavaScriptSerializer().Serialize(serializeModel); var prefixoCookie = ConfigurationManager.AppSettings["AdminCookieName"]; FormsAuthenticationUtil.SetCustomAuthCookie(prefixoCookie + model.Login, userData, false); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } return RedirectToAction("Index", "Home"); } } ModelState.AddModelError("Login", Constants._msgUserOrPasswordInvalid); } // If we got this far, something failed, redisplay form return View(model); }
public PerfilController(UsuarioService usuarioService, MensagemService mensagemService, AtividadeService atividadeService, IEnumHelper enumHelper) { this._usuarioService = usuarioService; this._mensagemService = mensagemService; this._atividadeService = atividadeService; ViewBag.Usuarios = usuarioService.ObterUsuarios(); ViewBag.ListaStatusTarefa = Enum.GetValues(typeof(DKO.EQualy.Domain.Enum.Atividade.StatusAtividade)).Cast<DKO.EQualy.Domain.Enum.Atividade.StatusAtividade>().Select(v => new SelectListItem { Text = enumHelper.ObterDescricaoDoEnum(v), Value = ((int)v).ToString() }).ToList(); ViewBag.LstaTipoTarefa = Enum.GetValues(typeof(DKO.EQualy.Domain.Enum.Atividade.TipoAtividade)).Cast<DKO.EQualy.Domain.Enum.Atividade.TipoAtividade>().Select(v => new SelectListItem { Text = enumHelper.ObterDescricaoDoEnum(v), Value = ((int)v).ToString() }); }
public void CreateAUsuarioServiceTest() { _usuario = ObjectMother.GetUsuario(); //ARRANGE var repository = new Mock<IUsuarioRepository>(); repository.Setup(r => r.Save(_usuario)).Returns(_usuario); //ARRANGE IUsuarioService service = new UsuarioService(repository.Object); //ARRANGE var validation = new Mock<Usuario>(); validation.As<IObjectValidation>().Setup(product => product.Validate()); //ACTION service.CreateUsuario(validation.Object); //ASSERT validation.As<IObjectValidation>().Verify(x => x.Validate()); }
public UsuarioUnitTest() { service = new UsuarioService(); }
public ActionResult TrocarSenha(TrocaSenha troca) { try { if (ModelState.IsValid) { Salao.Domain.Abstract.Admin.ITrocaSenha trocar; trocar = new UsuarioService(); trocar.TrocarSenha(troca.IdUsuario, troca.SenhaAtual, troca.NovaSenhaConfere, false); return View("SenhaAlterada"); } return View(troca); } catch (Exception e) { ModelState.AddModelError(string.Empty, e.Message); return View(troca); } }
public ActionResult RedefinirSenha(int id) { var usuario = _service.Find(id); if (usuario == null) { return HttpNotFound(); } try { Salao.Domain.Abstract.Admin.ITrocaSenha redefinir; redefinir = new UsuarioService(); redefinir.RedefinirSenha(id); ViewBag.Nome = usuario.Nome; ViewBag.Email = usuario.Email; return View("SenhaRedefinida"); } catch (Exception e) { ModelState.AddModelError(string.Empty, e.Message); return View(usuario); } }
public ActionResult LogIn(LogInModel model, String returnUrl) { if (!ModelState.IsValid) { return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Validation, Message = @Resources.Resource.Msg_Geral_DadosInvalidos }); } Model.Usuario usuario = null; Perfil perfil = new Perfil(); // TODO: M.L. 2012/11/15 16:06 - Alterar a Senha de Todos novamente, quem é do EC deverá ser Encryption.EncryptMd5(senha@email) var senha = Encryption.EncryptMd5(String.Format("{1}@{0}", model.Password.Trim(), model.UserName.Trim())); var isValid = new UsuarioService().ValidateEcommerce(model.UserName.Trim(), senha); if (isValid) { usuario = new UsuarioService().GetRecords(usu => usu.Email == model.UserName.Trim() && usu.IsAtivo).FirstOrDefault(); } if (usuario == null) { return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Alert, Message = @Resources.Resource.Msg_Geral_UsuarioSenhaInvalido }); } var cliente = new ClienteService().GetCustomer(usuario.IdUsuario); if (cliente.IdPerfil != null) { // Armazena o Perfil do Cliente (logado) na Variável perfil = new Perfil { IdPerfil = cliente.Ecommerce_Perfil.IdPerfil, Nome = cliente.Ecommerce_Perfil.Nome, PercentualDesconto = cliente.Ecommerce_Perfil.PercentualDesconto }; } Guid cookieCarrinho = Guid.NewGuid(); var idCliente = 0; if (cliente != null) { idCliente = cliente.IdCliente; var cookie = Request.Cookies[_cookieCartKey]; //check if there is a cart if (cookie != null) { cookieCarrinho = new Guid(cookie.Value); var carrinhoAnonimo = new CarrinhoService().GetCart(cookieCarrinho); //verificar se existem items para o carrinho anonimo if (carrinhoAnonimo != null) { if (carrinhoAnonimo.Ecommerce_CarrinhoItem.Count > 0) { //remove qualquer carrinho antigo do cliente var carrinhosCliente = new CarrinhoService().GetRecords(car => car.IdCliente == idCliente); if (carrinhosCliente.Count > 0) { foreach (var item in carrinhosCliente.ToList()) { new CarrinhoService().DeleteCart(item.GuidCookie); } } new CarrinhoService().AttachCartToClient(cookieCarrinho, idCliente); } else { var carrinhoCliente = new CarrinhoService().GetRecords(car => car.IdCliente == idCliente).FirstOrDefault(); if (carrinhoCliente != null) { cookieCarrinho = carrinhoCliente.GuidCookie; } else { new CarrinhoService().AttachCartToClient(cookieCarrinho, idCliente); } } } else { //verificar se existe alguma carrinho para o cliente var carrinho = new CarrinhoService().GetRecords(car => car.IdCliente == idCliente).FirstOrDefault(); if (carrinho != null) { cookieCarrinho = carrinho.GuidCookie; } else { new CarrinhoService().CreateCart(cookieCarrinho, idCliente); } } cookie.Expires = DateTime.Now.AddDays(-1); // TODO: M.L. 2012/11/15 16:53 - Definir nos Setting o Tempo para expiração do Cookie do Carrinho System.Web.HttpContext.Current.Response.Cookies.Add(cookie); } else { //if cookie was null new CarrinhoService().CreateCart(cookieCarrinho, idCliente); } } var serializeModel = new CustomPrincipalSerializeModel { IdUsuario = usuario.IdUsuario, NomeUsuario = usuario.NomeUsuario, Login = usuario.Login, Email = usuario.Email, IdGrupo = usuario.IdGrupo, IdCliente = idCliente, CookieCarrinho = cookieCarrinho }; //Armazenar o Perfil do Cliente (logado) caso exista serializeModel.Perfil = perfil; var prefixoCookie = ConfigurationManager.AppSettings["EcommerceCookieName"]; FormsAuthenticationUtil.SetCustomAuthCookie(prefixoCookie + model.UserName, new JavaScriptSerializer().Serialize(serializeModel), model.RememberMe); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Success, ReturnUrl = returnUrl }, JsonRequestBehavior.AllowGet); } return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Success, ReturnUrl = Url.Content(@"~/Dashboard/") }, JsonRequestBehavior.AllowGet); }
public JsonResult PasswordRecover(ForgotPasswordModel model) { var regExpEmail = new Regex(@"^[\w-]+(\.[\w-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)*?\.[a-z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?$"); if (model == null || String.IsNullOrEmpty(model.EmailAdress) || !regExpEmail.IsMatch(model.EmailAdress)) { return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Alert, Message = Resources.Resource.Conta_EmailInvalido }); } if (ModelState.IsValid) { var user = new UsuarioService().GetByEmail(model.EmailAdress); if (user == null) { return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Alert, Message = Resources.Resource.Msg_EnvioSenha_EmailNotFound }, JsonRequestBehavior.AllowGet); } var newPass = Membership.GeneratePassword(6, 2); if (Email.SendNewPassword(user, newPass, false)) { user.Senha = newPass; user.LembreteSenha = String.Format(Resources.Resource.Senha_PerguntaSecreta, DateTime.Now); new UsuarioService().UpdateObject(user); return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Success, Message = Resources.Resource.Conta_SenhaEncaminhadaEmail }, JsonRequestBehavior.AllowGet); } return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Error, Message = Resources.Resource.Autenticacao_RecuperarSenhaErro }, JsonRequestBehavior.AllowGet); } return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Error, Message = Resources.Resource.Msg_Geral_Erro }, JsonRequestBehavior.AllowGet); }
public ActionResult ChangePassword(ChangePasswordModel model) { if (ModelState.IsValid) { if (!model.NewPassword.Equals(model.ConfirmPassword)) { return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Alert, Message = Resources.Resource.Msg_Geral_ConfirmacaoSenhaInvalido }); } var login = FormsAuthenticationUtil.UserAuthenticated.Login; var senha = Encryption.EncryptMd5(string.Format("{1}@{0}", model.OldPassword.Trim(), login.Trim())); var isValid = new UsuarioService().Validate(login.Trim(), senha); if (!isValid) { return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Alert, Message = Resources.Resource.Msg_Geral_SenhaAtualInvalida }); } try { var user = new UsuarioService().GetByEmail(FormsAuthenticationUtil.UserAuthenticated.Email); user.LembreteSenha = string.Format(Resources.Resource.Senha_PerguntaSecreta, DateTime.Now); user.Senha = model.NewPassword; new UsuarioService().UpdateObject(user); return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Success, Message = Resources.Resource.Msg_Geral_SenhaAlterada }); } catch (Exception) { return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Error, Message = Resources.Resource.Msg_Geral_SenhaErroAoAlterar }); } } return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Alert, Message = Resources.Resource.Conta_SenhaOuNovaSenhaInvalido }); }
public ActionResult InsertNewCustomer(NovoClienteModel model) { if (ModelState.IsValid) { if (!new ClienteService().EmailIsValid(model.EmailAdress)) { return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Validation, Message = Resources.Resource.NovoCliente_EmailDuplicado }, JsonRequestBehavior.AllowGet); } if (new ClienteService().InsertCustomer(model)) { if (model.IdKit.HasValue) { //var senha = Encryption.EncryptMd5(string.Format("{1}@{0}", model.Password.Trim(), model.EmailAdress.Trim())); Usuario usuario = new UsuarioService().GetRecords(usu => usu.Login == model.EmailAdress.Trim() && usu.IsAtivo).FirstOrDefault(); if (usuario == null) { return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Alert, Message = Resources.Resource.Msg_Geral_UsuarioSenhaInvalido }); } var cliente = new ClienteService().GetRecords(cli => cli.IdUsuario == usuario.IdUsuario).FirstOrDefault(); Guid cookieCarrinho = Guid.NewGuid(); var idCliente = 0; if (cliente != null) { idCliente = cliente.IdCliente; var cookie = Request.Cookies[_cookieCartKey]; //check if there is a cart if (cookie != null) { cookieCarrinho = new Guid(cookie.Value); var carrinhoAnonimo = new CarrinhoService().GetCart(cookieCarrinho); //verificar se existem items para o carrinho anonimo if (carrinhoAnonimo != null) { if (carrinhoAnonimo.Ecommerce_CarrinhoItem.Count > 0) { //remove qualquer carrinho antigo do cliente var carrinhosCliente = new CarrinhoService().GetRecords(car => car.IdCliente == idCliente); if (carrinhosCliente.Count > 0) { foreach (var item in carrinhosCliente.ToList()) { new CarrinhoService().DeleteCart(item.GuidCookie); } } new CarrinhoService().AttachCartToClient(cookieCarrinho, idCliente); } else { var carrinhoCliente = new CarrinhoService().GetRecords(car => car.IdCliente == idCliente).FirstOrDefault(); if (carrinhoCliente != null) { cookieCarrinho = carrinhoCliente.GuidCookie; } else { new CarrinhoService().AttachCartToClient(cookieCarrinho, idCliente); } } } else { //verificar se existe alguma carrinho para o cliente var carrinho = new CarrinhoService().GetRecords(car => car.IdCliente == idCliente).FirstOrDefault(); if (carrinho != null) { cookieCarrinho = carrinho.GuidCookie; } else { new CarrinhoService().CreateCart(cookieCarrinho, idCliente); } } cookie.Expires = DateTime.Now.AddDays(-1); System.Web.HttpContext.Current.Response.Cookies.Add(cookie); } else { //if cookie was null new CarrinhoService().CreateCart(cookieCarrinho, idCliente); } } var serializeModel = new CustomPrincipalSerializeModel { IdUsuario = usuario.IdUsuario, NomeUsuario = usuario.NomeUsuario, Login = usuario.Login, Email = usuario.Email, //IdGrupo = usuario.IdGrupo, IdCliente = idCliente, CookieCarrinho = cookieCarrinho }; var prefixoCookie = ConfigurationManager.AppSettings["EcommerceCookieName"]; FormsAuthenticationUtil.SetCustomAuthCookie(prefixoCookie + model.EmailAdress, new JavaScriptSerializer().Serialize(serializeModel), false); return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Success, ReturnUrl = Url.Content(@"~/Cart/Details") }, JsonRequestBehavior.AllowGet); } return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Success, Message = Resources.Resource.Msg_Geral_CadastroRealizado, ReturnUrl = Url.Content(@"~/Dashboard") }, JsonRequestBehavior.AllowGet); } return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Error, Message = Resources.Resource.Msg_Geral_Erro }, JsonRequestBehavior.AllowGet); } return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Validation, Message = Resources.Resource.Msg_Geral_DadosIncorretos }, JsonRequestBehavior.AllowGet); }