コード例 #1
0
        /// <summary>
        /// Determines whether the specified navigatable matches the current request URL.
        /// </summary>
        /// <param name="navigatable">The <see cref="INavigatable"/> object.</param>
        /// <param name="viewContext">The <see cref="ViewContext"/> object.</param>
        /// <param name="urlGenerator">The <see cref="IUrlGenerator"/> generator.</param>
        /// <returns></returns>
        public static bool IsCurrent(this INavigatable navigatable, ViewContext viewContext, IUrlGenerator urlGenerator)
        {
            var currentUrl   = viewContext.HttpContext.Request.Url.PathAndQuery;
            var url          = urlGenerator.Generate(viewContext.RequestContext, navigatable);
            var currentRoute = new UrlHelper(viewContext.RequestContext).RouteUrl(viewContext.RequestContext.RouteData.Values);

            return(url.IsCaseInsensitiveEqual(currentUrl) || url.IsCaseInsensitiveEqual(currentRoute));
        }
コード例 #2
0
    public void GenerateUrl()
    {
        // Arrange & Act
        string result = _urlGenerator.Generate();

        _output.WriteLine("Generated string: " + result);

        // Assert
        Assert.NotNull(result);
        Assert.NotEqual(string.Empty, result);
    }
コード例 #3
0
        public async Task <ZippedLinkModel> ZipLink(ZipLinkDTO dto)
        {
            new ZipLinkValidator(dto).Validate();
            var newEntity = new ZippedLinkEntity()
            {
                Created      = DateTime.Now,
                Followed     = 0,
                OriginalLink = dto.Link,
                Hash         = _urlGenerator.Generate()
            };
            await _zippedLinksRepository.CreateLink(newEntity);

            return(newEntity.ConvertTo <ZippedLinkModel>());
        }
コード例 #4
0
    public async Task <IActionResult> OnPostAsync()
    {
        var _user = await _userManager.GetUserAsync(User);

        _user.UniqueUrl = _urlGenerator.Generate();

        await _userManager.UpdateAsync(_user);

        _logger.LogInformation($"User {_user.Id} has changed his url");

        StatusMessage = _localizer["StatusMessage"];

        return(Page());
    }
コード例 #5
0
        private string GetUrl(INavigatable node, HttpContextBase httpContext, string applicationRoot)
        {
            string url = urlGenerator.Generate(httpContext.RequestContext(), node);

            if (!string.IsNullOrEmpty(url))
            {
                if (!url.StartsWith("/", StringComparison.Ordinal))
                {
                    url = "/" + url;
                }

                url = applicationRoot + url;
            }

            return(url);
        }
コード例 #6
0
    public async Task <IActionResult> OnPostAsync(string returnUrl = null)
    {
        returnUrl ??= Url.Content("~/");

        if (ModelState.IsValid)
        {
            var _user = await _userManager.FindByNameAsync(Input.UserName);

            if (_user != null)
            {
                ModelState.AddModelError("Input.UserName", _localizer["LoginExist"]);
                return(Page());
            }

            _user = await _userManager.FindByEmailAsync(Input.Email);

            if (_user != null)
            {
                ModelState.AddModelError(string.Empty, _localizer["EmailExist"]);
                return(Page());
            }

            string[] fullName = Input.FullName.Split(' ');

            ApplicationUser user = new()
            {
                Email            = Input.Email,
                UserName         = Input.UserName,
                Name             = fullName[1],
                Surname          = fullName[0],
                MiddleName       = fullName[2],
                UniqueUrl        = _urlGenerator.Generate(),
                RegistrationDate = DateTime.UtcNow
            };

            var result = await _userManager.CreateAsync(user, Input.Password);

            if (result.Succeeded)
            {
                _logger.LogInformation($"New User {user.Id} registered");

                await _userManager.AddToRoleAsync(user, "User");

// Remove the mandatory check by mail during debugging.
#if DEBUG
                return(RedirectToPage("./Login"));
#elif RELEASE
                var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                var callbackUrl = Url.Page("/Account/ConfirmEmail",
                                           pageHandler: null,
                                           values: new { area = "Identity", userId = user.Id, code = code },
                                           protocol: Request.Scheme);

                var email = _emailTemplate.GetTemplate(EmailMessageType.RegisterConfirmation, callbackUrl);

                await _emailSender.SendEmailAsync(Input.Email, email.subject, email.template);

                return(RedirectToPage("./RegisterConfirmation"));
#endif
            }

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

        return(Page());
    }
}
コード例 #7
0
 public EditorImageBrowserSettingsBuilder Image(string url)
 {
     settings.Image.Url = urlGenerator.Generate(viewContext.RequestContext, url);
     return(this);
 }
コード例 #8
0
 /// <summary>
 /// Generating url depending on the ViewContext and the <see cref="IUrlGenerator"/> generator.
 /// </summary>
 /// <param name="navigatable">The <see cref="INavigatable"/> object.</param>
 /// <param name="viewContext">The <see cref="ViewContext"/> object</param>
 /// <param name="urlGenerator">The <see cref="IUrlGenerator"/> generator.</param>
 public static string GenerateUrl(this INavigatable navigatable, ViewContext viewContext, IUrlGenerator urlGenerator, RouteValueDictionary routeValues)
 {
     return(urlGenerator.Generate(viewContext.RequestContext, navigatable, routeValues));
 }
コード例 #9
0
 /// <summary>
 /// Generating url depending on the ViewContext and the <see cref="IUrlGenerator"/> generator.
 /// </summary>
 /// <param name="navigatable">The <see cref="INavigatable"/> object.</param>
 /// <param name="viewContext">The <see cref="ViewContext"/> object</param>
 /// <param name="urlGenerator">The <see cref="IUrlGenerator"/> generator.</param>
 public static string GenerateUrl(this INavigatable navigatable, ViewContext viewContext, IUrlGenerator urlGenerator)
 {
     return(urlGenerator.Generate(viewContext.RequestContext, navigatable));
 }
コード例 #10
0
        /// <summary>
        /// Specifies an absolute or relative URL for the operation.
        /// </summary>
        /// <param name="url">Absolute or relative URL for the operation</param>
        public EditorImageBrowserOperationBuilder Url(string url)
        {
            operation.Url = urlGenerator.Generate(viewContext.RequestContext, url);

            return(this);
        }