public async Task <ActionResult> CreateUser([FromServices] UserManager <ApplicationUser> userManager, [FromServices] AccessManager accessManager, [FromBody] RegisterUser registerUser) { var user = new ApplicationUser { UserName = registerUser.UserName, Email = registerUser.Email, PhoneNumber = registerUser.PhoneNumber }; var result = userManager.CreateAsync(user, registerUser.Password).Result; if (result.Succeeded) { var usuarioAcesso = new User(); usuarioAcesso.UserID = user.Id; usuarioAcesso.Password = user.PasswordHash; usuarioAcesso.Email = user.Email; var resultado = accessManager.GenerateToken(usuarioAcesso); return(Created($"registerUser/{resultado}", new { resultado })); } else { return(BadRequest("Usuário ou senha inválidos")); } }
public IActionResult Post( [FromBody] UserLoginRequest user, [FromServices] AccessManager accessManager) { if (accessManager.ValidateCredentials(user)) { var token = accessManager.GenerateToken(user).AccessToken; var userInfo = _userService.GetBy(x => x.Email.Equals(user.Email)); var userResponse = UserLoginResponse.Create(user.Email, token, userInfo.Role.Equals(Role.ADMINISTRATOR)); return(Ok(new { success = true, data = userResponse })); } else { return(Ok(new { success = false, message = "The email and / or password entered is invalid.Please try again." })); } }
public IActionResult Post([FromBody] User user) { if (_accessManager.ValidateCredentials(user)) { return(Ok(_accessManager.GenerateToken(user))); } return(BadRequest(new { Error = "Erro ao gerar o token" })); }
public async Task <object> Login([FromBody] AccessCredentials credentials, [FromServices] AccessManager accessManager) { if (await accessManager.ValidateCredentialsAsync(credentials)) { return(accessManager.GenerateToken(credentials)); } return(new { Authenticated = false, Message = "Falha ao autenticar" }); }
public async Task <object> Post([FromBody] LoginDTO usuario) { if (await _accessManager.ValidateCredentials(usuario)) { return(_accessManager.GenerateToken(usuario)); } return(new { Authenticated = false, Message = "Falha ao autenticar" }); }
public void GenerateToken() { _tokenConfigurations.Audience = "ExemploAudience"; _tokenConfigurations.Issuer = "ExemploIssuer"; _tokenConfigurations.Seconds = 90; var accessManager = new AccessManager(_signingConfigurations, _tokenConfigurations, _loginValidator); var token = accessManager.GenerateToken(SetupTests.GetLogin()); Assert.True(token.Authenticated); Assert.IsType <string>(token.AccessToken); Assert.IsType <Token>(token); }
public async Task <IActionResult> Register([FromBody] RegisterViewModel registerViewModel) { if (!ModelState.IsValid) { NotifyModelStateErrors(); return(ResponseBadRequest()); } var user = _mapper.Map <User>(registerViewModel); var result = await _accessManager.CreateUser(user); if (result.Succeeded) { var token = await _accessManager.GenerateToken(user); return(Response(token)); } await AddIdentityErrors(result); return(ResponseBadRequest()); }
public object Login([FromBody] User usuario, [FromServices] AccessManager accessManager) { if (accessManager.ValidateCredentials(usuario)) { return(accessManager.GenerateToken(usuario)); } else { return(new { Authenticated = false, Message = "Falha ao autenticar" }); } }
public IActionResult Login([FromBody] User usuario) { if (_accessManager.ValidateCredentials(usuario)) { return(Ok(_accessManager.GenerateToken(usuario))); } else { return(Ok(new { Authenticated = false, Message = "Falha ao autenticar" })); } }
public IActionResult Login([FromBody] UserModel user, [FromServices] AccessManager accessManager) { CredentialModel credenciais = accessManager.ValidateCredentials(user).Result; if (credenciais.IsOk) { return(Ok(accessManager.GenerateToken(credenciais.User))); } else { return(Unauthorized(new { Error = "Acesso não autorizado" })); } }
public IActionResult Login([FromBody] User user, [FromServices] AccessManager accessManager) { if (accessManager.ValidateCredentials(user)) { var token = accessManager.GenerateToken(user); return(Ok(token)); } var authError = new { Authenticated = false, Message = "Falha na autenticação" }; return(BadRequest(authError)); }
public JsonResult Login([FromBody] User usuario, [FromServices] AccessManager accessManager) { if (accessManager.ValidateCredentials(usuario)) { JsonResult js = Json(accessManager.GenerateToken(usuario)); return(js); //return Json(accessManager.GenerateToken(usuario)); } else { return(Json(new { Authenticated = false, Message = "Falha ao autenticar" })); } }
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public async Task <object> Post([FromBody] Cliente usuario) #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member { if (await _accessManager.ValidateCredentials(usuario)) { return(_accessManager.GenerateToken(usuario)); } else { return(new { Authenticated = false, Message = "Falha ao autenticar" }); } }
public object Post( [FromBody] User usuario, [FromServices] AccessManager accessManager) { if (accessManager.ValidateCredentials(usuario)) { return(accessManager.GenerateToken(usuario)); } else { return(new { Authenticated = false, Message = "Authentication Failed." }); } }
public object Post( [FromBody]Login user, [FromServices]AccessManager accessManager) { if (accessManager.ValidateCredentials(user)) { return accessManager.GenerateToken(user); } else { return new { Authenticated = false, Message = "Falha ao autenticar" }; } }
public async Task <IActionResult> Autenticar([FromBody] AutenticarUsuarioRequest request) { try { var response = _serviceUsuario.AutenticarUsuario(request); if (response != null) { var token = _accessManager.GenerateToken(response); return(await ResponseAsync(token, _serviceUsuario)); } return(await ResponseAsync(response, _serviceUsuario)); } catch (Exception e) { return(await ResponseExceptionAsync(e)); } }
public object Post( [FromBody] AccessCredentials credenciais, [FromServices] AccessManager accessManager) { if (accessManager.ValidateCredentials(credenciais)) { return(accessManager.GenerateToken(credenciais)); } else { return(new { Authenticated = false, Message = "Falha ao autenticar" }); } }
public object Post( [FromBody] User userInput, [FromServices] AccessManager accessManager) { if (accessManager.ValidateCredentials(userInput)) { return(accessManager.GenerateToken(userInput)); } else { return(new { Authenticated = false, Message = "Lütfen kullanıcı adı ve şifrenizi kontrol edin" }); } }
public object Login([FromBody] User user, [FromServices] AccessManager accessManager) { var userAutentication = accessManager.ValidateCredentials(user); if (userAutentication.Authenticated) { return(accessManager.GenerateToken(userAutentication)); } else { return(new { Authenticated = false, Message = "Authentication failed!" }); } }
public ActionResult <object> Post( [FromBody] SignInUserModel usuario, [FromServices] AccessManager accessManager) { if (accessManager.ValidateLoginCredentials(usuario)) { ClaimsPrincipal claims = this.User; return(Ok(accessManager.GenerateToken(usuario, claims))); } else { return(Unauthorized(new { Authenticated = false, Message = "Falha ao autenticar" })); } }
public async Task <CustomResponse <Token> > GerarAcesso(User user, AccessManager accessManager) { var _result = new CustomResponse <Token>(); ClaimsIdentity identity = new ClaimsIdentity(new GenericIdentity(user.UserId.ToString(), "Login")); try { if (user.UserRoles.Any(x => x != null)) { if (user.UserRoles.Any(x => x.Role != null)) { foreach (Role role in user.UserRoles.Select(x => x.Role).ToList <Role>()) { var _roleFound = await _context.Set <Role>().Where(x => x.NameRole == role.NameRole).FirstOrDefaultAsync <Role>(); identity.AddClaim(new Claim(ClaimTypes.Role, _roleFound.NameRole)); } } } var Token = accessManager.GenerateToken(identity); _result.StatusCode = StatusCodes.Status202Accepted; _result.Message = "Acesso Autorizado"; _result.Result = Token; var acesso = new Acesso() { Data = DateTime.Now, User = user, IpAcesso = accessManager.IpAcess }; await _acessoService.Adicionar(acesso); } catch (Exception ex) { _result.Message = ex.Message; _result.StatusCode = StatusCodes.Status417ExpectationFailed; Error.LogError(ex); } return(_result); }
public object Post( [FromBody] User usuario, [FromServices] AccessManager accessManager) { usuario = Component.Login(usuario.Email, usuario.Password); if (usuario != null) { return(accessManager.GenerateToken(usuario)); } else { return(new { Authenticated = false, Message = "Falha ao autenticar" }); } }
public async Task <object> LogIn(FacebookSignInModel signInModel) { var isValidToken = await IsValidAccessToken(signInModel.AccessToken); if (!isValidToken) { return(new { Authenticated = false, Message = "Falha ao autenticar" }); } var userData = await GetUserData(signInModel.AccessToken); var user = await _userManager.FindByEmailAsync(userData.Email); if (user == null) { var appUser = new ApplicationUser { Id = Guid.NewGuid().ToString(), Email = userData.Email, UserName = userData.Email, NomeCompleto = userData.Name, LinkFoto = userData.FacebookPicture.Data.Url.AbsoluteUri, Cpf = signInModel.Cpf, Endereco = signInModel.Endereco, Telefone = signInModel.Telefone, }; var creationResult = await _userManager.CreateAsync(appUser); if (!creationResult.Succeeded) { return(new { Authenticated = false, Message = "Falha ao criar o usuário" }); } var createdUser = await _userManager.FindByEmailAsync(appUser.Email); if (signInModel.Tipo == "PRESTADOR") { Prestador prestador = new Prestador { Biografia = signInModel.Biografia, User = createdUser, Id = Guid.NewGuid() }; await _userManager.AddToRoleAsync(createdUser, Roles.Prestador); _identityDbContext.SaveChanges(); _applicationDbContext.Add <Prestador>(prestador); _applicationDbContext.Add <ServicoPrestado>( new ServicoPrestado() { Servico = _applicationDbContext.Find <Servico>(signInModel.Servico), Prestador = _applicationDbContext.Find <Prestador>(createdUser), Unidade = _applicationDbContext.Find <UnidadeDeCobranca>(signInModel.UnidadeDeCobranca), Preco = signInModel.Preco } ); _applicationDbContext.SaveChanges(); return("Succeeded"); } else if (signInModel.Tipo == "CLIENTE") { Contratante contratante = new Contratante { Id = Guid.NewGuid(), User = createdUser }; await _userManager.AddToRoleAsync(createdUser, Roles.Cliente); _identityDbContext.SaveChanges(); _applicationDbContext.Add <Contratante>(contratante); _applicationDbContext.SaveChanges(); return("Succeeded"); } return(new { Authenticated = true, Message = "Usuário criado com sucesso", AccessToken = _accessManager.GenerateToken(user).AccessToken }); } return(_accessManager.GenerateToken(user)); }