public async Task <ActionResult> Registrar(RegistrarUsuarioViewModel registrar) { if (!ModelState.IsValid) { return(Result(ModelState)); } var usuario = new IdentityUser() { UserName = registrar.Login, }; var result = await _userManager.CreateAsync(usuario, registrar.Senha); if (result.Succeeded) { return(Result("Regitro incluido com sucesso")); } foreach (var erro in result.Errors) { NotificarErro($"{erro.Code}-{erro.Description}"); } return(Result(registrar)); }
public async Task <IActionResult> RegistrarNovoUsuario(RegistrarUsuarioViewModel model, string returnUrl) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new UserApplication { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { _logger.LogInformation("Usuário criou uma nova conta com senha"); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("Usuário com acesso com a conta criada"); return(RedirectToLocal(returnUrl)); } AddErros(result); } return(View(model)); }
public async Task RegistrarUsuario(RegistrarUsuarioViewModel model) { var body = new StringContent(JsonSerializer.Serialize(model), Encoding.UTF8, "application/json"); using (var Response = await Client.PostAsync("RegistrarTreinador", body)) { if (Response.IsSuccessStatusCode) { } } }
public ActionResult <AvisoLoginViewModel> Registrar([FromBody] RegistrarUsuarioViewModel usuario) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values.SelectMany(e => e.Errors))); } var avisoLogin = _app.Registrar(usuario).GetAwaiter().GetResult(); return(Ok(avisoLogin)); }
public async Task <ActionResult> Registrar(RegistrarUsuarioViewModel registrarUsuario) { if (!ModelState.IsValid) { return(Retorno(ModelState)); } var user = new IdentityUser { UserName = registrarUsuario.Email, Email = registrarUsuario.Email, EmailConfirmed = true }; var resultUser = await _userManager.CreateAsync(user, registrarUsuario.Password); try { if (resultUser.Succeeded) { await _signInManager.SignInAsync(user, false); var ong = registrarUsuario.Ong; ong.IdUsuario = user.Id; ong.Usuario = user; var resultOng = _ongService.Adicionar(ong); if (!resultOng) { await _userManager.DeleteAsync(user); } else { return(Retorno(await GerarToken(registrarUsuario.Email))); } } foreach (var erro in resultUser.Errors) { NotificarErro(erro.Description); } } catch (Exception e) { NotificarErro("Comportamento Inesperado"); } return(Retorno()); }
public RegistrarUsuarioPage() { try { InitializeComponent(); NavigationPage.SetHasNavigationBar(this, false); UsuarioRepo = new UsuarioRepository(); BindingContext = new RegistrarUsuarioViewModel(UsuarioRepo); ViewModel.NovoUsuario = new Models.Usuario(); } catch (System.Exception ex) { var e = ex.Message; } }
/// <summary> /// Definir bindings /// </summary> private void DefinirBindings() { // Define o Binding Context this.contexto = new RegistrarUsuarioViewModel(); this.BindingContext = this.contexto; // Bindings this.entryUsuario.SetBinding(Entry.TextProperty, nameof(this.contexto.Usuario)); this.borderUsuario.SetBinding( SfBorder.BorderColorProperty, new Binding( nameof(this.entryUsuario.IsFocused), converter: new ErrorValidationColorConverter(), converterParameter: this.entryUsuario, source: this.entryUsuario)); this.entryEmail.SetBinding(Entry.TextProperty, nameof(this.contexto.Email)); this.borderEmail.SetBinding( SfBorder.BorderColorProperty, new Binding( nameof(this.entryEmail.IsFocused), converter: new ErrorValidationColorConverter(), converterParameter: this.entryEmail, source: this.entryEmail)); this.labelValidationEmail.SetBinding( Label.IsVisibleProperty, new Binding( nameof(this.entryEmail.IsFocused), converter: new StringToBooleanConverter(), converterParameter: this.entryEmail, source: this.entryEmail)); this.labelIconValidationEmail.SetBinding( Label.IsVisibleProperty, new Binding( nameof(this.entryEmail.IsFocused), converter: new StringToBooleanConverter(), converterParameter: this.entryEmail, source: this.entryEmail)); this.borderSenha.SetBinding(SfBorder.BorderColorProperty, new Binding(nameof(this.entrySenha.IsFocused), converter: new BooleanToColorConverter(), converterParameter: 3, source: this.entrySenha)); this.entrySenha.SetBinding(Entry.TextProperty, nameof(this.contexto.Senha)); this.borderConfirmarSenha.SetBinding(SfBorder.BorderColorProperty, new Binding(nameof(this.entryConfirmarSenha.IsFocused), converter: new BooleanToColorConverter(), converterParameter: 3, source: this.entryConfirmarSenha)); this.entryConfirmarSenha.SetBinding(Entry.TextProperty, nameof(this.contexto.ConfirmarSenha)); this.btnRegistrar.SetBinding(SfButton.CommandProperty, nameof(this.contexto.RegistrarCommand)); this.btnLogin.SetBinding(SfButton.CommandProperty, nameof(this.contexto.LoginCommand)); this.btnRegistrarWeb.SetBinding(SfButton.CommandProperty, nameof(this.contexto.RegistrarWebCommand)); }
public async void Usuario_RealizarLogin_DeveFalharPorNaoTerCadastro() { // Arrange var obj = new RegistrarUsuarioViewModel { Email = "*****@*****.**", Senha = "Teste@123", SenhaConfirmacao = "Teste@123" }; string strData = JsonConvert.SerializeObject(obj); var contentData = new StringContent(strData, Encoding.UTF8, "application/json"); // Act var postResponse = await _testsFixture.Client.PostAsync("/api/identidade/autenticar", contentData); // Assert Assert.Equal(HttpStatusCode.BadRequest, postResponse.StatusCode); }
public async void Usuario_RealizarCadastroComSenhaFraca_DeveRetornarMensagemDeErro() { //Arrange var obj = new RegistrarUsuarioViewModel { Email = "*****@*****.**", Senha = "teste", SenhaConfirmacao = "teste" }; string strData = JsonConvert.SerializeObject(obj); var contentData = new StringContent(strData, Encoding.UTF8, "application/json"); //Act var postResponse = await _testsFixture.Client.PostAsync("/api/identidade/nova-conta", contentData); //Assert Assert.Equal(HttpStatusCode.BadRequest, postResponse.StatusCode); }
public async Task <AvisoLoginViewModel> Registrar(RegistrarUsuarioViewModel regUsuario) { var usuario = await _repo.Registrar(regUsuario.Nome, regUsuario.Email, regUsuario.Senha, regUsuario.Role); var avisoLogin = new AvisoLoginViewModel() { Descricao = "Problemas ao registrar usuário", Token = null }; if (usuario != null) { var token = GerarToken(usuario); avisoLogin.Descricao = "Usuário registrado com sucesso!"; avisoLogin.Token = token; } return(avisoLogin); }
public async Task <UsuarioDto> RegistrarNovoUsuario(RegistrarUsuarioViewModel usuario) { try { var json = JsonConvert.SerializeObject(usuario); var content = new StringContent(json, Encoding.UTF8, "application/json"); var resposta = await client.PostAsync("http://webslave.azurewebsites.net/api/Account/Register", content); var respostaContent = await resposta.Content.ReadAsStringAsync(); if (resposta.IsSuccessStatusCode) { UsuarioDto novoUsuario = JsonConvert.DeserializeObject <UsuarioDto>(respostaContent); return(novoUsuario); } return(null); } catch (Exception e) { return(null); } }
public async void Usuario_RealizarCadastro_DeveExecutarComSucesso() { //Arrange var obj = new RegistrarUsuarioViewModel { Email = "*****@*****.**", Senha = "Teste@123", SenhaConfirmacao = "Teste@123" }; string strData = JsonConvert.SerializeObject(obj); var contentData = new StringContent(strData, Encoding.UTF8, "application/json"); _testsFixture.UsuarioEmail = obj.Email; _testsFixture.UsuarioSenha = obj.Senha; //Act var postResponse = await _testsFixture.Client.PostAsync("/api/identidade/nova-conta", contentData); //Assert Assert.Equal(HttpStatusCode.OK, postResponse.StatusCode); }
public async Task <ActionResult> Registrar([FromBody] RegistrarUsuarioViewModel registrarUsuarioVM) { if (!ModelState.IsValid) { return(BadRequest()); } var user = new IdentityUser { UserName = registrarUsuarioVM.Email, Email = registrarUsuarioVM.Email, EmailConfirmed = true }; var result = await _userManager.CreateAsync(user, registrarUsuarioVM.Senha); if (result.Succeeded) { return(Ok(registrarUsuarioVM)); } return(BadRequest(result.Errors)); }
private async void OnBtnFinalizarClicked(object sender, EventArgs e) { if (EntryConfirmarSenha.Text != EntrySenha.Text) { await DisplayAlert("Erro", MensagensErro.SENHA_CONFIRMACAO_ERRADA, "Ok"); EntryConfirmarSenha.TextColor = Color.Red; EntrySenha.TextColor = Color.Red; return; } UsuarioSingleton.Senha = EntrySenha.Text; UsuarioSingleton.Email = EntryEmail.Text; var apiUsuario = new RestUsuario(); var model = new RegistrarUsuarioViewModel() { Nome = UsuarioSingleton.Nome, Funcao = "Usuario", Email = UsuarioSingleton.Email, Password = UsuarioSingleton.Senha, ConfirmPassword = UsuarioSingleton.Senha }; var resultadoUsuario = await apiUsuario.RegistrarNovoUsuario(model); var apiVeiculo = new RestVeiculo(); var modelVeiculo = new VeiculoDto() { Placa = VeiculoSingleton.Placa, Cor = VeiculoSingleton.Cor, Marca = VeiculoSingleton.Marca, Modelo = VeiculoSingleton.Modelo, UsuarioId = resultadoUsuario.Id }; var resultadoVeiculo = await apiVeiculo.PostVeiculo(modelVeiculo); var apiLavagem = new RestLavagem(); //TODO: Pegar a cidade dinamicamente var modelLavagem = new LavagemDto() { ValorEmReais = LavagemSingleton.ValorEmReais, Longitude = LavagemSingleton.Longitude, Latitude = LavagemSingleton.Latitude, Cidade = "Santa Cruz do Sul", DiaHorario = LavagemSingleton.DiaHorario, Endereco = LavagemSingleton.Endereco, LocalDeRecebimento = LavagemSingleton.LocalDeRecebimento, TipoLavagemId = LavagemSingleton.TipoLavagemId, TrocoEmReais = LavagemSingleton.TrocoEmReais, UsuarioId = resultadoUsuario.Id, VeiculoId = resultadoVeiculo.Id, StatusId = StatusDisponiveis.AGENDADA, Adicionais = LavagemSingleton.Adicionais }; var resultadoLavagem = await apiLavagem.PostLavagem(modelLavagem); await DisplayAlert("Erro", resultadoLavagem, "Ok"); //TODO: Melhorar essas verificações if (resultadoUsuario.Id != null && resultadoVeiculo.Cor != null && resultadoLavagem != null) { var resultadoLogin = await apiUsuario.Logar(new Login() { Password = UsuarioSingleton.Senha, Username = UsuarioSingleton.Email }); if (resultadoLogin != null) { var dbToken = new TokenDatabase(); dbToken.AddToken(resultadoLogin); TokenSingleton.Token = resultadoLogin.AccessToken; var page = new IndexPage(); Application.Current.MainPage = page; } } else { await DisplayAlert("Erro", resultadoLavagem, "Ok"); } }
public IActionResult RegistrarUsuario(RegistrarUsuarioViewModel model) { return(View()); }