2019-06-07 08:59:07 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) Copyright Ascensio System Limited 2010-2018
|
|
|
|
*
|
|
|
|
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
|
|
|
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
|
|
|
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
|
|
|
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
|
|
|
*
|
|
|
|
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
|
|
|
*
|
|
|
|
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
|
|
|
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
|
|
|
*
|
|
|
|
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
|
|
|
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
|
|
|
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
|
|
|
* in every copy of the program you distribute.
|
|
|
|
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Web;
|
2020-01-22 13:59:49 +00:00
|
|
|
|
2020-02-17 08:58:14 +00:00
|
|
|
using ASC.Common;
|
2019-10-17 15:55:35 +00:00
|
|
|
using ASC.Common.Logging;
|
2019-06-07 08:59:07 +00:00
|
|
|
using ASC.Core;
|
|
|
|
using ASC.Core.Common;
|
2019-11-08 12:21:51 +00:00
|
|
|
using ASC.Core.Common.Settings;
|
2019-06-07 08:59:07 +00:00
|
|
|
using ASC.Core.Users;
|
|
|
|
using ASC.Security.Cryptography;
|
|
|
|
using ASC.Web.Core;
|
|
|
|
using ASC.Web.Core.WhiteLabel;
|
2020-01-22 13:59:49 +00:00
|
|
|
|
2019-07-02 15:30:31 +00:00
|
|
|
using Microsoft.AspNetCore.Http;
|
2019-10-17 15:55:35 +00:00
|
|
|
using Microsoft.Extensions.Options;
|
2019-06-07 08:59:07 +00:00
|
|
|
|
|
|
|
namespace ASC.Web.Studio.Utility
|
|
|
|
{
|
|
|
|
public enum ManagementType
|
|
|
|
{
|
|
|
|
General = 0,
|
|
|
|
Customization = 1,
|
|
|
|
ProductsAndInstruments = 2,
|
|
|
|
PortalSecurity = 3,
|
|
|
|
AccessRights = 4,
|
|
|
|
Backup = 5,
|
|
|
|
LoginHistory = 6,
|
|
|
|
AuditTrail = 7,
|
|
|
|
LdapSettings = 8,
|
|
|
|
ThirdPartyAuthorization = 9,
|
|
|
|
SmtpSettings = 10,
|
|
|
|
Statistic = 11,
|
|
|
|
Monitoring = 12,
|
|
|
|
SingleSignOnSettings = 13,
|
|
|
|
Migration = 14,
|
|
|
|
DeletionPortal = 15,
|
|
|
|
HelpCenter = 16,
|
|
|
|
DocService = 17,
|
|
|
|
FullTextSearch = 18,
|
|
|
|
WhiteLabel = 19,
|
|
|
|
MailService = 20,
|
2020-09-18 07:59:23 +00:00
|
|
|
Storage = 21,
|
|
|
|
PrivacyRoom = 22
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2019-10-10 10:59:22 +00:00
|
|
|
public class CommonLinkUtility : BaseCommonLinkUtility
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
private static readonly Regex RegFilePathTrim = new Regex("/[^/]*\\.aspx", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
|
|
|
|
|
|
|
public const string ParamName_ProductSysName = "product";
|
|
|
|
public const string ParamName_UserUserID = "uid";
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public CommonLinkUtility(
|
2019-10-10 10:59:22 +00:00
|
|
|
CoreBaseSettings coreBaseSettings,
|
|
|
|
CoreSettings coreSettings,
|
|
|
|
TenantManager tenantManager,
|
|
|
|
UserManager userManager,
|
|
|
|
WebItemManagerSecurity webItemManagerSecurity,
|
2019-09-19 15:55:44 +00:00
|
|
|
WebItemManager webItemManager,
|
2019-10-17 15:55:35 +00:00
|
|
|
EmailValidationKeyProvider emailValidationKeyProvider,
|
2019-11-06 15:03:09 +00:00
|
|
|
IOptionsMonitor<ILog> options,
|
2019-11-01 08:49:08 +00:00
|
|
|
IOptions<CommonLinkUtilitySettings> settings) :
|
|
|
|
this(null, coreBaseSettings, coreSettings, tenantManager, userManager, webItemManagerSecurity, webItemManager, emailValidationKeyProvider, options, settings)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public CommonLinkUtility(
|
|
|
|
IHttpContextAccessor httpContextAccessor,
|
|
|
|
CoreBaseSettings coreBaseSettings,
|
2019-10-10 10:59:22 +00:00
|
|
|
CoreSettings coreSettings,
|
2019-09-19 15:55:44 +00:00
|
|
|
TenantManager tenantManager,
|
|
|
|
UserManager userManager,
|
|
|
|
WebItemManagerSecurity webItemManagerSecurity,
|
|
|
|
WebItemManager webItemManager,
|
2019-10-17 15:55:35 +00:00
|
|
|
EmailValidationKeyProvider emailValidationKeyProvider,
|
2019-11-06 15:03:09 +00:00
|
|
|
IOptionsMonitor<ILog> options,
|
2019-11-01 08:49:08 +00:00
|
|
|
IOptions<CommonLinkUtilitySettings> settings) :
|
|
|
|
base(httpContextAccessor, coreBaseSettings, coreSettings, tenantManager, options, settings) =>
|
2019-10-17 15:55:35 +00:00
|
|
|
(UserManager, WebItemManagerSecurity, WebItemManager, EmailValidationKeyProvider) = (userManager, webItemManagerSecurity, webItemManager, emailValidationKeyProvider);
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public string Logout
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
get { return ToAbsolute("~/auth.aspx") + "?t=logout"; }
|
|
|
|
}
|
|
|
|
|
2020-08-12 09:58:08 +00:00
|
|
|
private UserManager UserManager { get; }
|
|
|
|
private WebItemManagerSecurity WebItemManagerSecurity { get; }
|
|
|
|
private WebItemManager WebItemManager { get; }
|
|
|
|
private EmailValidationKeyProvider EmailValidationKeyProvider { get; }
|
2019-09-19 15:55:44 +00:00
|
|
|
|
|
|
|
public string GetDefault()
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
return VirtualRoot;
|
|
|
|
}
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public string GetMyStaff()
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2020-02-04 07:02:14 +00:00
|
|
|
return CoreBaseSettings.Personal ? ToAbsolute("~/my.aspx") : ToAbsolute("~/products/people/view/@self");
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public string GetEmployees()
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
return GetEmployees(EmployeeStatus.Active);
|
|
|
|
}
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public string GetEmployees(EmployeeStatus empStatus)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
return ToAbsolute("~/products/people/") +
|
|
|
|
(empStatus == EmployeeStatus.Terminated ? "#type=disabled" : string.Empty);
|
|
|
|
}
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public string GetDepartment(Guid depId)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
return depId != Guid.Empty ? ToAbsolute("~/products/people/#group=") + depId.ToString() : GetEmployees();
|
|
|
|
}
|
|
|
|
|
|
|
|
#region user profile link
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public string GetUserProfile(Guid userID)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-09-19 15:55:44 +00:00
|
|
|
if (!UserManager.UserExists(userID))
|
2019-08-08 09:26:58 +00:00
|
|
|
return GetEmployees();
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
return GetUserProfile(userID.ToString());
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public string GetUserProfile(UserInfo user)
|
2019-08-30 12:40:57 +00:00
|
|
|
{
|
2019-09-19 15:55:44 +00:00
|
|
|
if (!UserManager.UserExists(user))
|
2019-08-30 12:40:57 +00:00
|
|
|
return GetEmployees();
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
return GetUserProfile(user, true);
|
2019-08-30 12:40:57 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public string GetUserProfile(string user, bool absolute = true)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
var queryParams = "";
|
|
|
|
|
2019-08-15 13:16:39 +00:00
|
|
|
if (!string.IsNullOrEmpty(user))
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
var guid = Guid.Empty;
|
2019-08-15 13:16:39 +00:00
|
|
|
if (!string.IsNullOrEmpty(user) && 32 <= user.Length && user[8] == '-')
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
guid = new Guid(user);
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-04 07:02:14 +00:00
|
|
|
queryParams = guid != Guid.Empty ? GetUserParamsPair(guid) : HttpUtility.UrlEncode(user.ToLowerInvariant());
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var url = absolute ? ToAbsolute("~/products/people/") : "/products/people/";
|
2020-02-04 07:02:14 +00:00
|
|
|
url += "view/";
|
2019-06-07 08:59:07 +00:00
|
|
|
url += queryParams;
|
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
2019-08-30 12:40:57 +00:00
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public string GetUserProfile(UserInfo user, bool absolute = true)
|
2019-08-30 12:40:57 +00:00
|
|
|
{
|
2020-02-04 07:02:14 +00:00
|
|
|
var queryParams = user.ID != Guid.Empty ? GetUserParamsPair(user) : HttpUtility.UrlEncode(user.UserName.ToLowerInvariant());
|
2019-08-30 12:40:57 +00:00
|
|
|
|
|
|
|
var url = absolute ? ToAbsolute("~/products/people/") : "/products/people/";
|
2020-02-04 07:02:14 +00:00
|
|
|
url += "view/";
|
2019-08-30 12:40:57 +00:00
|
|
|
url += queryParams;
|
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
2019-09-19 15:55:44 +00:00
|
|
|
public string GetUserProfile(Guid user, bool absolute = true)
|
2019-08-08 09:26:58 +00:00
|
|
|
{
|
2019-09-19 15:55:44 +00:00
|
|
|
var queryParams = GetUserParamsPair(user);
|
2019-08-08 09:26:58 +00:00
|
|
|
|
|
|
|
var url = absolute ? ToAbsolute("~/products/people/") : "/products/people/";
|
2020-02-04 07:02:14 +00:00
|
|
|
url += "view/";
|
2019-08-08 09:26:58 +00:00
|
|
|
url += queryParams;
|
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public Guid GetProductID()
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
var productID = Guid.Empty;
|
|
|
|
|
2020-05-17 13:08:20 +00:00
|
|
|
if (HttpContextAccessor?.HttpContext != null)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-09-19 15:55:44 +00:00
|
|
|
GetLocationByRequest(out var product, out _);
|
2019-06-07 08:59:07 +00:00
|
|
|
if (product != null) productID = product.ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
return productID;
|
|
|
|
}
|
|
|
|
|
2020-01-22 13:59:49 +00:00
|
|
|
public Guid GetAddonID()
|
|
|
|
{
|
|
|
|
var addonID = Guid.Empty;
|
|
|
|
|
2020-05-17 13:08:20 +00:00
|
|
|
if (HttpContextAccessor?.HttpContext != null)
|
2020-01-22 13:59:49 +00:00
|
|
|
{
|
2020-05-17 13:08:20 +00:00
|
|
|
var addonName = GetAddonNameFromUrl(HttpContextAccessor.HttpContext.Request.Url().AbsoluteUri);
|
2020-01-22 13:59:49 +00:00
|
|
|
|
|
|
|
switch (addonName)
|
|
|
|
{
|
|
|
|
case "mail":
|
|
|
|
addonID = WebItemManager.MailProductID;
|
|
|
|
break;
|
|
|
|
case "talk":
|
|
|
|
addonID = WebItemManager.TalkProductID;
|
|
|
|
break;
|
|
|
|
case "calendar":
|
|
|
|
addonID = WebItemManager.CalendarProductID;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return addonID;
|
|
|
|
}
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public void GetLocationByRequest(out IProduct currentProduct, out IModule currentModule)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
var currentURL = string.Empty;
|
2020-05-17 13:08:20 +00:00
|
|
|
if (HttpContextAccessor?.HttpContext?.Request != null)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2020-05-17 13:08:20 +00:00
|
|
|
currentURL = HttpContextAccessor.HttpContext.Request.GetUrlRewriter().AbsoluteUri;
|
2019-06-07 08:59:07 +00:00
|
|
|
|
|
|
|
//TODO ?
|
|
|
|
// http://[hostname]/[virtualpath]/[AjaxPro.Utility.HandlerPath]/[assembly],[classname].ashx
|
|
|
|
//if (currentURL.Contains("/" + AjaxPro.Utility.HandlerPath + "/") && HttpContext.Current.Request.Headers["Referer"].FirstOrDefault() != null)
|
|
|
|
//{
|
|
|
|
// currentURL = HttpContext.Current.Request.Headers["Referer"].FirstOrDefault().ToString();
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
GetLocationByUrl(currentURL, out currentProduct, out currentModule);
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public IWebItem GetWebItemByUrl(string currentURL)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-08-15 13:16:39 +00:00
|
|
|
if (!string.IsNullOrEmpty(currentURL))
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
var itemName = GetWebItemNameFromUrl(currentURL);
|
|
|
|
if (!string.IsNullOrEmpty(itemName))
|
|
|
|
{
|
2019-09-19 15:55:44 +00:00
|
|
|
foreach (var item in WebItemManager.GetItemsAll())
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
var _itemName = GetWebItemNameFromUrl(item.StartURL);
|
2019-08-15 13:16:39 +00:00
|
|
|
if (string.Compare(itemName, _itemName, StringComparison.InvariantCultureIgnoreCase) == 0)
|
2019-06-07 08:59:07 +00:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var urlParams = HttpUtility.ParseQueryString(new Uri(currentURL).Query);
|
2019-09-19 15:55:44 +00:00
|
|
|
var productByName = GetProductBySysName(urlParams[ParamName_ProductSysName]);
|
2019-06-07 08:59:07 +00:00
|
|
|
var pid = productByName == null ? Guid.Empty : productByName.ID;
|
|
|
|
|
2019-08-15 13:16:39 +00:00
|
|
|
if (pid == Guid.Empty && !string.IsNullOrEmpty(urlParams["pid"]))
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
pid = new Guid(urlParams["pid"]);
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
pid = Guid.Empty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pid != Guid.Empty)
|
2019-09-19 15:55:44 +00:00
|
|
|
return WebItemManager[pid];
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public void GetLocationByUrl(string currentURL, out IProduct currentProduct, out IModule currentModule)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
currentProduct = null;
|
|
|
|
currentModule = null;
|
|
|
|
|
2019-08-15 13:16:39 +00:00
|
|
|
if (string.IsNullOrEmpty(currentURL)) return;
|
2019-06-07 08:59:07 +00:00
|
|
|
|
|
|
|
var urlParams = HttpUtility.ParseQueryString(new Uri(currentURL).Query);
|
2019-09-19 15:55:44 +00:00
|
|
|
var productByName = GetProductBySysName(urlParams[ParamName_ProductSysName]);
|
2019-06-07 08:59:07 +00:00
|
|
|
var pid = productByName == null ? Guid.Empty : productByName.ID;
|
|
|
|
|
2019-08-15 13:16:39 +00:00
|
|
|
if (pid == Guid.Empty && !string.IsNullOrEmpty(urlParams["pid"]))
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
pid = new Guid(urlParams["pid"]);
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
pid = Guid.Empty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var productName = GetProductNameFromUrl(currentURL);
|
|
|
|
var moduleName = GetModuleNameFromUrl(currentURL);
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(productName) || !string.IsNullOrEmpty(moduleName))
|
|
|
|
{
|
2019-09-19 15:55:44 +00:00
|
|
|
foreach (var product in WebItemManager.GetItemsAll<IProduct>())
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
var _productName = GetProductNameFromUrl(product.StartURL);
|
|
|
|
if (!string.IsNullOrEmpty(_productName))
|
|
|
|
{
|
2019-08-15 13:16:39 +00:00
|
|
|
if (string.Compare(productName, _productName, StringComparison.InvariantCultureIgnoreCase) == 0)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
currentProduct = product;
|
|
|
|
|
2019-08-15 13:16:39 +00:00
|
|
|
if (!string.IsNullOrEmpty(moduleName))
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-09-19 15:55:44 +00:00
|
|
|
foreach (var module in WebItemManagerSecurity.GetSubItems(product.ID).OfType<IModule>())
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
var _moduleName = GetModuleNameFromUrl(module.StartURL);
|
|
|
|
if (!string.IsNullOrEmpty(_moduleName))
|
|
|
|
{
|
2019-08-15 13:16:39 +00:00
|
|
|
if (string.Compare(moduleName, _moduleName, StringComparison.InvariantCultureIgnoreCase) == 0)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
currentModule = module;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-19 15:55:44 +00:00
|
|
|
foreach (var module in WebItemManagerSecurity.GetSubItems(product.ID).OfType<IModule>())
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
if (!module.StartURL.Equals(product.StartURL) && currentURL.Contains(RegFilePathTrim.Replace(module.StartURL, string.Empty)))
|
|
|
|
{
|
|
|
|
currentModule = module;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pid != Guid.Empty)
|
2019-09-19 15:55:44 +00:00
|
|
|
currentProduct = WebItemManager[pid] as IProduct;
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
private string GetWebItemNameFromUrl(string url)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
var name = GetModuleNameFromUrl(url);
|
2019-08-15 13:16:39 +00:00
|
|
|
if (string.IsNullOrEmpty(name))
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
name = GetProductNameFromUrl(url);
|
2019-08-15 13:16:39 +00:00
|
|
|
if (string.IsNullOrEmpty(name))
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2020-09-11 14:12:35 +00:00
|
|
|
return GetAddonNameFromUrl(url);
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
private string GetProductNameFromUrl(string url)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var pos = url.IndexOf("/products/", StringComparison.InvariantCultureIgnoreCase);
|
|
|
|
if (0 <= pos)
|
|
|
|
{
|
|
|
|
url = url.Substring(pos + 10).ToLower();
|
|
|
|
pos = url.IndexOf('/');
|
|
|
|
return 0 < pos ? url.Substring(0, pos) : url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-01-22 13:59:49 +00:00
|
|
|
private static string GetAddonNameFromUrl(string url)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var pos = url.IndexOf("/addons/", StringComparison.InvariantCultureIgnoreCase);
|
|
|
|
if (0 <= pos)
|
|
|
|
{
|
|
|
|
url = url.Substring(pos + 8).ToLower();
|
|
|
|
pos = url.IndexOf('/');
|
|
|
|
return 0 < pos ? url.Substring(0, pos) : url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-06-07 08:59:07 +00:00
|
|
|
private static string GetModuleNameFromUrl(string url)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var pos = url.IndexOf("/modules/", StringComparison.InvariantCultureIgnoreCase);
|
|
|
|
if (0 <= pos)
|
|
|
|
{
|
|
|
|
url = url.Substring(pos + 9).ToLower();
|
|
|
|
pos = url.IndexOf('/');
|
|
|
|
return 0 < pos ? url.Substring(0, pos) : url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
private IProduct GetProductBySysName(string sysName)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
IProduct result = null;
|
|
|
|
|
2019-08-15 13:16:39 +00:00
|
|
|
if (!string.IsNullOrEmpty(sysName))
|
2019-09-19 15:55:44 +00:00
|
|
|
foreach (var product in WebItemManager.GetItemsAll<IProduct>())
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-08-15 13:16:39 +00:00
|
|
|
if (string.CompareOrdinal(sysName, WebItemExtension.GetSysName(product as IWebItem)) == 0)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
result = product;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public string GetUserParamsPair(Guid userID)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-09-19 15:55:44 +00:00
|
|
|
return GetUserParamsPair(UserManager.GetUsers(userID));
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public string GetUserParamsPair(UserInfo user)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-09-19 15:55:44 +00:00
|
|
|
if (user == null || string.IsNullOrEmpty(user.UserName) || !UserManager.UserExists(user))
|
2019-06-07 08:59:07 +00:00
|
|
|
return "";
|
|
|
|
|
2020-02-04 07:02:14 +00:00
|
|
|
return HttpUtility.UrlEncode(user.UserName.ToLowerInvariant());
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#region Help Centr
|
|
|
|
|
2019-11-08 12:21:51 +00:00
|
|
|
public string GetHelpLink(SettingsManager settingsManager, AdditionalWhiteLabelSettingsHelper additionalWhiteLabelSettingsHelper, bool inCurrentCulture = true)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2020-09-07 13:53:39 +00:00
|
|
|
if (!settingsManager.LoadForDefaultTenant<AdditionalWhiteLabelSettings>().HelpCenterEnabled)
|
2019-08-15 13:16:39 +00:00
|
|
|
return string.Empty;
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2019-11-08 12:21:51 +00:00
|
|
|
var url = additionalWhiteLabelSettingsHelper.DefaultHelpCenterUrl;
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2019-08-15 13:16:39 +00:00
|
|
|
if (string.IsNullOrEmpty(url))
|
|
|
|
return string.Empty;
|
2019-06-07 08:59:07 +00:00
|
|
|
|
|
|
|
return GetRegionalUrl(url, inCurrentCulture ? CultureInfo.CurrentCulture.TwoLetterISOLanguageName : null);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region management links
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public string GetAdministration(ManagementType managementType)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
|
|
|
if (managementType == ManagementType.General)
|
|
|
|
return ToAbsolute("~/management.aspx") + string.Empty;
|
|
|
|
|
|
|
|
return ToAbsolute("~/management.aspx") + "?" + "type=" + ((int)managementType).ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region confirm links
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public string GetConfirmationUrl(string email, ConfirmType confirmType, object postfix = null, Guid userId = default)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-09-19 15:55:44 +00:00
|
|
|
return GetFullAbsolutePath(GetConfirmationUrlRelative(email, confirmType, postfix, userId));
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 15:55:44 +00:00
|
|
|
public string GetConfirmationUrlRelative(string email, ConfirmType confirmType, object postfix = null, Guid userId = default)
|
2020-07-02 14:11:59 +00:00
|
|
|
{
|
|
|
|
return $"confirm/{confirmType}?{GetToken(email, confirmType, postfix, userId)}";
|
|
|
|
}
|
|
|
|
|
|
|
|
public string GetToken(string email, ConfirmType confirmType, object postfix = null, Guid userId = default)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-09-19 15:55:44 +00:00
|
|
|
var validationKey = EmailValidationKeyProvider.GetEmailKey(email + confirmType + (postfix ?? ""));
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2020-07-02 14:11:59 +00:00
|
|
|
var link = $"type={confirmType}&key={validationKey}";
|
2019-06-07 08:59:07 +00:00
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(email))
|
|
|
|
{
|
2019-09-09 12:07:15 +00:00
|
|
|
link += $"&email={HttpUtility.UrlEncode(email)}";
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2019-08-15 13:00:20 +00:00
|
|
|
if (userId != default)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2019-09-09 12:07:15 +00:00
|
|
|
link += $"&uid={userId}";
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return link;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
}
|
2019-10-31 11:28:30 +00:00
|
|
|
|
2019-11-11 09:03:49 +00:00
|
|
|
public static class CommonLinkUtilityExtension
|
2019-10-31 11:28:30 +00:00
|
|
|
{
|
2020-02-17 08:58:14 +00:00
|
|
|
public static DIHelper AddCommonLinkUtilityService(this DIHelper services)
|
2019-10-31 11:28:30 +00:00
|
|
|
{
|
2020-07-17 10:52:28 +00:00
|
|
|
if (services.TryAddScoped<CommonLinkUtility>())
|
|
|
|
{
|
|
|
|
return services
|
|
|
|
.AddUserManagerService()
|
|
|
|
.AddBaseCommonLinkUtilityService()
|
|
|
|
.AddWebItemManagerSecurity()
|
|
|
|
.AddWebItemManager()
|
|
|
|
.AddEmailValidationKeyProviderService();
|
|
|
|
}
|
|
|
|
|
|
|
|
return services;
|
2019-10-31 11:28:30 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|