public async Task <IActionResult> OnPostAsync() { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(Input.Email); if (user == null) { // Don't reveal that the user does not exist return(RedirectToPage("./ForgotPasswordConfirmation")); } // For more information on how to enable account confirmation and password reset please // visit https://go.microsoft.com/fwlink/?LinkID=532713 var code = await _userManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = Url.Page( "/Account/ResetPassword", pageHandler: null, values: new { code }, protocol: Request.Scheme); var response = await MSLEmailHandler.SendPasswordResetEmail(user, callbackUrl); return(RedirectToPage("./ForgotPasswordConfirmation")); } return(Page()); }
public async Task <IActionResult> ResendConfirmation(string email) { var user = await _userManager.FindByEmailAsync(email); if (user != null) { var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = user.Id, code = code }, protocol: Request.Scheme); Response response = await MSLEmailHandler.SendConfirmationEmail(user, callbackUrl); if (response.StatusCode == System.Net.HttpStatusCode.Accepted) { TempData["ResentConfirmationSuccess"] = true; } else { TempData["ResentConfirmationSuccess"] = false; } } return(RedirectToPage("/Account/Login", new { area = "Identity" })); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/Home/Success"); if (ModelState.IsValid) { bool eligibleUser = false; string firstName = ""; string lastName = ""; int studentId = 0; //int eligibleId = 0; // Check user's email is in the eligible list or not var eligibleStudent = await _context.EligibleStudent.ToListAsync(); foreach (EligibleStudent student in eligibleStudent) { if ((student.StudentEmail).ToUpper() == (Input.Email).ToUpper()) { eligibleUser = true; firstName = student.FirstName; lastName = student.LastName; studentId = student.StudentID; //eligibleId = student.Id; TempData["UserEmail"] = student.StudentEmail; //Set this to allow for resending confirmation later break; } } if (eligibleUser) { var user = new ApplicationUser { UserName = Input.Email, Email = Input.Email, FirstName = firstName, LastName = lastName, StudentId = studentId, ActiveStatus = "Unverified", Role = "Student" }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); //Assign the new user to the student role var addRole = await _userManager.AddToRoleAsync(user, "Student"); if (addRole.Succeeded) { // Write log for get key action Logs newLog = new Logs() { StudentId = studentId, StudentEmail = Input.Email, Action = "Register", Product = "", ProductKey = "", }; _context.Add(newLog); _context.SaveChanges(); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); var response = await MSLEmailHandler.SendConfirmationEmail(user, callbackUrl); ViewData["UserEmail"] = user.Email; return(LocalRedirect(returnUrl)); } foreach (var error in addRole.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } else { ModelState.AddModelError(string.Empty, "Sorry, your e-mail address is not eligible to create an account. Please contact the administrator for permission."); } } // If we got this far, something failed, redisplay form return(Page()); }