public async Task <ActionResult> Register(RegisterAdministratorViewModel model) { ApplicationDbContext appDb = new ApplicationDbContext(); if (ModelState.IsValid) { // create a administratortable entry and a user table entry var administrator = new Administrator { UserName = model.Email, Email = model.Email }; var result = await UManager.CreateAsync(administrator, model.Password); if (result.Succeeded) { var addedToRole = await UManager.AddToRoleAsync(administrator.Id, "Administrator"); if (addedToRole.Succeeded) { return(RedirectToAction("Login")); } } AddErrors(result); } return(View(model)); }
public async Task <IActionResult> RegisterAdministrator(RegisterAdministratorViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var currentuser = await _userManager.GetUserAsync(HttpContext.User); var firma = _context.Firmy.FirstOrDefault(f => f.UserId == currentuser.Id); var user = new ApplicationUser { UserName = model.Email, Email = model.Email, Pracownik = new Pracownik { Stanowisko = "Administrator", Imie = model.Imie, Nazwisko = model.Nazwisko, Ulica = model.Ulica, Kod = model.Kod, Miasto = model.Miasto, Telefon = model.Telefon, DataUrodz = model.DataUrodz, DataZatru = model.DataZatru, DataKonUmowy = model.DataKonUmowy, NrDowoduOsob = model.NrDowoduOsob, Aktywny = model.Aktywny, Firma = firma // IdFirma = model.IdFirma } }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, "Admin"); // 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 ActionResult RegisterAdministrator(RegisterAdministratorViewModel viewModel) { return(RedirectToAction("Index", "Home")); }
public ActionResult RegisterAdministrator() { var viewModel = new RegisterAdministratorViewModel(); return(View(viewModel)); }