public ActionResult Register(PreRegisterViewModel model) { if (ModelState.IsValid) { Suscriptor suscriptor = new Suscriptor() { nombres = model.Names, apellidos = model.Lastnames, correoElectronico = model.Email, numeroTelefonico = model.PhoneNumber, emailConfirmation = false, SuscriptorGUID = model.getSuscriptorGuid().ToString() }; _entities.Suscriptor.Add(suscriptor); _entities.SaveChanges(); EmailHelper emailSender = new EmailHelper(model.Email, HttpContext, suscriptor.SuscriptorGUID); /////send the email in other worker thread emailSender.SendEmailAsync(); return(View("EmailConfirmationSended", model)); } // If we got this far, something failed, redisplay form return(View(model)); }
public IActionResult PreInscription(PreRegisterViewModel model) { if (ModelState.IsValid) { var result = _userService.ValidateRegister(model.UserName, model.RoleId); if (result.Result) { var user = new User() { UserName = model.UserName, RoleId = model.RoleId }; _userService.Create(user); return(Redirect("/Home/Index")); } else { ModelState.AddModelError(string.Empty, result.ErrorCode); model.Roles = new SelectList(_roleTypeService.GetAll(), "Id", "Name"); return(View(nameof(PreInscription), model)); } } model.Roles = new SelectList(_roleTypeService.GetAll(), "Id", "Name"); return(View(nameof(PreInscription), model)); }
public IActionResult PreInscription() { var viewModel = new PreRegisterViewModel(); viewModel.Roles = new SelectList(_roleTypeService.GetAll(), "Id", "Name"); return(View(viewModel)); }
public async Task <IActionResult> PreRegister(PreRegisterViewModel model, String RoleName) { model.Roles = _roleManager.Roles.ToList(); model.RoleName = RoleName; if (ModelState.IsValid) { model.Email = model.Email.Trim(); //Если такой пользователь уже есть, ругаемся User user = await _userManager.FindByNameAsync(model.Email); if (user != null) { ModelState.AddModelError(string.Empty, "Пользователь с таким именем уже существует!"); } else { user = new User { Email = model.Email, UserName = model.Email, PhoneNumber = String.Empty }; var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); // добавляем Приглашённого в таблицу Invities SqlParameter[] param = { new SqlParameter("@Email", model.Email), new SqlParameter("@TheToken", code), new SqlParameter("@RoleName", RoleName) }; Int32 yes = await _appContext.Database.ExecuteSqlRawAsync("Exec AddInvitee @Email, @TheToken, @RoleName", param); if (yes != 1) //Если он не добавился, ругаемся { ModelState.AddModelError(string.Empty, "Не удалось добавить Приглашённого в таблицу Invities"); } else // Всё в порядке... { // ...создаем ссылку для подтверждения... var callbackUrl = Url.Action("Register", "Account", new { code = code }, protocol: HttpContext.Request.Scheme); //...и отправляем письмо EmailService emailService = new EmailService(); await emailService.SendEmailAsync(model.Email, "Школьная библиотека: Приглашение для регистрации в качестве пользователя системы", $"Для регистрации личного кабинета на сайте schl.dialog-el.ru перейдите по ссылке: <a href='{callbackUrl}'>Регистрация</a>"); return(View("DisplayEmail")); } } } return(View(model)); }
public IActionResult PreRegister(PreRegisterViewModel model) { model.Roles = _roleManager.Roles.ToList(); return(View(model)); }
public ActionResult Register() { PreRegisterViewModel model = new PreRegisterViewModel(); return(View(model)); }
//[AllowAnonymous] //[ValidateAntiForgeryToken] public async Task <IActionResult> Register([FromBody] PreRegisterViewModel preReg) { var role = preReg.Role; RegisterViewModel model = new RegisterViewModel(); model.Email = preReg.Email; // Make sure that our password contains upper case letter do { model.Password = _identityService.GeneratePassword(); } while (!model.Password.Any(p => char.IsUpper(p))); //model.Password = "******"; // Check if everything is valid if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); // Assigning the user to the role Carsale var roleResult = await _userManager.AddToRoleAsync(user, role); if (roleResult.Succeeded) { // Assigning the user to its claim var claimResult = await _userManager.AddClaimAsync(user, new System.Security.Claims.Claim(role, role)); if (claimResult.Succeeded) { if (role == "Carsale") { // Change the carsale to accepted in database // TODO!! check if these fail... if something fails on the way // we need to remove the carsale from the identity database var carSale = _carSaleService.GetCarSaleByEmail(model.Email); var res = _carSaleService.AcceptCarSale(carSale.ID); var carSales = _carSaleService.GetAdminCarSales(); // Send email to the user to notify of new password var notificationEmail = _emailSender.CreateCarSaleEmail(model); _emailSender.SendEmail(notificationEmail); return(CreatedAtAction("Registered", carSales)); } else if (role == "Admin") { return(CreatedAtAction("Registered", null)); } } } } else { return(BadRequest(ModelState)); } } // If we got this far the registration model is not valid return(BadRequest(ModelState)); }