public async Task <ActionResult> Register(EducationRegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FavoriteColor = model.FavoriteColor }; var result = await userManager.CreateAsync(user, model.Password); if (result.Succeeded) { 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() { EducationRegisterViewModel model = new EducationRegisterViewModel(); model.FavoriteColors = Constants.FavoriteColors; return(View(model)); }
public async Task <ActionResult> CreateLocalAccountPost(EducationRegisterViewModel model) { var tenantId = User.GetTenantId(); var graphServiceClient = await AuthenticationHelper.GetGraphServiceClientAsync(); IGraphClient graphClient = new MSGraphClient(graphServiceClient); var user = await graphClient.GetCurrentUserAsync(); var tenant = await graphClient.GetTenantAsync(tenantId); model.Email = user.Mail ?? user.UserPrincipalName; model.FavoriteColors = Constants.FavoriteColors; // Create a new local user var localUser = new ApplicationUser { Email = model.Email, UserName = model.Email, FavoriteColor = model.FavoriteColor }; var result = await userManager.CreateAsync(localUser); if (!result.Succeeded) { AddErrors(result); return(View(model)); } // Update the local user await applicationService.UpdateLocalUserAsync(localUser, user, tenant); SetCookiesForO365User(user.GivenName + " " + user.Surname, user.Mail); return(RedirectToAction("Index", "Schools")); }
// // GET: /Link/CreateLocalAccount public async Task <ActionResult> CreateLocalAccount() { var client = await AuthenticationHelper.GetActiveDirectoryClientAsync(); var aadUser = await client.Me.ExecuteAsync(); var viewModel = new EducationRegisterViewModel { FirstName = aadUser.GivenName, LastName = aadUser.Surname, Email = aadUser.UserPrincipalName, FavoriteColors = Constants.FavoriteColors }; return(View(viewModel)); }
public async Task <ActionResult> CreateLocalAccountPost(EducationRegisterViewModel model) { if (!ModelState.IsValid) { return(View(model)); } // Create a new local user var localUser = new ApplicationUser { Email = model.Email, UserName = model.Email, FavoriteColor = model.FavoriteColor }; var result = await userManager.CreateAsync(localUser, model.Password); if (!result.Succeeded) { AddErrors(result); return(View(model)); } // Update the local user var tenantId = User.GetTenantId(); var activeDirectoryClient = await AuthenticationHelper.GetActiveDirectoryClientAsync(); IGraphClient graphClient = new AADGraphClient(activeDirectoryClient); var user = await graphClient.GetCurrentUserAsync(); var tenant = await graphClient.GetTenantAsync(tenantId); user.GivenName = model.FirstName; user.Surname = model.LastName; await applicationService.UpdateLocalUserAsync(localUser, user, tenant); // return(RedirectToAction("Index")); }