Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 };
- var result = await _userManager.CreateAsync(user, Input.Password);
- if (result.Succeeded)
- {
- _logger.LogInformation("User created a new account with password.");
- var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
- var 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);
- }
- foreach (var error in result.Errors)
- {
- ModelState.AddModelError(string.Empty, error.Description);
- }
- //Quiero añadir el rol del usuario si no hay usuarios SuperAdmin si hay usuarios sera User.
- //método que devuelva true o false solo necesito escribir el usuario y el rol que tiene en la tabla
- LUsuarios LUsers = new LUsuarios();
- int countUsers = await LUsers.CountUsers();
- if (countUsers == 0)
- {
- var roleUser = new ApplicationUserRole { UserId = user.Id, RoleId = 1 };
- }
- else
- {
- var roleUser0 = new ApplicationUserRole { UserId = user.Id, RoleId = 4 };
- }
- }
- // If we got this far, something failed, redisplay form
- return Page();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement