private async Task SeedUserInRoles(UserManager <PhotoPavilionUser> userManager) { if (!userManager.Users.Any(x => x.UserName == GlobalConstants.AdministratorUsername)) { var user = new PhotoPavilionUser { UserName = GlobalConstants.AdministratorUsername, Email = GlobalConstants.AdministratorEmail, FullName = GlobalConstants.AdministratorFullName, Gender = Gender.Male, ShoppingCart = new ShoppingCart(), }; 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))); } } }
private void InitializeFields() { this.firstShoppingCart = new ShoppingCart { UserId = "1", }; this.user = new PhotoPavilionUser { Id = "1", Gender = Gender.Male, UserName = "******", FullName = "Peter Petrov", Email = "*****@*****.**", PasswordHash = "123456", ShoppingCartId = 1, }; this.firstBrand = new Brand { Name = "Canon", }; this.firstCategory = new Category { Name = "Cameras", Description = "Sample category description", }; this.firstProduct = new Product { Id = 1, Name = "Canon eos 1100D", Code = 10600, Description = "Sample description for Canon eos 1100D", Price = 1500, ImagePath = TestProductImageUrl, BrandId = 1, CategoryId = 1, }; this.firstOrderProduct = new OrderProduct { ProductId = 1, Quantity = 1, Status = OrderStatus.Accepted, Date = DateTime.UtcNow, UserId = "1", }; this.firstShoppingCartProduct = new ShoppingCartProduct { ShoppingCartId = 1, ProductId = 1, Quantity = 1, }; }
private async Task LoadAsync(PhotoPavilionUser user) { var userName = await _userManager.GetUserNameAsync(user); var phoneNumber = await _userManager.GetPhoneNumberAsync(user); Username = userName; Input = new InputModel { PhoneNumber = phoneNumber }; }
private async Task LoadAsync(PhotoPavilionUser 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.firstShoppingCart = new ShoppingCart { UserId = "1", }; this.user = new PhotoPavilionUser { Id = "1", Gender = Gender.Male, UserName = "******", FullName = "Pesho Peshov", Email = "*****@*****.**", PasswordHash = "123456", ShoppingCartId = 1, }; this.firstBrand = new Brand { Name = "Canon", }; this.firstCategory = new Category { Name = "Cameras", Description = "Sample category description", }; this.firstProduct = new Product { Id = 1, Name = "Canon eos 1100D", Code = 10600, Description = "Sample description for Canon eos 1100D", Price = 1500, ImagePath = "test image path", BrandId = 1, CategoryId = 1, }; this.firstStarRating = new StarRating { Rate = 5, ProductId = 1, UserId = this.user.Id, NextVoteDate = DateTime.UtcNow.AddDays(1), }; }
private void InitializeFields() { this.firstShoppingCart = new ShoppingCart { UserId = "1", }; this.user = new PhotoPavilionUser { Id = "1", Gender = Gender.Male, UserName = "******", FullName = "Pesho Peshov", Email = "*****@*****.**", PasswordHash = "123456", ShoppingCartId = 1, }; this.firstBrand = new Brand { Name = "Canon", }; this.firstCategory = new Category { Name = "Cameras", Description = "Samle category description", }; this.firstProduct = new Product { Id = 1, Name = "Canon eos 1100D", Code = 10600, Description = "Sample description for Canon eos 1100D", Price = 1500, ImagePath = "test image path", BrandId = 1, CategoryId = 1, }; this.firstReview = new Review { Title = "Nice product to buy.", Description = "Sample description about this product.", UserId = "1", ProductId = 1, }; }
private void InitializeFields() { this.firstShoppingCart = new ShoppingCart { UserId = "1", }; this.user = new PhotoPavilionUser { Id = "1", Gender = Gender.Male, UserName = "******", FullName = "Pesho Peshov", Email = "*****@*****.**", PasswordHash = "123456", ShoppingCartId = 1, }; this.firstBrand = new Brand { Name = "Nikon", }; this.firstCategory = new Category { Name = "Cameras", Description = "Category only for cameras", }; this.firstProduct = new Product { Id = 1, Name = "Nikon 7200D", Code = 10200, Description = "Sample description for Nikon 7200D", Price = 3500, ImagePath = TestImagePath, BrandId = 1, CategoryId = 1, }; this.firstProductComment = new Comment { ProductId = this.firstProduct.Id, Content = "Test comment here", UserId = this.user.Id, }; }
private void InitializeFields() { this.user = new PhotoPavilionUser { Id = "1", Gender = Gender.Male, UserName = "******", FullName = "Stamat Stamatov", Email = "*****@*****.**", PasswordHash = "123456", ShoppingCart = new ShoppingCart(), }; this.firstBrand = new Brand { Name = "Nikon", }; this.firstCategory = new Category { Name = "Cameras", Description = "Sample category description", }; this.firstProduct = new Product { Id = 1, Name = "Nikon D7200", Code = 10200, Description = "Sample description for Nikon D7200", Price = 1300, ImagePath = TestProductImageUrl, BrandId = 1, CategoryId = 1, }; this.firstShoppingCartProduct = new ShoppingCartProduct { ProductId = 1, ShoppingCartId = 1, Quantity = 1, }; }
private void InitializeFields() { this.firstShoppingCart = new ShoppingCart { UserId = "1", }; this.user = new PhotoPavilionUser { Id = "1", Gender = Gender.Female, UserName = "******", FullName = "Maria Petrova", Email = "*****@*****.**", PasswordHash = "123456", ShoppingCartId = 1, }; this.firstBrand = new Brand { Name = "Canon", }; this.firstCategory = new Category { Name = "Cameras", Description = "Sample category description", }; this.firstProduct = new Product { Id = 1, Name = "Canon eos 1100D", Code = 10600, Description = "Sample description for Canon eos 1100D", Price = 1500, ImagePath = TestProductImageUrl, BrandId = 1, CategoryId = 1, }; }
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 PhotoPavilionUser { UserName = this.Input.Username, Email = this.Input.Email, FullName = this.Input.FullName, Gender = gender, ShoppingCart = new ShoppingCart(), }; 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); await this.shoppingCartsService.AssignShoppingCartToUserIdAsync(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 = 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); var shoppingCartProducts = this.HttpContext.Session .GetObjectFromJson <ShoppingCartProductViewModel[]>(WebConstants.ShoppingCartSessionKey) ?? new List <ShoppingCartProductViewModel>().ToArray(); if (shoppingCartProducts != null) { foreach (var product in shoppingCartProducts) { await this.shoppingCartsService .AddProductToShoppingCartAsync(product.ProductId, this.Input.Username, product.Quantity); } this.HttpContext.Session.Remove(WebConstants.ShoppingCartSessionKey); } 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()); }
public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null) { returnUrl = returnUrl ?? this.Url.Content("~/"); // Get the information about the user from the external login provider 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>(this.Input.SelectedGender, out Gender gender); var user = new PhotoPavilionUser { UserName = this.Input.Username, Email = this.Input.Email, Gender = gender, FullName = this.Input.FullName, ShoppingCart = new ShoppingCart(), }; 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); await this.shoppingCartsService.AssignShoppingCartToUserIdAsync(user); await this.StoreGuestShoppingCartIfAny(info.Principal.Identity.Name.RemoveWhiteSpaces()); // 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 = this.Input.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( this.Input.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); } return(this.Page()); } this.LoginProvider = info.LoginProvider; this.ReturnUrl = returnUrl; return(this.Page()); }