public async Task <IActionResult> ArtistRegister(ArtistRegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { Name = model.Name, UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713 // Send an email with this link //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //var callbackUrl = Url.Action("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 _userManager.AddToRoleAsync(user, "ARTIST"); 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> ArtistRegister(ArtistRegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { if (!db.Genres.Any(g => g.Name == model.Genre)) { db.Add(new Genre { Name = model.Genre }); db.SaveChanges(); } var user = new ApplicationUser { Name = model.Name, UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _signInManager.SignInAsync(user, isPersistent : false); return(RedirectToAction("ArtistIndex", "Events")); } } return(View(model)); }
public async Task <IActionResult> ArtistRegister(ArtistRegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { Name = model.Name, UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _signInManager.SignInAsync(user, isPersistent : false); return(RedirectToLocal(returnUrl)); } AddErrors(result); } return(View(model)); }
public async Task <ActionResult> RegisterArtist(ArtistRegisterViewModel model) { if (ModelState.IsValid) { bool ajaxValidationResult = CaptchaControl.AjaxValidate (model.CaptchaId, model.CaptchaInput, model.InstanceId); if (ajaxValidationResult) { try { Artist artist = new Artist() { ContactManName = model.ContactManName, ContactManPhone = model.ContactManPhone, ParticipateInAuction = true }; var user = new PaskolUser { RegisteredDate = DateTime.Now, UserName = model.Name, Email = model.Email, Artist = artist, UserType = UserType.Artist, Status = UserStatus.WaitingNewArtist }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { // assign user artist to role var roleResoult = await UserManager.AddToRoleAsync(user.Id, UserType.Artist.ToString()); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // Add to confirmation waiting _conSrv.Add(new Confirmation() { ConfirmType = ConfirmType.NewArtist, DateUpdate = DateTime.Now, EntityId = user.Id, Name = user.UserName }); // email to artist EmailService.RegisterArtist(model.Email, model.Name, model.Password); await _pdfService.ArtistPermissionAgreementAsync(DateTime.Now, user.UserName, user.Email, user.Id, WebConf.FSBaseRoute); return(Json(new { suceeded = true, UserName = model.Name })); } AddErrors(result); } catch (Exception ex) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "ארעה שגיאה אנא פנה לתמיכה")); } } else { // handle not valid captcha _errors.Add(new KeyValuePair <string, string>("Captcha", "")); } } return(Json(new { suceeded = false, errors = _errors })); }