public IActionResult Logar(LoginViewModelInput loginViewModeInput) { var registrarViewModelInput = new RegistrarViewModelInput() { Login = "******", Email = "*****@*****.**", Senha = "teste123" }; var secret = Encoding.ASCII.GetBytes("MzfsT&d9gprP>!9$Es(X!5g@;ef!5sbk:jH\\2.}8ZP'qY#7"); var symmetricSecurityKey = new SymmetricSecurityKey(secret); var securityTokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, registrarViewModelInput.Email.ToString()), new Claim(ClaimTypes.Name, registrarViewModelInput.Login.ToString()), new Claim(ClaimTypes.Name, registrarViewModelInput.Senha.ToString()) }), Expires = DateTime.UtcNow.AddDays(1), SigningCredentials = new SigningCredentials(symmetricSecurityKey, SecurityAlgorithms.HmacSha256Signature) }; var jwtSecurityTokenHandler = new JwtSecurityTokenHandler(); var tokenGenerated = jwtSecurityTokenHandler.CreateToken(securityTokenDescriptor); var token = jwtSecurityTokenHandler.WriteToken(tokenGenerated); return(Ok(new { Token = token, Usuario = registrarViewModelInput })); }
public IActionResult Registrar(RegistrarViewModelInput registrarViewModelInput) { var options = new DbContextOptionsBuilder <CursoDBContext>(); options.UseSqlServer("Server=localhost"); CursoDBContext contexto = new CursoDBContext(options); return(Created("", registrarViewModelInput)); }
public IActionResult Registrar(RegistrarViewModelInput registrarViewModelInput) { var options = new DbContextOptionsBuilder <CursoDbContext>(); options.UseSqlServer("Server=localhost;Database=CURSO;user=sa;password=App@223020"); CursoDbContext contexto = new CursoDbContext(options); //Convertendo var usuario = new Usuario(); usuario.Email = registrarViewModelInput.Login; usuario.Senha = registrarViewModelInput.Senha; usuario.Email = registrarViewModelInput.Email; _usuarioRepository.AdicionarUser(usuario); _usuarioRepository.Commit(usuario); return(Created("Registro realizado com sucesso ! ", registrarViewModelInput)); }
public IActionResult Registrar(RegistrarViewModelInput registrarViewModelInput) { // var migracoesPendentes = context.Database.GetPendingMigrations(); // if (migracoesPendentes.Any()) // { // context.Database.Migrate(); // } var usuario = new Usuario(); usuario.Login = registrarViewModelInput.Login; usuario.Email = registrarViewModelInput.Email; usuario.Senha = registrarViewModelInput.Senha; _usuarioRepository.Adicionar(usuario); _usuarioRepository.Commit(); return(Created("", registrarViewModelInput)); }
public IActionResult Registro(RegistrarViewModelInput registrarViewModelInput) { return(Created("", registrarViewModelInput)); }