public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var user = new UniPortalUser { UserName = Input.Username, Title = Input.Title, FirstName = Input.FirstName, LastName = Input.LastName, //TODO make a service or constant for emails Email = Input.FirstName + "." + Input.LastName + "@student.uniportal.com", Age = Input.Age, Address = Input.Address, }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); await _userManager.AddToRoleAsync(user, "Student"); //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //var callbackUrl = Url.Page( // "/Account/ConfirmEmail", // pageHandler: null, // values: new { userId = user.Id, code = code }, // protocol: Request.Scheme); // //await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", // $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <bool> AddUserTo(string semesterId, UniPortalUser user) { try { await this.studentCoursesRepository.AddAsync(new StudentSemester { StudentId = user.Id, SemesterId = semesterId, PaidOn = DateTime.UtcNow }); return(true); } catch { return(false); } }
public async Task <bool> Join(UniPortalUser user, string courseId) { var course = this.coursesRepository.GetById(courseId); try { await studentCoursesRepository.AddAsync(new StudentCourse { StudentId = user.Id, CourseId = courseId, }); await studentCoursesRepository.SaveChangesAsync(); return(true); } catch { return(false); } }
public Task <IdentityResult> AddToRoleAsync(UniPortalUser user, string role) => this.userManager.AddToRoleAsync(user, role);