public void Dado_um_email_e_senha_validos_o_usuario_deve_ser_autenticado() { var _email = "*****@*****.**"; var _senha = "P@ssw0rd"; var command = new LoginCommand(_email, _senha); var commandResult = (GenericCommandResult)_handler.Handle(command); Assert.IsTrue(commandResult.Sucess); }
public ActionResult Read(string nome) { try { var handler = new UsuarioHandler(); var command = new UsuarioReadCommand() { Nome = nome }; var result = (CommandResult <UsuarioReadOut>)handler.Handle(command, Service); return(Ok(result)); } catch (ArgumentNullException e) { return(NotFound(new CommandResult <bool>() { Message = e.Message })); } catch (Exception e) { return(NotFound(new CommandResult <bool>() { Message = e.Message })); } }
public IActionResult Update([FromBody] UsuarioUpdateIn value) { try { var handler = new UsuarioHandler(); var command = new UsuarioUpdateCommand() { Id = value.Id, Nome = value.Nome, Email = value.Email, Senha = value.Senha }; var result = (CommandResult <bool>)handler.Handle(command, Service); return(Ok(result)); } catch (ArgumentNullException e) { return(NotFound(new CommandResult <bool>() { Message = e.Message })); } catch (Exception e) { return(NotFound(new CommandResult <bool>() { Message = e.Message })); } }
public IActionResult Authenticate([FromBody] AuthenticateIn value) { if (value.Nome == "Wilham Ezequiel de Sousa" && value.Senha == "123") { var securityKey = Configuration["SecurityKey"]; var handler = new UsuarioHandler(); var command = new UsuarioAuthenticateCommand() { Nome = value.Nome, Senha = value.Senha, SecurityKey = securityKey }; var result = (CommandResult <string>)handler.Handle(command, Service); return(Ok(result)); } else { bool sucess = false; var result = new CommandResult <bool>() { Success = false, Message = "Usuário ou senha inválidos" }; result.Data = sucess; return(Unauthorized(result)); } }
public IActionResult TrocaPassword([FromBody] UsuarioTrocaPasswordIn value) { try { var handler = new UsuarioHandler(); var command = new UsuarioTrocaPasswordCommand() { Nome = value.Nome, SenhaAtual = value.SenhaAtual, SenhaNova = value.SenhaNova }; var result = (CommandResult <bool>)handler.Handle(command, Service); return(Ok(result)); } catch (ArgumentNullException e) { return(NotFound(new CommandResult <bool>() { Message = e.Message })); } catch (Exception e) { return(NotFound(new CommandResult <bool>() { Message = e.Message })); } }
public ActionResult Delete(int id) { try { var handler = new UsuarioHandler(); var command = new UsuarioDeleteCommand() { Id = id }; var result = (CommandResult <bool>)handler.Handle(command, Service); return(Ok(result)); } catch (ArgumentNullException e) { return(NotFound(new CommandResult <bool>() { Message = e.Message })); } catch (Exception e) { return(NotFound(new CommandResult <bool>() { Message = e.Message })); } }
public GenericCommandResult Create([FromBody] RegistrarUsuarioCommand command, [FromServices] UsuarioHandler handler) { command.IdFirebase = HttpContext.User.Identities.FirstOrDefault().Claims.FirstOrDefault(c => c.Type.Contains("user_id")).Value; command.Email = HttpContext.User.Identities.FirstOrDefault().Claims.FirstOrDefault(c => c.Type.Contains("email")).Value; return((GenericCommandResult)handler.Handle(command)); }
public GenericCommandResult AlterarUsuario([FromServices] UsuarioHandler handler, [FromBody] AlterarUsuarioCommand usuario) { return((GenericCommandResult)handler.Handle(new AlterarUsuarioCommand { IdUsuario = usuario.IdUsuario, Perfil = usuario.Perfil, Ativo = usuario.Ativo })); }
public void AutheticateSuccess() { var handler = new UsuarioHandler(); var command = new UsuarioAuthenticateCommand() { SecurityKey = key, Nome = "UsuarioExistente", Senha = "123" }; var result = (CommandResult <string>)handler.Handle(command, Service); Assert.AreEqual(true, result.Success); }
public void TrocaPasswordSuccess() { var handler = new UsuarioHandler(); var command = new UsuarioTrocaPasswordCommand() { Nome = "UsuarioExistente", SenhaAtual = "123", SenhaNova = "456" }; var result = (CommandResult <bool>)handler.Handle(command, Service); Assert.AreEqual(true, result.Success); }
public void UpdateEmailErro() { var handler = new UsuarioHandler(); var command = new UsuarioUpdateCommand() { Id = 1, Email = "wil.com", Nome = "wilham", Senha = "123" }; handler.Handle(command, Service); Assert.AreEqual(false, handler.Valid); }
public void UpdateTamanhoNomeMinimoErro() { var handler = new UsuarioHandler(); var command = new UsuarioUpdateCommand() { Id = 1, Email = "*****@*****.**", Nome = "W", Senha = "123" }; handler.Handle(command, Service); Assert.AreEqual(false, handler.Valid); //nao precisa acoplar o result do command }
public GenericCommandResult Login([FromServices] UsuarioHandler handler) { var idUserFirebase = HttpContext.User.Identities.FirstOrDefault().Claims.FirstOrDefault(c => c.Type.Contains("user_id")).Value; var email = HttpContext.User.Identities.FirstOrDefault().Claims.FirstOrDefault(c => c.Type.Contains("email")).Value; return((GenericCommandResult)handler.Handle(new LogarUsuarioCommand { IdFirebase = idUserFirebase, Email = email })); }
public void CreateJaExisteErro() { var handler = new UsuarioHandler(); var command = new UsuarioCreateCommand() { Email = "wil.com", Nome = "Fake", Senha = "123" }; handler.Handle(command, Service); Assert.AreEqual(false, handler.Valid); }
public void CreateSucesso() { var handler = new UsuarioHandler(); var command = new UsuarioCreateCommand() { Email = "*****@*****.**", Nome = "UsuarioExistente", Senha = "123" }; handler.Handle(command, Service); Assert.AreEqual(true, handler.Valid); //nao precisa acoplar o result do command }
public void DeleteRegistroInexistenteErro() { var handler = new UsuarioHandler(); var command = new UsuarioDeleteCommand() { Id = 0 }; var result = (CommandResult <bool>)handler.Handle(command, Service); Assert.AreEqual(false, result.Success); }
public void DeleteSucesso() { var handler = new UsuarioHandler(); var command = new UsuarioDeleteCommand() { Id = 1 }; var result = (CommandResult <bool>)handler.Handle(command, Service); Assert.AreEqual(true, result.Success); }
public void ReadRegistroInexistenteErro() { var handler = new UsuarioHandler(); var command = new UsuarioReadCommand() { Nome = "UsuarioInexistente" }; var result = (CommandResult <UsuarioReadOut>)handler.Handle(command, Service); Assert.AreEqual(false, result.Success); }
public void ReadSucesso() { var handler = new UsuarioHandler(); var command = new UsuarioReadCommand() { Nome = "UsuarioExistente" }; var result = (CommandResult <UsuarioReadOut>)handler.Handle(command, Service); Assert.AreEqual(true, result.Success); }
public IActionResult Post([FromBody] AdicionarUsuarioCommand command) { var result = _usuarioHandler.Handle(command); return(Response(result, _usuarioHandler.Notifications)); }
public IComandResult Post([FromBody] RegistroUsuarioComand command) { var result = (ComandResult)_usuarioHandler.Handle(command); this.Commit(result.Success); return(result); }
public ICommandResult UsuarioNovo([FromBody] AdicionarUsuarioCommand command) { return((UsuarioCommandResult)_handler.Handle(command)); }
public GenericoUsuarioCommandResult Deletar([FromBody] DeletarUsuarioCommand command, [FromServices] UsuarioHandler handler) { return((GenericoUsuarioCommandResult)handler.Handle(command)); }
public object Post( [FromBody] AutenticarUsuarioComand usuario, [FromServices] SigningConfigurations signingConfigurations, [FromServices] TokenConfigurations tokenConfigurations) { bool credenciaisValidas = false; var resposta = (ComandResult)_usuarioHandler.Handle(usuario); if (resposta.Success == false) { return(resposta); } else { usuarioComand = DeserializerObjeto <UsuarioComand> .RetornoObjetoTipado(resposta.Data); credenciaisValidas = true; Commit(resposta.Success); } //var usuarioBase = usersDAO.Find(usuario.UserID); //credenciaisValidas = (usuarioBase != null usuario.UserID == usuarioBase.UserID && usuario.AccessKey == usuarioBase.AccessKey); if (credenciaisValidas) { ClaimsIdentity identity = new ClaimsIdentity( new GenericIdentity(usuarioComand.Id, "UsuarioId"), new[] { new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString("N")), new Claim(JwtRegisteredClaimNames.UniqueName, usuarioComand.Id), new Claim(JwtRegisteredClaimNames.Email, usuario.Login), new Claim(JwtRegisteredClaimNames.Sid, usuarioComand.Id), new Claim("Administrador", usuarioComand.TipoUsuario) //new Claim(JwtRegisteredClaimNames.NameId, usuario.Nome), //new Claim(JwtRegisteredClaimNames.UniqueName, usuario.Id.ToString()) } ); var usuarioHomeCommandResult = new UsuarioHomeCommandResult(usuario.Login, usuarioComand.Nome, usuarioComand.SobreNome, usuarioComand.Foto, usuarioComand.TipoUsuario); DateTime dataCriacao = DateTime.Now; DateTime dataExpiracao = dataCriacao + TimeSpan.FromSeconds(tokenConfigurations.Seconds); var handler = new JwtSecurityTokenHandler(); var securityToken = handler.CreateToken(new SecurityTokenDescriptor { Issuer = tokenConfigurations.Issuer, Audience = tokenConfigurations.Audience, SigningCredentials = signingConfigurations.SigningCredentials, Subject = identity, NotBefore = dataCriacao, Expires = dataExpiracao }); var token = handler.WriteToken(securityToken); return(new { authenticated = true, created = dataCriacao.ToString("yyyy-MM-dd HH:mm:ss"), expiration = dataExpiracao.ToString("yyyy-MM-dd HH:mm:ss"), accessToken = token, message = "OK", Usuario = usuarioComand }); } else { return(new { authenticated = false, message = "Falha ao autenticar" }); } }