private void InitializeFields()
        {
            this.cookingHubUser = new CookingHubUser
            {
                Id       = "1",
                FullName = "Peter Petrov",
                UserName = "******",
                Gender   = Gender.Male,
            };

            this.firstCategory = new Category
            {
                Id          = 1,
                Name        = "Vegetables",
                Description = "Test description",
            };

            this.firstArticle = new Article
            {
                Title       = "Test Article",
                Description = "Test Description",
                ImagePath   = "Test IMG path",
                CategoryId  = 1,
                UserId      = "1",
            };
        }
        private void InitializeFields()
        {
            this.cookingHubUser = new CookingHubUser
            {
                Id       = "1",
                FullName = "Peter Petrov",
                UserName = "******",
                Gender   = Gender.Male,
            };

            this.firstCategory = new Category
            {
                Id          = 1,
                Name        = "Vegetables",
                Description = "Test description",
            };

            this.firstRecipe = new Recipe
            {
                Name            = "Test recipe name",
                Description     = "Test description name which has to have at least 50 sybmols for...reasons!Anyway Test description.",
                Ingredients     = "Test ingredients here",
                Rate            = 3,
                PreparationTime = 5,
                CookingTime     = 3,
                PortionsNumber  = 3,
                Difficulty      = Difficulty.Easy,
                ImagePath       = "Test image path",
                CategoryId      = 1,
                UserId          = "1",
            };
        }
        private void InitializeFields()
        {
            this.firstCookingHubUser = new CookingHubUser
            {
                Id       = "1",
                FullName = "Stamat Stamatov",
                UserName = "******",
                Gender   = Gender.Male,
            };

            this.firstCategory = new Category
            {
                Name        = "Vegetables",
                Description = "Test category description",
            };

            this.firstArticle = new Article
            {
                Id          = 1,
                Title       = "Test article title",
                Description = "Test article description",
                ImagePath   = "https://someimageurl.com",
                CategoryId  = 1,
                UserId      = "1",
            };

            this.firstArticleComment = new ArticleComment
            {
                ArticleId = this.firstArticle.Id,
                Content   = "Nice article.",
                UserId    = this.firstCookingHubUser.Id,
            };
        }
Esempio n. 4
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl           = 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 CookingHubUser
                {
                    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, returnUrl = returnUrl },
                        protocol: this.Request.Scheme);

                    string htmlMessage = $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.";
                    await this.emailSender.SendEmailAsync(this.Input.Email, "Confirm your email", htmlMessage : htmlMessage);

                    if (this.userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(this.RedirectToPage("RegisterConfirmation", new { email = this.Input.Email, returnUrl = returnUrl }));
                    }
                    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());
        }
Esempio n. 5
0
 private void InitializeFields()
 {
     this.firstCookingHubUser = new CookingHubUser
     {
         Id        = "1",
         FullName  = "Kiril Petrov",
         UserName  = "******",
         Gender    = Gender.Male,
         CreatedOn = DateTime.Parse("2020-02-10"),
     };
 }
        private async Task LoadAsync(CookingHubUser 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 void InitializeFields()
        {
            this.firstCookingHubUser = new CookingHubUser
            {
                Id       = "1",
                FullName = "Peter Petrov",
                UserName = "******",
                Gender   = Gender.Male,
            };

            this.secondCookingHubUser = new CookingHubUser
            {
                Id       = "2",
                FullName = "Incho",
                UserName = "******",
                Gender   = Gender.Male,
            };

            this.firstCategory = new Category
            {
                Id          = 1,
                Name        = "Vegetables",
                Description = "Test description",
            };

            this.firstReview = new Review
            {
                Title       = "Бива",
                Description = "Test description",
                Rate        = 5,
                RecipeId    = 1,
                UserId      = "1",
            };

            this.firstRecipe = new Recipe
            {
                Name            = "Test recipe name",
                Description     = "Test description name",
                Ingredients     = "Test ingredients here",
                Rate            = 3,
                PreparationTime = 5,
                CookingTime     = 3,
                PortionsNumber  = 3,
                Difficulty      = Difficulty.Easy,
                ImagePath       = "Test image path",
                CategoryId      = 1,
                UserId          = "1",
            };
        }
        private void InitializeFields()
        {
            this.cookingHubUser = new CookingHubUser
            {
                Id       = "1",
                FullName = "Peter Petrov",
                UserName = "******",
                Gender   = Gender.Male,
            };

            this.firstMessage = new Message
            {
                Content  = "Hello, World",
                UserId   = this.cookingHubUser.Id,
                UserName = this.cookingHubUser.UserName,
            };
        }
Esempio n. 9
0
        private async Task SeedUserInRoles(UserManager <CookingHubUser> userManager)
        {
            if (!userManager.Users.Any(x => x.UserName == GlobalConstants.AdministratorUsername))
            {
                var user = new CookingHubUser
                {
                    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)));
                }
            }
        }
Esempio n. 10
0
        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 CookingHubUser
                {
                    UserName = this.Input.Username,
                    Email    = this.Input.Email,
                    Gender   = gender,
                    FullName = this.Input.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);

                        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>.");

                        // 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, info.LoginProvider);

                        return(this.LocalRedirect(returnUrl));
                    }
                }

                foreach (var error in result.Errors)
                {
                    this.ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            this.ProviderDisplayName = info.ProviderDisplayName;
            this.ReturnUrl           = returnUrl;
            return(this.Page());
        }