public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; //user.Claims.Add(new IdentityUserClaim<string> { ClaimType = "Eventos", ClaimValue = "Consultar" }); //user.Claims.Add(new IdentityUserClaim<string> { ClaimType = "Eventos", ClaimValue = "Gravar" }); //user.Claims.Add(new IdentityUserClaim<string> { ClaimType = "Eventos", ClaimValue = "Excluir" }); var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _userManager.AddClaimsAsync(user, new[] { new Claim("Eventos", "Consultar"), new Claim("Eventos", "Gravar"), new Claim("Eventos", "Excluir") }); // Cria o organizador usando o Id do user criado acima, assim não precisa criar um vínculo entre as tabelas AspNetUsers e Organizadores var organizador = new OrganizadorViewModel { Id = Guid.Parse(user.Id), Email = user.Email, Nome = model.Nome, CpfCnpj = model.CpfCnpj }; _organizadorAppService.Registrar(organizador); if (!OperacaoValida()) { await _userManager.DeleteAsync(user); return(View(model)); } _logger.LogInformation("User created a new account with password."); //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); //await _emailSender.SendEmailAsync(model.Email, "Confirm your email", // $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { IdentityUser user = new IdentityUser { UserName = Input.Email, Email = Input.Email }; IdentityResult result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { List <System.Security.Claims.Claim> claims = new List <System.Security.Claims.Claim>() { new System.Security.Claims.Claim("Eventos", "Ler"), new System.Security.Claims.Claim("Eventos", "Gravar") }; await _userManager.AddClaimsAsync(user, claims); _logger.LogInformation("User created a new account with password."); OrganizadorViewModel organizador = new OrganizadorViewModel { Id = Guid.Parse(user.Id), Email = user.Email, Nome = Input.Nome, Cpf = Input.Cpf }; _organizadorAppService.Registrar(organizador); string code = await _userManager.GenerateEmailConfirmationTokenAsync(user); string callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } foreach (IdentityError error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var user = new IdentityUser { UserName = Input.Email, Email = Input.Email }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { var organizador = new OrganizadorViewModel { Id = Guid.Parse(user.Id), Email = user.Email, Nome = Input.Nome, CPF = Input.CPF }; _organizadorAppService.Registrar(organizador); if (!OperacaoValida()) { await _userManager.DeleteAsync(user); return(Page()); } _logger.LogInformation("O usuário criou uma nova conta com senha."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirme seu email", $"Por favor, confirme sua conta <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; user.Claims.Add(new IdentityUserClaim <string> { ClaimType = "Eventos", ClaimValue = "Ler" }); user.Claims.Add(new IdentityUserClaim <string> { ClaimType = "Eventos", ClaimValue = "Gravar" }); var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var organizador = new OrganizadorViewModel { Id = Guid.Parse(user.Id), Email = user.Email, Nome = model.Nome, CPF = model.CPF }; _organizadorAppService.Registrar(organizador); if (!OperacaoValida()) { await _userManager.DeleteAsync(user); return(View(model)); } // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=532713 // Send an email with this link //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //var callbackUrl = Url.Action(nameof(ConfirmEmail), "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); //await _emailSender.SendEmailAsync(model.Email, "Confirm your account", // $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>"); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation(3, "User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; //user.Claims.Add(new IdentityUserClaim<string> { ClaimType = "Eventos", ClaimValue = "Ler" }); //user.Claims.Add(new IdentityUserClaim<string> { ClaimType = "Eventos", ClaimValue = "Gravar" }); var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var organizador = new OrganizadorViewModel { Id = Guid.Parse(user.Id), Nome = model.Nome, Email = user.Email, Cpf = model.CPF }; _organizadorAppService.Registrar(organizador); if (!OperacaoValida()) { await _userManager.DeleteAsync(user); return(View(model)); } _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var organizador = new OrganizadorViewModel { Id = Guid.Parse(user.Id), Email = user.Email, Nome = model.Nome, CPF = model.CPF }; _organziadorAppService.Registrar(organizador); if (!OperacaoValida()) { await _userManager.DeleteAsync(user); return(View(model)); } await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation(3, "User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public void Registrar(OrganizadorViewModel organizadorViewModel) { var registroCommand = Mapper.Map <RegistrarOrganizadorCommand>(organizadorViewModel); _bus.SendCommand(registroCommand); }
public void Registrar(OrganizadorViewModel organizadorViewModel) { var registroCommand = _mapper.Map <RegistrarOrganizadorCommand>(organizadorViewModel); _mediator.EnviarComando(registroCommand); }
void IOrganizadorAppService.Registrar(OrganizadorViewModel organizadorViewModel) { var registroCommand = _mapper.Map <RegistrarOrganizadorCommand>(organizadorViewModel); _bus.SendCommand(registroCommand); }
// Identity: Video 16 Eduardo Pires - Tb substitui input por model public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var user = new ApplicationUser { UserName = Input.Email, Email = Input.Email }; // Exatamente aqui o usuário será criado var result = await _userManager.CreateAsync(user, Input.Senha); if (result.Succeeded) { await _userManager.AddClaimAsync(user, new Claim("Eventos", "Ler")); await _userManager.AddClaimAsync(user, new Claim("Eventos", "Gravar")); // Identity: Video 16 Eduardo Pires // Atrelei o guid do usuário do Identity ao organizador // Este ponto é responsável por incluir o organizador no banco com o mesmo Id criado pelo Identity var organizador = new OrganizadorViewModel { Id = Guid.Parse(user.Id), Email = user.Email, Nome = Input.Nome, CPF = Input.CPF }; // Identity: Video 16 Eduardo Pires - Este ponto é responsável por incluir o organizador no banco com o mesmo Id criado pelo Identity _organizadorAppService.Registrar(organizador); // Identity: Video 16 Eduardo Pires if (!OperacaoValida()) { await _userManager.DeleteAsync(user); return(Page()); } _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); // Identity: Correção da rota do identity var callbackUrl = Url.Page( "/Identity/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); // Identity: Video 16 Eduardo Pires -Troquei input por model - 03022019 /* ssbcvp - voltar aqui - Envio de email ainda não está funcionando * await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", * $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); */ await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }