DocSpace-buildtools/web/ASC.Web.Core/Notify/StudioNotifyService.cs

1016 lines
41 KiB
C#
Raw Normal View History

2022-03-15 18:00:53 +00:00
// (c) Copyright Ascensio System SIA 2010-2022
//
// This program is a free software product.
// You can redistribute it and/or modify it under the terms
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
// Foundation. In accordance with Section 7(a) of the GNU AGPL 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 details, see
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
//
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
//
// The interactive user interfaces in modified source and object code versions of the Program must
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
//
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
// trademark law for use of our trademarks.
//
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
using Constants = ASC.Core.Users.Constants;
2022-03-17 15:13:38 +00:00
namespace ASC.Web.Studio.Core.Notify;
2022-04-14 19:23:57 +00:00
[Scope]
2022-03-17 15:13:38 +00:00
public class StudioNotifyService
{
2022-04-14 19:23:57 +00:00
private readonly StudioNotifyServiceHelper _client;
2022-03-17 15:13:38 +00:00
public static string EMailSenderName { get { return ASC.Core.Configuration.Constants.NotifyEMailSenderSysName; } }
2022-04-14 19:23:57 +00:00
private readonly UserManager _userManager;
private readonly StudioNotifyHelper _studioNotifyHelper;
private readonly TenantExtra _tenantExtra;
private readonly AuthManager _authentication;
private readonly AuthContext _authContext;
private readonly TenantManager _tenantManager;
private readonly CoreBaseSettings _coreBaseSettings;
private readonly CommonLinkUtility _commonLinkUtility;
private readonly SetupInfo _setupInfo;
private readonly DisplayUserSettingsHelper _displayUserSettingsHelper;
private readonly SettingsManager _settingsManager;
private readonly WebItemSecurity _webItemSecurity;
private readonly ILogger _log;
2022-03-17 15:13:38 +00:00
public StudioNotifyService(
UserManager userManager,
StudioNotifyHelper studioNotifyHelper,
StudioNotifyServiceHelper studioNotifyServiceHelper,
TenantExtra tenantExtra,
AuthManager authentication,
AuthContext authContext,
TenantManager tenantManager,
CoreBaseSettings coreBaseSettings,
CommonLinkUtility commonLinkUtility,
SetupInfo setupInfo,
DisplayUserSettingsHelper displayUserSettingsHelper,
SettingsManager settingsManager,
WebItemSecurity webItemSecurity,
ILoggerProvider option)
{
_log = option.CreateLogger("ASC.Notify");
2022-04-14 19:23:57 +00:00
_client = studioNotifyServiceHelper;
_tenantExtra = tenantExtra;
_authentication = authentication;
_authContext = authContext;
_tenantManager = tenantManager;
_coreBaseSettings = coreBaseSettings;
_commonLinkUtility = commonLinkUtility;
_setupInfo = setupInfo;
_displayUserSettingsHelper = displayUserSettingsHelper;
_settingsManager = settingsManager;
_webItemSecurity = webItemSecurity;
_userManager = userManager;
_studioNotifyHelper = studioNotifyHelper;
2022-03-17 15:13:38 +00:00
}
2022-03-09 17:15:51 +00:00
2022-03-17 15:13:38 +00:00
public void SendMsgToAdminAboutProfileUpdated()
{
2022-04-14 19:23:57 +00:00
_client.SendNoticeAsync(Actions.SelfProfileUpdated, null);
2022-03-17 15:13:38 +00:00
}
2022-03-09 17:15:51 +00:00
2022-03-17 15:13:38 +00:00
public void SendMsgToAdminFromNotAuthUser(string email, string message)
{
2022-04-14 19:23:57 +00:00
_client.SendNoticeAsync(Actions.UserMessageToAdmin, null, new TagValue(Tags.Body, message), new TagValue(Tags.UserEmail, email));
2022-03-17 15:13:38 +00:00
}
2022-03-09 17:15:51 +00:00
2022-03-17 15:13:38 +00:00
public void SendRequestTariff(bool license, string fname, string lname, string title, string email, string phone, string ctitle, string csize, string site, string message)
{
fname = (fname ?? "").Trim();
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(fname);
2022-03-09 17:15:51 +00:00
2022-03-17 15:13:38 +00:00
lname = (lname ?? "").Trim();
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(lname);
2022-03-17 15:01:39 +00:00
2022-03-17 15:13:38 +00:00
title = (title ?? "").Trim();
email = (email ?? "").Trim();
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(email);
2022-03-17 15:13:38 +00:00
phone = (phone ?? "").Trim();
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(phone);
2022-03-17 15:13:38 +00:00
ctitle = (ctitle ?? "").Trim();
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(ctitle);
2022-03-17 15:13:38 +00:00
csize = (csize ?? "").Trim();
ArgumentNullOrEmptyException.ThrowIfNullOrEmpty(csize);
site = (site ?? "").Trim();
2022-04-14 19:23:57 +00:00
if (string.IsNullOrEmpty(site) && !_coreBaseSettings.CustomMode)
{
throw new ArgumentNullException(nameof(site));
}
2022-03-17 15:13:38 +00:00
message = (message ?? "").Trim();
2022-04-14 19:23:57 +00:00
if (string.IsNullOrEmpty(message) && !_coreBaseSettings.CustomMode)
{
throw new ArgumentNullException(nameof(message));
}
2022-04-14 19:23:57 +00:00
var salesEmail = _settingsManager.LoadForDefaultTenant<AdditionalWhiteLabelSettings>().SalesEmail ?? _setupInfo.SalesEmail;
2022-03-17 15:13:38 +00:00
2022-04-14 19:23:57 +00:00
var recipient = (IRecipient)new DirectRecipient(_authContext.CurrentAccount.ID.ToString(), string.Empty, new[] { salesEmail }, false);
2022-03-17 15:13:38 +00:00
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(license ? Actions.RequestLicense : Actions.RequestTariff,
new[] { recipient },
new[] { "email.sender" },
new TagValue(Tags.UserName, fname),
new TagValue(Tags.UserLastName, lname),
new TagValue(Tags.UserPosition, title),
new TagValue(Tags.UserEmail, email),
new TagValue(Tags.Phone, phone),
new TagValue(Tags.Website, site),
new TagValue(Tags.CompanyTitle, ctitle),
new TagValue(Tags.CompanySize, csize),
new TagValue(Tags.Body, message));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
#region Voip
2022-03-17 15:13:38 +00:00
public void SendToAdminVoipWarning(double balance)
{
2022-04-14 19:23:57 +00:00
_client.SendNoticeAsync(Actions.VoipWarning, null, new TagValue(Tags.Body, balance));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
public void SendToAdminVoipBlocked()
{
2022-04-14 19:23:57 +00:00
_client.SendNoticeAsync(Actions.VoipBlocked, null);
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
#endregion
2022-03-17 15:13:38 +00:00
#region User Password
2022-03-17 15:13:38 +00:00
public void UserPasswordChange(UserInfo userInfo)
{
2022-04-14 19:23:57 +00:00
var hash = _authentication.GetUserPasswordStamp(userInfo.Id).ToString("s");
var confirmationUrl = _commonLinkUtility.GetConfirmationUrl(userInfo.Email, ConfirmType.PasswordChange, hash, userInfo.Id);
2022-04-14 19:23:57 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonChangePassword;
2022-04-14 19:23:57 +00:00
var action = _coreBaseSettings.Personal
? (_coreBaseSettings.CustomMode ? Actions.PersonalCustomModePasswordChange : Actions.PersonalPasswordChange)
: Actions.PasswordChange;
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
action,
_studioNotifyHelper.RecipientFromEmail(userInfo.Email, false),
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, confirmationUrl));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
#endregion
2022-03-17 15:13:38 +00:00
#region User Email
2022-03-17 15:13:38 +00:00
public void SendEmailChangeInstructions(UserInfo user, string email)
{
2022-04-14 19:23:57 +00:00
var confirmationUrl = _commonLinkUtility.GetConfirmationUrl(email, ConfirmType.EmailChange, _authContext.CurrentAccount.ID);
2022-04-14 19:23:57 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonChangeEmail;
2022-04-14 19:23:57 +00:00
var action = _coreBaseSettings.Personal
? (_coreBaseSettings.CustomMode ? Actions.PersonalCustomModeEmailChangeV115 : Actions.PersonalEmailChangeV115)
: Actions.EmailChangeV115;
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
action,
_studioNotifyHelper.RecipientFromEmail(email, false),
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, confirmationUrl),
new TagValue(CommonTags.Culture, user.GetCulture().Name));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
public void SendEmailActivationInstructions(UserInfo user, string email)
{
2022-04-14 19:23:57 +00:00
var confirmationUrl = _commonLinkUtility.GetConfirmationUrl(email, ConfirmType.EmailActivation, null, user.Id);
2022-04-14 19:23:57 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonActivateEmail;
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
Actions.ActivateEmail,
_studioNotifyHelper.RecipientFromEmail(email, false),
new[] { EMailSenderName },
new TagValue(Tags.InviteLink, confirmationUrl),
TagValues.GreenButton(greenButtonText, confirmationUrl),
new TagValue(Tags.UserDisplayName, (user.DisplayUserName(_displayUserSettingsHelper) ?? string.Empty).Trim()));
2022-03-17 15:13:38 +00:00
}
2022-06-16 15:34:38 +00:00
public void SendEmailRoomInvite(string email, string confirmationUrl)
{
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonConfirmRoomInvite;
_client.SendNoticeToAsync(
Actions.RoomInvite,
_studioNotifyHelper.RecipientFromEmail(email, false),
new[] { EMailSenderName },
new TagValue(Tags.InviteLink, confirmationUrl),
TagValues.GreenButton(greenButtonText, confirmationUrl));
}
2022-03-17 15:13:38 +00:00
#endregion
#region MailServer
public void SendMailboxCreated(List<string> toEmails, string username, string address)
{
SendMailboxCreated(toEmails, username, address, null, null, -1, -1, null);
}
public void SendMailboxCreated(List<string> toEmails, string username, string address, string server,
string encyption, int portImap, int portSmtp, string login, bool skipSettings = false)
{
var tags = new List<ITagValue>
{
new TagValue(Tags.UserName, username ?? string.Empty),
new TagValue(Tags.Address, address ?? string.Empty)
};
2022-03-17 15:13:38 +00:00
if (!skipSettings)
{
2022-04-14 19:23:57 +00:00
var link = $"{_commonLinkUtility.GetFullAbsolutePath("~").TrimEnd('/')}/addons/mail/#accounts/changepwd={address}";
2022-03-17 15:13:38 +00:00
tags.Add(new TagValue(Tags.MyStaffLink, link));
tags.Add(new TagValue(Tags.Server, server));
tags.Add(new TagValue(Tags.Encryption, encyption ?? string.Empty));
tags.Add(new TagValue(Tags.ImapPort, portImap.ToString(CultureInfo.InvariantCulture)));
tags.Add(new TagValue(Tags.SmtpPort, portSmtp.ToString(CultureInfo.InvariantCulture)));
tags.Add(new TagValue(Tags.Login, login));
}
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
skipSettings
? Actions.MailboxWithoutSettingsCreated
: Actions.MailboxCreated,
null,
_studioNotifyHelper.RecipientFromEmail(toEmails, false),
new[] { EMailSenderName });
2022-03-17 15:13:38 +00:00
}
public void SendMailboxPasswordChanged(List<string> toEmails, string username, string address)
{
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
Actions.MailboxPasswordChanged,
null,
_studioNotifyHelper.RecipientFromEmail(toEmails, false),
new[] { EMailSenderName },
new TagValue(Tags.UserName, username ?? string.Empty),
new TagValue(Tags.Address, address ?? string.Empty));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
#endregion
2022-03-17 15:13:38 +00:00
public void SendMsgMobilePhoneChange(UserInfo userInfo)
{
2022-04-14 19:23:57 +00:00
var confirmationUrl = _commonLinkUtility.GetConfirmationUrl(userInfo.Email.ToLower(), ConfirmType.PhoneActivation);
2022-04-14 19:23:57 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonChangePhone;
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
Actions.PhoneChange,
_studioNotifyHelper.RecipientFromEmail(userInfo.Email, false),
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, confirmationUrl));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
public void SendMsgTfaReset(UserInfo userInfo)
{
2022-04-14 19:23:57 +00:00
var confirmationUrl = _commonLinkUtility.GetConfirmationUrl(userInfo.Email.ToLower(), ConfirmType.TfaActivation);
2022-04-14 19:23:57 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonChangeTfa;
2022-03-17 15:13:38 +00:00
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
Actions.TfaChange,
_studioNotifyHelper.RecipientFromEmail(userInfo.Email, false),
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, confirmationUrl));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
public void UserHasJoin()
{
2022-04-14 19:23:57 +00:00
if (!_coreBaseSettings.Personal)
{
2022-04-14 19:23:57 +00:00
_client.SendNoticeAsync(Actions.UserHasJoin, null);
}
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
public void SendJoinMsg(string email, EmployeeType emplType)
{
2022-04-14 19:23:57 +00:00
var inviteUrl = _commonLinkUtility.GetConfirmationUrl(email, ConfirmType.EmpInvite, (int)emplType)
+ string.Format("&emplType={0}", (int)emplType);
2022-04-14 19:23:57 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonJoin;
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
Actions.JoinUsers,
_studioNotifyHelper.RecipientFromEmail(email, true),
new[] { EMailSenderName },
new TagValue(Tags.InviteLink, inviteUrl),
TagValues.GreenButton(greenButtonText, inviteUrl));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
public void UserInfoAddedAfterInvite(UserInfo newUserInfo)
{
2022-04-14 19:23:57 +00:00
if (!_userManager.UserExists(newUserInfo))
{
return;
}
2022-03-17 15:13:38 +00:00
INotifyAction notifyAction;
var footer = "social";
2022-04-14 19:23:57 +00:00
if (_coreBaseSettings.Personal)
2022-03-17 15:13:38 +00:00
{
2022-04-14 19:23:57 +00:00
if (_coreBaseSettings.CustomMode)
2020-09-18 14:45:59 +00:00
{
2022-03-17 15:13:38 +00:00
notifyAction = Actions.PersonalCustomModeAfterRegistration1;
footer = "personalCustomMode";
2020-09-18 14:45:59 +00:00
}
else
{
2022-03-17 15:13:38 +00:00
notifyAction = Actions.PersonalAfterRegistration1;
footer = "personal";
}
2022-03-17 15:13:38 +00:00
}
2022-04-14 19:23:57 +00:00
else if (_tenantExtra.Enterprise)
2022-03-17 15:13:38 +00:00
{
2022-04-14 19:23:57 +00:00
var defaultRebranding = MailWhiteLabelSettings.IsDefault(_settingsManager);
2022-03-17 15:13:38 +00:00
notifyAction = defaultRebranding
? Actions.EnterpriseUserWelcomeV10
Merge branch 'feature/backend-refactor' into feature/warnings # Conflicts: # common/ASC.Common/Threading/DistributedTaskProgress.cs # common/ASC.Common/Threading/DistributedTaskQueue.cs # common/ASC.Core.Common/Configuration/AmiPublicDnsSyncService.cs # common/ASC.Core.Common/Notify/Engine/NotifyRequest.cs # common/ASC.Core.Common/Notify/Model/NotifyClientImpl.cs # common/ASC.Core.Common/Security/EmailValidationKeyProvider.cs # common/ASC.Data.Reassigns/QueueWorker.cs # common/ASC.Data.Reassigns/ReassignProgressItem.cs # common/ASC.Data.Reassigns/RemoveProgressItem.cs # common/ASC.Data.Storage/StaticUploader.cs # products/ASC.Files/Core/ApiModels/ResponseDto/FileDto.cs # products/ASC.Files/Core/ApiModels/ResponseDto/FolderDto.cs # products/ASC.Files/Core/Core/Dao/TeamlabDao/FileDao.cs # products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs # products/ASC.Files/Core/Core/Dao/TeamlabDao/TagDao.cs # products/ASC.Files/Core/Core/Thirdparty/Box/BoxDaoBase.cs # products/ASC.Files/Core/Core/Thirdparty/Dropbox/DropboxDaoBase.cs # products/ASC.Files/Core/Core/Thirdparty/GoogleDrive/GoogleDriveDaoBase.cs # products/ASC.Files/Core/Core/Thirdparty/IThirdPartyProviderDao.cs # products/ASC.Files/Core/Core/Thirdparty/OneDrive/OneDriveDaoBase.cs # products/ASC.Files/Core/Core/Thirdparty/ProviderDao/ProviderSecutiryDao.cs # products/ASC.Files/Core/Core/Thirdparty/Sharpbox/SharpBoxDaoBase.cs # products/ASC.Files/Core/HttpHandlers/FileHandler.ashx.cs # products/ASC.Files/Core/HttpHandlers/ThirdPartyAppHandler.ashx.cs # products/ASC.Files/Core/HttpHandlers/docusignhandler.ashx.cs # products/ASC.Files/Core/Services/DocumentService/DocumentServiceTracker.cs # products/ASC.Files/Core/Services/WCFService/FileOperations/FileDownloadOperation.cs # products/ASC.Files/Core/Services/WCFService/FileOperations/FileOperation.cs # products/ASC.Files/Core/Utils/EntryManager.cs # web/ASC.Web.Core/CollaboratorSettings.cs # web/ASC.Web.Core/CustomNavigationSettings.cs # web/ASC.Web.Core/EmailActivationSettings.cs # web/ASC.Web.Core/Notify/NotifyConfiguration.cs # web/ASC.Web.Core/Notify/SpamEmailSettings.cs # web/ASC.Web.Core/Notify/StudioNotifyHelper.cs # web/ASC.Web.Core/Notify/StudioNotifyService.cs # web/ASC.Web.Core/Notify/StudioNotifyServiceSender.cs # web/ASC.Web.Core/Notify/StudioPeriodicNotify.cs # web/ASC.Web.Core/Notify/StudioWhatsNewNotify.cs # web/ASC.Web.Core/PersonalSettings.cs # web/ASC.Web.Core/PrivacyRoomSettings.cs # web/ASC.Web.Core/PromotionsSettings.cs # web/ASC.Web.Core/QuotaSync.cs # web/ASC.Web.Core/Sms/SmsSender.cs # web/ASC.Web.Core/Sms/StudioSmsNotificationSettings.cs # web/ASC.Web.Core/StudioAdminMessageSettings.cs # web/ASC.Web.Core/StudioDefaultPageSettings.cs # web/ASC.Web.Core/StudioTrustedDomainSettings.cs # web/ASC.Web.Core/TariffSettings.cs # web/ASC.Web.Core/Tfa/TfaAppAuthSettings.cs # web/ASC.Web.Core/Tfa/TfaAppUserSettings.cs # web/ASC.Web.Core/TipsSettings.cs # web/ASC.Web.Core/Users/CustomNamingPeople.cs # web/ASC.Web.Core/Users/UserHelpTourSettings.cs # web/ASC.Web.Core/Users/UserPhotoManager.cs # web/ASC.Web.Core/Users/UserPhotoThumbnailManager.cs # web/ASC.Web.Core/Users/UserPhotoThumbnailSettings.cs # web/ASC.Web.Core/Utility/ColorThemesSettings.cs # web/ASC.Web.Core/Utility/PasswordSettings.cs # web/ASC.Web.Core/Utility/Settings/TenantAccessSettings.cs # web/ASC.Web.Core/Utility/Settings/WebItemSettings.cs # web/ASC.Web.Core/Utility/Settings/WizardSettings.cs # web/ASC.Web.Core/Utility/TenantExtra.cs # web/ASC.Web.Core/WhiteLabel/AdditionalWhiteLabelSettings.cs # web/ASC.Web.Core/WhiteLabel/CompanyWhiteLabelSettings.cs # web/ASC.Web.Core/WhiteLabel/TenantInfoSettings.cs # web/ASC.Web.Core/WhiteLabel/TenantWhiteLabelSettings.cs
2022-04-14 12:21:06 +00:00
: _coreBaseSettings.CustomMode
2022-03-17 15:13:38 +00:00
? Actions.EnterpriseWhitelabelUserWelcomeCustomMode
: Actions.EnterpriseWhitelabelUserWelcomeV10;
footer = null;
}
2022-04-14 19:23:57 +00:00
else if (_tenantExtra.Opensource)
2022-03-17 15:13:38 +00:00
{
notifyAction = Actions.OpensourceUserWelcomeV11;
footer = "opensource";
}
else
{
notifyAction = Actions.SaasUserWelcomeV115;
}
2022-04-14 19:23:57 +00:00
string greenButtonText() => _tenantExtra.Enterprise
? WebstudioNotifyPatternResource.ButtonAccessYourPortal
: WebstudioNotifyPatternResource.ButtonAccessYouWebOffice;
2022-03-17 15:13:38 +00:00
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
notifyAction,
_studioNotifyHelper.RecipientFromEmail(newUserInfo.Email, false),
new[] { EMailSenderName },
new TagValue(Tags.UserName, newUserInfo.FirstName.HtmlEncode()),
new TagValue(Tags.MyStaffLink, GetMyStaffLink()),
TagValues.GreenButton(greenButtonText, _commonLinkUtility.GetFullAbsolutePath("~").TrimEnd('/')),
new TagValue(CommonTags.Footer, footer),
new TagValue(CommonTags.MasterTemplate, _coreBaseSettings.Personal ? "HtmlMasterPersonal" : "HtmlMaster"));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
public void GuestInfoAddedAfterInvite(UserInfo newUserInfo)
{
2022-04-14 19:23:57 +00:00
if (!_userManager.UserExists(newUserInfo))
{
return;
}
2022-03-17 15:13:38 +00:00
INotifyAction notifyAction;
var footer = "social";
2022-04-14 19:23:57 +00:00
if (_tenantExtra.Enterprise)
{
2022-04-14 19:23:57 +00:00
var defaultRebranding = MailWhiteLabelSettings.IsDefault(_settingsManager);
2022-03-17 15:13:38 +00:00
notifyAction = defaultRebranding ? Actions.EnterpriseGuestWelcomeV10 : Actions.EnterpriseWhitelabelGuestWelcomeV10;
footer = null;
}
2022-04-14 19:23:57 +00:00
else if (_tenantExtra.Opensource)
2022-03-17 15:13:38 +00:00
{
notifyAction = Actions.OpensourceGuestWelcomeV11;
footer = "opensource";
}
else
{
notifyAction = Actions.SaasGuestWelcomeV115;
}
2022-04-14 19:23:57 +00:00
string greenButtonText() => _tenantExtra.Enterprise
? WebstudioNotifyPatternResource.ButtonAccessYourPortal
: WebstudioNotifyPatternResource.ButtonAccessYouWebOffice;
2022-03-17 15:13:38 +00:00
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
notifyAction,
_studioNotifyHelper.RecipientFromEmail(newUserInfo.Email, false),
new[] { EMailSenderName },
new TagValue(Tags.UserName, newUserInfo.FirstName.HtmlEncode()),
new TagValue(Tags.MyStaffLink, GetMyStaffLink()),
TagValues.GreenButton(greenButtonText, _commonLinkUtility.GetFullAbsolutePath("~").TrimEnd('/')),
new TagValue(CommonTags.Footer, footer));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
public void UserInfoActivation(UserInfo newUserInfo)
{
if (newUserInfo.IsActive)
{
throw new ArgumentException("User is already activated!");
}
2022-03-17 15:13:38 +00:00
INotifyAction notifyAction;
var footer = "social";
2022-04-14 19:23:57 +00:00
if (_tenantExtra.Enterprise)
2022-03-17 15:13:38 +00:00
{
2022-04-14 19:23:57 +00:00
var defaultRebranding = MailWhiteLabelSettings.IsDefault(_settingsManager);
2022-03-17 15:13:38 +00:00
notifyAction = defaultRebranding ? Actions.EnterpriseUserActivationV10 : Actions.EnterpriseWhitelabelUserActivationV10;
footer = null;
}
2022-04-14 19:23:57 +00:00
else if (_tenantExtra.Opensource)
{
2022-03-17 15:13:38 +00:00
notifyAction = Actions.OpensourceUserActivationV11;
footer = "opensource";
}
else
{
notifyAction = Actions.SaasUserActivationV115;
}
2022-03-17 15:13:38 +00:00
var confirmationUrl = GenerateActivationConfirmUrl(newUserInfo);
2022-04-14 19:23:57 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonAccept;
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
notifyAction,
_studioNotifyHelper.RecipientFromEmail(newUserInfo.Email, false),
new[] { EMailSenderName },
new TagValue(Tags.ActivateUrl, confirmationUrl),
TagValues.GreenButton(greenButtonText, confirmationUrl),
new TagValue(Tags.UserName, newUserInfo.FirstName.HtmlEncode()),
new TagValue(CommonTags.Footer, footer));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
public void GuestInfoActivation(UserInfo newUserInfo)
{
if (newUserInfo.IsActive)
{
throw new ArgumentException("User is already activated!");
}
2022-03-17 15:13:38 +00:00
INotifyAction notifyAction;
var footer = "social";
2022-04-14 19:23:57 +00:00
if (_tenantExtra.Enterprise)
2022-03-17 15:13:38 +00:00
{
2022-04-14 19:23:57 +00:00
var defaultRebranding = MailWhiteLabelSettings.IsDefault(_settingsManager);
2022-03-17 15:13:38 +00:00
notifyAction = defaultRebranding ? Actions.EnterpriseGuestActivationV10 : Actions.EnterpriseWhitelabelGuestActivationV10;
footer = null;
}
2022-04-14 19:23:57 +00:00
else if (_tenantExtra.Opensource)
2022-03-17 15:13:38 +00:00
{
notifyAction = Actions.OpensourceGuestActivationV11;
footer = "opensource";
}
else
{
notifyAction = Actions.SaasGuestActivationV115;
}
2022-03-17 15:13:38 +00:00
var confirmationUrl = GenerateActivationConfirmUrl(newUserInfo);
2022-04-14 19:23:57 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonAccept;
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
notifyAction,
_studioNotifyHelper.RecipientFromEmail(newUserInfo.Email, false),
new[] { EMailSenderName },
new TagValue(Tags.ActivateUrl, confirmationUrl),
TagValues.GreenButton(greenButtonText, confirmationUrl),
new TagValue(Tags.UserName, newUserInfo.FirstName.HtmlEncode()),
new TagValue(CommonTags.Footer, footer));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
public void SendMsgProfileDeletion(UserInfo user)
{
2022-04-14 19:23:57 +00:00
var confirmationUrl = _commonLinkUtility.GetConfirmationUrl(user.Email, ConfirmType.ProfileRemove, _authContext.CurrentAccount.ID, _authContext.CurrentAccount.ID);
2022-04-14 19:23:57 +00:00
string greenButtonText() => _coreBaseSettings.Personal ? WebstudioNotifyPatternResource.ButtonConfirmTermination : WebstudioNotifyPatternResource.ButtonRemoveProfile;
2022-04-14 19:23:57 +00:00
var action = _coreBaseSettings.Personal
? (_coreBaseSettings.CustomMode ? Actions.PersonalCustomModeProfileDelete : Actions.PersonalProfileDelete)
: Actions.ProfileDelete;
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
action,
_studioNotifyHelper.RecipientFromEmail(user.Email, false),
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, confirmationUrl),
new TagValue(CommonTags.Culture, user.GetCulture().Name));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
public void SendMsgProfileHasDeletedItself(UserInfo user)
{
2022-04-14 19:23:57 +00:00
var tenant = _tenantManager.GetCurrentTenant();
var admins = _userManager.GetUsers()
.Where(u => _webItemSecurity.IsProductAdministrator(WebItemManager.PeopleProductID, u.Id));
2022-03-17 15:13:38 +00:00
ThreadPool.QueueUserWorkItem(_ =>
2020-01-23 08:52:07 +00:00
{
2022-03-17 15:13:38 +00:00
try
2020-01-23 08:52:07 +00:00
{
2022-04-14 19:23:57 +00:00
_tenantManager.SetCurrentTenant(tenant);
2022-03-17 15:13:38 +00:00
foreach (var admin in admins)
2020-01-23 08:52:07 +00:00
{
2022-03-17 15:13:38 +00:00
var culture = string.IsNullOrEmpty(admin.CultureName) ? tenant.GetCulture() : admin.GetCulture();
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
Actions.ProfileHasDeletedItself,
null,
new IRecipient[] { admin },
new[] { EMailSenderName },
new TagValue(Tags.FromUserName, user.DisplayUserName(_displayUserSettingsHelper)),
new TagValue(Tags.FromUserLink, GetUserProfileLink(user)));
2020-01-23 08:52:07 +00:00
}
2022-03-17 15:13:38 +00:00
}
catch (Exception ex)
{
2022-05-13 14:48:49 +00:00
_log.ErrorSendMsgProfileHasDeletedItself(ex);
2022-03-17 15:13:38 +00:00
}
});
2020-01-23 08:52:07 +00:00
2022-03-17 15:13:38 +00:00
}
public void SendMsgReassignsCompleted(Guid recipientId, UserInfo fromUser, UserInfo toUser)
{
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
Actions.ReassignsCompleted,
new[] { _studioNotifyHelper.ToRecipient(recipientId) },
new[] { EMailSenderName },
new TagValue(Tags.UserName, _displayUserSettingsHelper.GetFullUserName(recipientId)),
new TagValue(Tags.FromUserName, fromUser.DisplayUserName(_displayUserSettingsHelper)),
new TagValue(Tags.FromUserLink, GetUserProfileLink(fromUser)),
new TagValue(Tags.ToUserName, toUser.DisplayUserName(_displayUserSettingsHelper)),
new TagValue(Tags.ToUserLink, GetUserProfileLink(toUser)));
2022-03-17 15:13:38 +00:00
}
public void SendMsgReassignsFailed(Guid recipientId, UserInfo fromUser, UserInfo toUser, string message)
{
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
Actions.ReassignsFailed,
new[] { _studioNotifyHelper.ToRecipient(recipientId) },
new[] { EMailSenderName },
new TagValue(Tags.UserName, _displayUserSettingsHelper.GetFullUserName(recipientId)),
new TagValue(Tags.FromUserName, fromUser.DisplayUserName(_displayUserSettingsHelper)),
new TagValue(Tags.FromUserLink, GetUserProfileLink(fromUser)),
new TagValue(Tags.ToUserName, toUser.DisplayUserName(_displayUserSettingsHelper)),
new TagValue(Tags.ToUserLink, GetUserProfileLink(toUser)),
new TagValue(Tags.Message, message));
2022-03-17 15:13:38 +00:00
}
public void SendMsgRemoveUserDataCompleted(Guid recipientId, UserInfo user, string fromUserName, long docsSpace, long crmSpace, long mailSpace, long talkSpace)
{
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
_coreBaseSettings.CustomMode ? Actions.RemoveUserDataCompletedCustomMode : Actions.RemoveUserDataCompleted,
new[] { _studioNotifyHelper.ToRecipient(recipientId) },
new[] { EMailSenderName },
new TagValue(Tags.UserName, _displayUserSettingsHelper.GetFullUserName(recipientId)),
new TagValue(Tags.FromUserName, fromUserName.HtmlEncode()),
new TagValue(Tags.FromUserLink, GetUserProfileLink(user)),
new TagValue("DocsSpace", FileSizeComment.FilesSizeToString(docsSpace)),
new TagValue("CrmSpace", FileSizeComment.FilesSizeToString(crmSpace)),
new TagValue("MailSpace", FileSizeComment.FilesSizeToString(mailSpace)),
new TagValue("TalkSpace", FileSizeComment.FilesSizeToString(talkSpace)));
2022-03-17 15:13:38 +00:00
}
2020-01-23 08:52:07 +00:00
2022-03-17 15:13:38 +00:00
public void SendMsgRemoveUserDataFailed(Guid recipientId, UserInfo user, string fromUserName, string message)
{
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
Actions.RemoveUserDataFailed,
new[] { _studioNotifyHelper.ToRecipient(recipientId) },
new[] { EMailSenderName },
new TagValue(Tags.UserName, _displayUserSettingsHelper.GetFullUserName(recipientId)),
new TagValue(Tags.FromUserName, fromUserName.HtmlEncode()),
new TagValue(Tags.FromUserLink, GetUserProfileLink(user)),
new TagValue(Tags.Message, message));
2022-03-17 15:13:38 +00:00
}
public void SendAdminWelcome(UserInfo newUserInfo)
{
2022-04-14 19:23:57 +00:00
if (!_userManager.UserExists(newUserInfo))
{
return;
}
2022-03-17 15:13:38 +00:00
if (!newUserInfo.IsActive)
{
2022-03-17 15:13:38 +00:00
throw new ArgumentException("User is not activated yet!");
}
2022-03-17 15:13:38 +00:00
INotifyAction notifyAction;
var tagValues = new List<ITagValue>();
2022-04-14 19:23:57 +00:00
if (_tenantExtra.Enterprise)
{
2022-04-14 19:23:57 +00:00
var defaultRebranding = MailWhiteLabelSettings.IsDefault(_settingsManager);
2022-03-17 15:13:38 +00:00
notifyAction = defaultRebranding ? Actions.EnterpriseAdminWelcomeV10 : Actions.EnterpriseWhitelabelAdminWelcomeV10;
2022-04-14 19:23:57 +00:00
tagValues.Add(TagValues.GreenButton(() => WebstudioNotifyPatternResource.ButtonAccessControlPanel, _commonLinkUtility.GetFullAbsolutePath(_setupInfo.ControlPanelUrl)));
2022-03-17 15:13:38 +00:00
}
2022-04-14 19:23:57 +00:00
else if (_tenantExtra.Opensource)
{
2022-03-17 15:13:38 +00:00
notifyAction = Actions.OpensourceAdminWelcomeV11;
tagValues.Add(new TagValue(CommonTags.Footer, "opensource"));
2022-04-14 19:23:57 +00:00
tagValues.Add(new TagValue(Tags.ControlPanelUrl, _commonLinkUtility.GetFullAbsolutePath(_setupInfo.ControlPanelUrl).TrimEnd('/')));
}
2022-03-17 15:13:38 +00:00
else
{
2022-03-17 15:13:38 +00:00
notifyAction = Actions.SaasAdminWelcomeV115;
//tagValues.Add(TagValues.GreenButton(() => WebstudioNotifyPatternResource.ButtonConfigureRightNow, CommonLinkUtility.GetFullAbsolutePath(CommonLinkUtility.GetAdministration(ManagementType.General))));
2022-03-17 15:13:38 +00:00
tagValues.Add(new TagValue(CommonTags.Footer, "common"));
}
tagValues.Add(new TagValue(Tags.UserName, newUserInfo.FirstName.HtmlEncode()));
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
notifyAction,
_studioNotifyHelper.RecipientFromEmail(newUserInfo.Email, false),
new[] { EMailSenderName },
tagValues.ToArray());
2022-03-17 15:13:38 +00:00
}
#region Portal Deactivation & Deletion
public void SendMsgPortalDeactivation(Tenant t, string deactivateUrl, string activateUrl)
{
2022-04-14 19:23:57 +00:00
var u = _userManager.GetUsers(t.OwnerId);
2022-03-17 15:13:38 +00:00
2022-04-14 19:23:57 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonDeactivatePortal;
2022-03-17 15:13:38 +00:00
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
Actions.PortalDeactivate,
new IRecipient[] { u },
new[] { EMailSenderName },
new TagValue(Tags.ActivateUrl, activateUrl),
TagValues.GreenButton(greenButtonText, deactivateUrl),
new TagValue(Tags.OwnerName, u.DisplayUserName(_displayUserSettingsHelper)));
2022-03-17 15:13:38 +00:00
}
public void SendMsgPortalDeletion(Tenant t, string url, bool showAutoRenewText)
{
2022-04-14 19:23:57 +00:00
var u = _userManager.GetUsers(t.OwnerId);
2022-03-17 15:13:38 +00:00
2022-04-14 19:23:57 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonDeletePortal;
2022-03-17 15:13:38 +00:00
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
Actions.PortalDelete,
new IRecipient[] { u },
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, url),
new TagValue(Tags.AutoRenew, showAutoRenewText.ToString()),
new TagValue(Tags.OwnerName, u.DisplayUserName(_displayUserSettingsHelper)));
2022-03-17 15:13:38 +00:00
}
public void SendMsgPortalDeletionSuccess(UserInfo owner, string url)
{
2022-04-14 19:23:57 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonLeaveFeedback;
2022-03-17 15:13:38 +00:00
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
Actions.PortalDeleteSuccessV115,
new IRecipient[] { owner },
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, url),
new TagValue(Tags.OwnerName, owner.DisplayUserName(_displayUserSettingsHelper)));
2022-03-17 15:13:38 +00:00
}
#endregion
public void SendMsgDnsChange(Tenant t, string confirmDnsUpdateUrl, string portalAddress, string portalDns)
{
2022-04-14 19:23:57 +00:00
var u = _userManager.GetUsers(t.OwnerId);
2022-03-17 15:13:38 +00:00
2022-04-14 19:23:57 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonConfirmPortalAddressChange;
2022-03-17 15:13:38 +00:00
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
Actions.DnsChange,
new IRecipient[] { u },
new[] { EMailSenderName },
new TagValue("ConfirmDnsUpdate", confirmDnsUpdateUrl),//TODO: Tag is deprecated and replaced by TagGreenButton
TagValues.GreenButton(greenButtonText, confirmDnsUpdateUrl),
new TagValue("PortalAddress", AddHttpToUrl(portalAddress)),
new TagValue("PortalDns", AddHttpToUrl(portalDns ?? string.Empty)),
new TagValue(Tags.OwnerName, u.DisplayUserName(_displayUserSettingsHelper)));
2022-03-17 15:13:38 +00:00
}
public void SendMsgConfirmChangeOwner(UserInfo owner, UserInfo newOwner, string confirmOwnerUpdateUrl)
{
2022-04-14 19:23:57 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonConfirmPortalOwnerUpdate;
2022-03-17 15:13:38 +00:00
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
Actions.ConfirmOwnerChange,
null,
new IRecipient[] { owner },
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, confirmOwnerUpdateUrl),
new TagValue(Tags.UserName, newOwner.DisplayUserName(_displayUserSettingsHelper)),
new TagValue(Tags.OwnerName, owner.DisplayUserName(_displayUserSettingsHelper)));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
public void SendCongratulations(UserInfo u)
{
try
{
INotifyAction notifyAction;
2022-03-17 15:13:38 +00:00
var footer = "common";
2022-04-14 19:23:57 +00:00
if (_tenantExtra.Enterprise)
{
2022-04-14 19:23:57 +00:00
var defaultRebranding = MailWhiteLabelSettings.IsDefault(_settingsManager);
2022-03-17 15:13:38 +00:00
notifyAction = defaultRebranding ? Actions.EnterpriseAdminActivationV10 : Actions.EnterpriseWhitelabelAdminActivationV10;
footer = null;
2020-09-18 14:45:59 +00:00
}
2022-04-14 19:23:57 +00:00
else if (_tenantExtra.Opensource)
2020-09-18 14:45:59 +00:00
{
2022-03-17 15:13:38 +00:00
notifyAction = Actions.OpensourceAdminActivationV11;
footer = "opensource";
}
else
{
2022-03-17 15:13:38 +00:00
notifyAction = Actions.SaasAdminActivationV115;
}
2022-04-14 19:23:57 +00:00
var confirmationUrl = _commonLinkUtility.GetConfirmationUrl(u.Email, ConfirmType.EmailActivation);
2022-03-17 15:13:38 +00:00
confirmationUrl += "&first=true";
2022-04-14 19:23:57 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonConfirm;
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
notifyAction,
_studioNotifyHelper.RecipientFromEmail(u.Email, false),
new[] { EMailSenderName },
new TagValue(Tags.UserName, u.FirstName.HtmlEncode()),
new TagValue(Tags.MyStaffLink, GetMyStaffLink()),
new TagValue(Tags.ActivateUrl, confirmationUrl),
TagValues.GreenButton(greenButtonText, confirmationUrl),
new TagValue(CommonTags.Footer, footer));
}
2022-03-17 15:13:38 +00:00
catch (Exception error)
{
2022-05-13 14:48:49 +00:00
_log.ErrorSendCongratulations(error);
2022-03-17 15:13:38 +00:00
}
}
2022-03-17 15:13:38 +00:00
#region Personal
2022-03-17 15:13:38 +00:00
public void SendInvitePersonal(string email, string additionalMember = "")
{
2022-04-14 19:23:57 +00:00
var newUserInfo = _userManager.GetUserByEmail(email);
if (_userManager.UserExists(newUserInfo))
{
return;
}
2022-04-14 19:23:57 +00:00
var lang = _coreBaseSettings.CustomMode
2022-03-17 15:13:38 +00:00
? "ru-RU"
: Thread.CurrentThread.CurrentUICulture.Name;
2022-04-14 19:23:57 +00:00
var culture = _setupInfo.GetPersonalCulture(lang);
2022-04-14 19:23:57 +00:00
var confirmUrl = _commonLinkUtility.GetConfirmationUrl(email, ConfirmType.EmpInvite, (int)EmployeeType.User)
+ "&emplType=" + (int)EmployeeType.User
+ "&lang=" + culture.Key
+ additionalMember;
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
_coreBaseSettings.CustomMode ? Actions.PersonalCustomModeConfirmation : Actions.PersonalConfirmation,
_studioNotifyHelper.RecipientFromEmail(email, false),
new[] { EMailSenderName },
new TagValue(Tags.InviteLink, confirmUrl),
new TagValue(CommonTags.Footer, _coreBaseSettings.CustomMode ? "personalCustomMode" : "personal"),
new TagValue(CommonTags.Culture, Thread.CurrentThread.CurrentUICulture.Name));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
public void SendAlreadyExist(string email)
{
2022-04-14 19:23:57 +00:00
var userInfo = _userManager.GetUserByEmail(email);
if (!_userManager.UserExists(userInfo))
{
return;
}
2022-04-14 19:23:57 +00:00
var portalUrl = _commonLinkUtility.GetFullAbsolutePath("~").TrimEnd('/');
2022-04-14 19:23:57 +00:00
var hash = _authentication.GetUserPasswordStamp(userInfo.Id).ToString("s");
2022-04-14 19:23:57 +00:00
var linkToRecovery = _commonLinkUtility.GetConfirmationUrl(userInfo.Email, ConfirmType.PasswordChange, hash, userInfo.Id);
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
_coreBaseSettings.CustomMode ? Actions.PersonalCustomModeAlreadyExist : Actions.PersonalAlreadyExist,
_studioNotifyHelper.RecipientFromEmail(email, false),
new[] { EMailSenderName },
new TagValue(Tags.PortalUrl, portalUrl),
new TagValue(Tags.LinkToRecovery, linkToRecovery),
new TagValue(CommonTags.Footer, _coreBaseSettings.CustomMode ? "personalCustomMode" : "personal"),
new TagValue(CommonTags.Culture, Thread.CurrentThread.CurrentUICulture.Name));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
public void SendUserWelcomePersonal(UserInfo newUserInfo)
{
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
_coreBaseSettings.CustomMode ? Actions.PersonalCustomModeAfterRegistration1 : Actions.PersonalAfterRegistration1,
_studioNotifyHelper.RecipientFromEmail(newUserInfo.Email, true),
new[] { EMailSenderName },
new TagValue(CommonTags.Footer, _coreBaseSettings.CustomMode ? "personalCustomMode" : "personal"),
new TagValue(CommonTags.MasterTemplate, "HtmlMasterPersonal"));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
#endregion
2022-03-17 15:13:38 +00:00
#region Migration Portal
2019-08-15 12:04:42 +00:00
2022-03-17 15:13:38 +00:00
public void PortalRenameNotify(Tenant tenant, string oldVirtualRootPath)
{
2022-04-14 19:23:57 +00:00
var users = _userManager.GetUsers()
.Where(u => u.ActivationStatus.HasFlag(EmployeeActivationStatus.Activated));
2022-04-14 19:23:57 +00:00
try
{
_tenantManager.SetCurrentTenant(tenant);
2022-04-14 19:23:57 +00:00
foreach (var u in users)
{
2022-04-14 19:23:57 +00:00
var culture = string.IsNullOrEmpty(u.CultureName) ? tenant.GetCulture() : u.GetCulture();
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
_client.SendNoticeToAsync(
Actions.PortalRename,
new[] { _studioNotifyHelper.ToRecipient(u.Id) },
new[] { EMailSenderName },
new TagValue(Tags.PortalUrl, oldVirtualRootPath),
new TagValue(Tags.UserDisplayName, u.DisplayUserName(_displayUserSettingsHelper)));
}
2022-04-14 19:23:57 +00:00
}
catch (Exception ex)
{
2022-05-13 14:48:49 +00:00
_log.ErrorPortalRenameNotify(ex);
2022-04-14 19:23:57 +00:00
}
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
#endregion
2022-03-17 15:13:38 +00:00
#region Helpers
2022-03-17 15:13:38 +00:00
private string GetMyStaffLink()
{
2022-04-14 19:23:57 +00:00
return _commonLinkUtility.GetFullAbsolutePath(_commonLinkUtility.GetMyStaff());
2022-03-17 15:13:38 +00:00
}
2021-11-16 17:40:15 +00:00
2022-03-17 15:13:38 +00:00
private string GetUserProfileLink(UserInfo userInfo)
{
2022-04-14 19:23:57 +00:00
return _commonLinkUtility.GetFullAbsolutePath(_commonLinkUtility.GetUserProfile(userInfo));
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
private static string AddHttpToUrl(string url)
{
var httpPrefix = Uri.UriSchemeHttp + Uri.SchemeDelimiter;
return !string.IsNullOrEmpty(url) && !url.StartsWith(httpPrefix) ? httpPrefix + url : url;
}
2022-03-17 15:13:38 +00:00
private string GenerateActivationConfirmUrl(UserInfo user)
{
2022-04-14 19:23:57 +00:00
var confirmUrl = _commonLinkUtility.GetConfirmationUrl(user.Email, ConfirmType.Activation, user.Id, user.Id);
2022-03-17 15:13:38 +00:00
return confirmUrl + $"&firstname={HttpUtility.UrlEncode(user.FirstName)}&lastname={HttpUtility.UrlEncode(user.LastName)}";
}
2022-03-17 15:13:38 +00:00
public void SendRegData(UserInfo u)
{
try
{
2022-04-14 19:23:57 +00:00
if (!_tenantExtra.Saas || !_coreBaseSettings.CustomMode)
{
return;
}
2022-04-14 19:23:57 +00:00
var settings = _settingsManager.LoadForDefaultTenant<AdditionalWhiteLabelSettings>();
var salesEmail = settings.SalesEmail ?? _setupInfo.SalesEmail;
2022-03-17 15:13:38 +00:00
if (string.IsNullOrEmpty(salesEmail))
{
return;
}
2022-03-17 15:13:38 +00:00
var recipient = new DirectRecipient(salesEmail, null, new[] { salesEmail }, false);
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
Actions.SaasCustomModeRegData,
null,
new IRecipient[] { recipient },
new[] { EMailSenderName },
new TagValue(Tags.UserName, u.FirstName.HtmlEncode()),
new TagValue(Tags.UserLastName, u.LastName.HtmlEncode()),
new TagValue(Tags.UserEmail, u.Email.HtmlEncode()),
new TagValue(Tags.Phone, u.MobilePhone != null ? u.MobilePhone.HtmlEncode() : "-"),
new TagValue(Tags.Date, u.CreateDate.ToShortDateString() + " " + u.CreateDate.ToShortTimeString()),
new TagValue(CommonTags.Footer, null),
TagValues.WithoutUnsubscribe());
}
2022-03-17 15:13:38 +00:00
catch (Exception error)
{
2022-05-13 14:48:49 +00:00
_log.ErrorSendRegData(error);
}
2022-03-17 15:13:38 +00:00
}
2022-03-17 15:13:38 +00:00
#endregion
2020-09-11 14:12:35 +00:00
2022-03-17 15:13:38 +00:00
#region Storage encryption
2020-09-11 14:12:35 +00:00
2022-03-17 15:13:38 +00:00
public void SendStorageEncryptionStart(string serverRootPath)
{
SendStorageEncryptionNotify(Actions.StorageEncryptionStart, false, serverRootPath);
}
2020-09-11 14:12:35 +00:00
2022-03-17 15:13:38 +00:00
public void SendStorageEncryptionSuccess(string serverRootPath)
{
SendStorageEncryptionNotify(Actions.StorageEncryptionSuccess, false, serverRootPath);
}
2020-09-11 14:12:35 +00:00
2022-03-17 15:13:38 +00:00
public void SendStorageEncryptionError(string serverRootPath)
{
SendStorageEncryptionNotify(Actions.StorageEncryptionError, true, serverRootPath);
}
2020-09-16 10:50:53 +00:00
2022-03-17 15:13:38 +00:00
public void SendStorageDecryptionStart(string serverRootPath)
{
SendStorageEncryptionNotify(Actions.StorageDecryptionStart, false, serverRootPath);
}
2020-09-16 10:50:53 +00:00
2022-03-17 15:13:38 +00:00
public void SendStorageDecryptionSuccess(string serverRootPath)
{
SendStorageEncryptionNotify(Actions.StorageDecryptionSuccess, false, serverRootPath);
}
2020-09-16 10:50:53 +00:00
2022-03-17 15:13:38 +00:00
public void SendStorageDecryptionError(string serverRootPath)
{
SendStorageEncryptionNotify(Actions.StorageDecryptionError, true, serverRootPath);
}
2020-09-16 10:50:53 +00:00
2022-03-17 15:13:38 +00:00
private void SendStorageEncryptionNotify(INotifyAction action, bool notifyAdminsOnly, string serverRootPath)
{
var users = notifyAdminsOnly
2022-03-31 17:32:46 +00:00
? _userManager.GetUsersByGroup(Constants.GroupAdmin.ID)
: _userManager.GetUsers().Where(u => u.ActivationStatus.HasFlag(EmployeeActivationStatus.Activated));
2020-09-16 10:50:53 +00:00
2022-03-17 15:13:38 +00:00
foreach (var u in users)
2020-09-16 10:50:53 +00:00
{
2022-04-14 19:23:57 +00:00
_client.SendNoticeToAsync(
action,
null,
new[] { _studioNotifyHelper.ToRecipient(u.Id) },
new[] { EMailSenderName },
new TagValue(Tags.UserName, u.FirstName.HtmlEncode()),
new TagValue(Tags.PortalUrl, serverRootPath),
new TagValue(Tags.ControlPanelUrl, GetControlPanelUrl(serverRootPath)));
2020-09-16 10:50:53 +00:00
}
2022-03-17 15:13:38 +00:00
}
2020-09-16 10:50:53 +00:00
2022-03-17 15:13:38 +00:00
private string GetControlPanelUrl(string serverRootPath)
{
2022-04-14 19:23:57 +00:00
var controlPanelUrl = _setupInfo.ControlPanelUrl;
2020-09-16 10:50:53 +00:00
2022-03-17 15:13:38 +00:00
if (string.IsNullOrEmpty(controlPanelUrl))
2020-09-16 10:50:53 +00:00
{
2022-03-17 15:13:38 +00:00
return string.Empty;
2020-09-16 10:50:53 +00:00
}
2022-03-17 15:13:38 +00:00
if (controlPanelUrl.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase) ||
controlPanelUrl.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
2020-09-16 10:50:53 +00:00
{
2022-03-17 15:13:38 +00:00
return controlPanelUrl;
2020-09-16 10:50:53 +00:00
}
2022-03-17 15:13:38 +00:00
return serverRootPath + "/" + controlPanelUrl.TrimStart('~', '/').TrimEnd('/');
}
2020-09-16 10:50:53 +00:00
2022-03-17 15:13:38 +00:00
#endregion
}