private void InitializeFields() { this.user = new CinemaWorldUser { Id = "1", Gender = Gender.Male, UserName = "******", FullName = "Pesho Peshov", Email = "*****@*****.**", PasswordHash = "123456", }; this.firstNews = new News { Id = 1, Title = "First news title", Description = "First news description", ShortDescription = "First news short description", ImagePath = TestImageUrl, UserId = this.user.Id, ViewsCounter = 30, IsUpdated = false, }; this.firstNewsComment = new NewsComment { NewsId = this.firstNews.Id, Content = "Test comment here", UserId = this.user.Id, }; }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl ??= this.Url.Content("~/"); this.ExternalLogins = (await this.signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (this.ModelState.IsValid) { Enum.TryParse <Gender>(this.Input.SelectedGender, out Gender gender); var user = new CinemaWorldUser { UserName = this.Input.Username, Email = this.Input.Email, FullName = this.Input.FullName, Gender = gender, }; var result = await this.userManager.CreateAsync(user, this.Input.Password); if (result.Succeeded) { this.logger.LogInformation("User created a new account with password."); await this.userManager.AddToRoleAsync(user, GlobalConstants.UserRoleName); var code = await this.userManager.GenerateEmailConfirmationTokenAsync(user); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = this.Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = user.Id, code = code }, protocol: this.Request.Scheme); await this.emailSender.SendEmailAsync( this.Input.Email, "Confirm your email", htmlMessage : $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); if (this.userManager.Options.SignIn.RequireConfirmedAccount) { return(this.RedirectToPage("RegisterConfirmation", new { email = this.Input.Email })); } else { await this.signInManager.SignInAsync(user, isPersistent : false); return(this.LocalRedirect(returnUrl)); } } foreach (var error in result.Errors) { this.ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(this.Page()); }
private async Task LoadAsync(CinemaWorldUser user) { var userName = await this.userManager.GetUserNameAsync(user); var phoneNumber = await this.userManager.GetPhoneNumberAsync(user); this.Username = userName; this.Input = new IndexInputModel { PhoneNumber = phoneNumber, }; }
private async Task LoadAsync(CinemaWorldUser user) { var email = await this.userManager.GetEmailAsync(user); this.Email = email; this.Input = new EmailInputModel { NewEmail = email, }; this.IsEmailConfirmed = await this.userManager.IsEmailConfirmedAsync(user); }
private void InitializeFields() { this.user = new CinemaWorldUser { Id = "1", Gender = Gender.Male, UserName = "******", FullName = "Pesho Peshov", Email = "*****@*****.**", PasswordHash = "123456", }; this.firstDirector = new Director { FirstName = "Peter", LastName = "Kirilov", }; this.firstMovie = new Movie { Name = "Titanic", DateOfRelease = DateTime.UtcNow, Resolution = "HD", Rating = 7.80m, Description = "Test description here", Language = "English", CinemaCategory = CinemaCategory.B, TrailerPath = "test trailer path", CoverPath = "test cover path", WallpaperPath = "test wallpaper path", IMDBLink = "test imdb link", Length = 120, DirectorId = 1, }; this.firstStarRating = new StarRating { Rate = 5, MovieId = 1, UserId = this.user.Id, NextVoteDate = DateTime.UtcNow.AddDays(1), }; }
private void InitializeFields() { this.user = new CinemaWorldUser { Id = "1", Gender = Gender.Male, UserName = "******", FullName = "Pesho Peshov", Email = "*****@*****.**", PasswordHash = "123456", }; this.firstDirector = new Director { Id = 1, FirstName = "Kiril", LastName = "Petrov", }; this.firstMovie = new Movie { Id = 1, Name = "Avatar", DateOfRelease = DateTime.UtcNow, Resolution = "HD", Rating = 7.80m, Description = "Avatar movie description", Language = "English", CoverPath = TestCoverPath, WallpaperPath = TestWallpaperPath, TrailerPath = TestTrailerPath, CinemaCategory = CinemaCategory.A, Length = 120, DirectorId = this.firstDirector.Id, }; this.firstMovieComment = new MovieComment { MovieId = this.firstMovie.Id, Content = "Test comment here", UserId = this.user.Id, }; }
private async Task SeedUserInRoles(UserManager <CinemaWorldUser> userManager) { if (!userManager.Users.Any(x => x.UserName == GlobalConstants.AdministratorUsername)) { var user = new CinemaWorldUser { UserName = GlobalConstants.AdministratorUsername, Email = GlobalConstants.AdministratorEmail, FullName = GlobalConstants.AdministratorFullName, Gender = Gender.Male, }; var result = await userManager.CreateAsync(user, GlobalConstants.AdministratorPassword); if (result.Succeeded) { await userManager.AddToRoleAsync(user, GlobalConstants.AdministratorRoleName); } else { throw new Exception(string.Join(Environment.NewLine, result.Errors.Select(e => e.Description))); } } }
public async Task <IActionResult> AjaxRegister(AjaxRegisterInputModel registerInput, string returnUrl = null) { returnUrl = returnUrl ?? this.Url.Content("~/"); var ajaxObject = new AjaxObject(); if (this.ModelState.IsValid) { Enum.TryParse <Gender>(registerInput.SelectedGender, out Gender gender); var user = new CinemaWorldUser { UserName = registerInput.Username, Email = registerInput.Email, FullName = registerInput.FullName, Gender = gender, }; var result = await this.userManager.CreateAsync(user, registerInput.Password); if (result.Succeeded) { this.logger.LogInformation("User created a new account with password."); await this.userManager.AddToRoleAsync(user, GlobalConstants.UserRoleName); ajaxObject.Success = true; ajaxObject.Message = "Registered-in"; ajaxObject.Action = returnUrl; var code = await this.userManager.GenerateEmailConfirmationTokenAsync(user); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = this.Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = user.Id, code = code }, protocol: this.Request.Scheme); await this.emailSender.SendEmailAsync( registerInput.Email, "Confirm your email", htmlMessage : $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); if (this.userManager.Options.SignIn.RequireConfirmedAccount) { return(this.RedirectToPage("RegisterConfirmation", new { email = registerInput.Email })); } else { await this.signInManager.SignInAsync(user, isPersistent : false); } } foreach (var error in result.Errors) { this.ModelState.AddModelError(string.Empty, error.Description); } } if (!ajaxObject.Success) { ajaxObject.Message = ModelErrorsHelper.GetModelErrors(this.ModelState); } var jsonResult = new JsonResult(ajaxObject); return(jsonResult); }
public async Task <IActionResult> Confirmation(ExternalLoginInputModel inputModel, string returnUrl = null) { returnUrl = returnUrl ?? this.Url.Content("~/"); var info = await this.signInManager.GetExternalLoginInfoAsync(); if (info == null) { this.ErrorMessage = "Error loading external login information during confirmation."; return(this.RedirectToPage("/Login", new { ReturnUrl = returnUrl })); } if (this.ModelState.IsValid) { Enum.TryParse <Gender>(inputModel.SelectedGender, out Gender gender); var user = new CinemaWorldUser { UserName = inputModel.Username, Email = inputModel.Email, Gender = gender, FullName = inputModel.FullName, }; var result = await this.userManager.CreateAsync(user); if (result.Succeeded) { result = await this.userManager.AddLoginAsync(user, info); if (result.Succeeded) { this.logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider); await this.userManager.AddToRoleAsync(user, GlobalConstants.UserRoleName); // If account confirmation is required, we need to show the link if we don't have a real email sender if (this.userManager.Options.SignIn.RequireConfirmedAccount) { return(this.RedirectToPage("/RegisterConfirmation", new { Email = inputModel.Email })); } await this.signInManager.SignInAsync(user, isPersistent : false); var userId = await this.userManager.GetUserIdAsync(user); var code = await this.userManager.GenerateEmailConfirmationTokenAsync(user); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = this.Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = userId, code = code }, protocol: this.Request.Scheme); await this.emailSender.SendEmailAsync( inputModel.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); return(this.LocalRedirect(returnUrl)); } } foreach (var error in result.Errors) { this.ModelState.AddModelError(string.Empty, error.Description); } } this.LoginProvider = info.LoginProvider; this.ReturnUrl = returnUrl; return(this.View("ExternalFacebookLoginCallback", inputModel)); }