public async Task<ActionResult> Register(RegisterViewModel model) { String fotoId; PhotoInfo fotoInfo; if (ModelState.IsValid) { if (!bs.IsValidKey(model.Key)) return RedirectToAction("Login"); var user = new ApplicationUser { Naam = model.Naam,Voornaam = model.Voornaam }; Uitnodiging u = bs.GetUitnodigingByKey(model.Key); user.Email = u.EmailUitgenodigde; user.UserName = u.EmailUitgenodigde; if (model.Afbeelding != null) { try { fotoId = flickr.UploadPicture(model.Afbeelding.InputStream, model.Email, model.Email, "", "", false, false, false, ContentType.Photo, SafetyLevel.Safe, HiddenFromSearch.Hidden); flickr.PhotosetsAddPhoto(ConfigurationManager.AppSettings.Get("FlickrGebruikersAlbumId"), fotoId); fotoInfo = flickr.PhotosGetInfo(fotoId); user.Afbeelding = fotoInfo.MediumUrl; } catch (Exception ex) { return RedirectToAction("Index", "Home"); } } var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { UserManager.SetLockoutEnabled(user.Id, false); UserManager.AddToRole(user.Id, "User"); bs.SetUitnodigingGebruikt(u.Id, user.Email); await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return RedirectToAction("Index", "Home"); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult Register(string Key) { RegisterViewModel rVM = new RegisterViewModel(); if (Key == null) return RedirectToAction("Login"); if (!bs.IsValidKey(Key)) return View("OngeldigeSleutel"); rVM.Email = bs.GetUitnodigingByKey(Key).EmailUitgenodigde; rVM.Key = Key; return View(rVM); }