password reset scheduler added
This commit is contained in:
parent
c5b6c0d9f6
commit
aa59d180e2
33 changed files with 2180 additions and 1078 deletions
|
@ -1494,7 +1494,65 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return result;
|
||||
}
|
||||
|
||||
public static List<OrganizationUser> GetOrganizationUsersWithExpiredPassword(int itemId, int daysBeforeExpiration)
|
||||
{
|
||||
// load organization
|
||||
Organization org = GetOrganization(itemId);
|
||||
|
||||
if (org == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Organizations orgProxy = GetOrganizationProxy(org.ServiceId);
|
||||
|
||||
var expiredUsersAd = orgProxy.GetOrganizationUsersWithExpiredPassword(org.OrganizationId, daysBeforeExpiration);
|
||||
|
||||
var expiredUsersDb = GetOrganizationUsersPaged(itemId, null, null, null, 0, int.MaxValue).PageUsers.Where(x => expiredUsersAd.Any(z => z.SamAccountName == x.SamAccountName)).ToList();
|
||||
|
||||
foreach (var user in expiredUsersDb)
|
||||
{
|
||||
var adUser = expiredUsersAd.First(x => x.SamAccountName == user.SamAccountName);
|
||||
|
||||
user.PasswordExpirationDateTime = adUser.PasswordExpirationDateTime;
|
||||
}
|
||||
|
||||
return expiredUsersDb;
|
||||
}
|
||||
|
||||
public static void SendResetUserPasswordEmail(UserInfo owner, OrganizationUser user, string mailTo, string logoUrl)
|
||||
{
|
||||
UserSettings settings = UserController.GetUserSettings(owner.UserId, UserSettings.USER_PASSWORD_EXPIRATION_LETTER);
|
||||
|
||||
if (string.IsNullOrEmpty(logoUrl))
|
||||
{
|
||||
logoUrl = settings["LogoUrl"];
|
||||
}
|
||||
|
||||
string from = settings["From"];
|
||||
|
||||
string subject = settings["Subject"];
|
||||
string body = owner.HtmlMail ? settings["HtmlBody"] : settings["TextBody"];
|
||||
bool isHtml = owner.HtmlMail;
|
||||
|
||||
MailPriority priority = MailPriority.Normal;
|
||||
|
||||
if (!String.IsNullOrEmpty(settings["Priority"]))
|
||||
{
|
||||
priority = (MailPriority)Enum.Parse(typeof(MailPriority), settings["Priority"], true);
|
||||
}
|
||||
|
||||
Hashtable items = new Hashtable();
|
||||
|
||||
items["user"] = user;
|
||||
items["logoUrl"] = logoUrl;
|
||||
items["passwordResetLink"] = "reset link";
|
||||
|
||||
body = PackageController.EvaluateTemplate(body, items);
|
||||
|
||||
// send mail message
|
||||
//MailHelper.SendMessage(from, mailTo, string.Empty, subject, body, priority, isHtml);
|
||||
}
|
||||
|
||||
private static bool EmailAddressExists(string emailAddress)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using WebsitePanel.Providers.HostedSolution;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
{
|
||||
public class UserPasswordExpirationNotificationTask : SchedulerTask
|
||||
{
|
||||
private static readonly string TaskId = "SCHEDULE_TASK_DOMAIN_EXPIRATION";
|
||||
|
||||
// Input parameters:
|
||||
private static readonly string DaysBeforeNotify = "DAYS_BEFORE_EXPIRATION";
|
||||
|
||||
public override void DoWork()
|
||||
{
|
||||
BackgroundTask topTask = TaskManager.TopTask;
|
||||
|
||||
int daysBeforeNotify;
|
||||
|
||||
// check input parameters
|
||||
if (!int.TryParse((string)topTask.GetParamValue(DaysBeforeNotify), out daysBeforeNotify))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify 'Notify before (days)' task parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
var owner = UserController.GetUser(topTask.EffectiveUserId);
|
||||
|
||||
var packages = PackageController.GetMyPackages(topTask.EffectiveUserId);
|
||||
|
||||
foreach (var package in packages)
|
||||
{
|
||||
var organizations = ExchangeServerController.GetExchangeOrganizations(package.PackageId, true);
|
||||
|
||||
foreach (var organization in organizations)
|
||||
{
|
||||
var usersWithExpiredPasswords = OrganizationController.GetOrganizationUsersWithExpiredPassword(organization.Id, daysBeforeNotify);
|
||||
|
||||
foreach (var user in usersWithExpiredPasswords)
|
||||
{
|
||||
if (string.IsNullOrEmpty(user.PrimaryEmailAddress))
|
||||
{
|
||||
TaskManager.WriteWarning(string.Format("Unable to send email to {0} user (organization: {1}), user primary email address is not set.", user.DisplayName, organization.OrganizationId));
|
||||
continue;
|
||||
}
|
||||
|
||||
TaskManager.Write(string.Format("Email sent to {0} user (organization: {1}).", user.DisplayName, organization.OrganizationId));
|
||||
|
||||
OrganizationController.SendResetUserPasswordEmail(owner, user, user.PrimaryEmailAddress, string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// send mail message
|
||||
// MailHelper.SendMessage(mailFrom, mailTo, mailSubject, mailBody, false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -158,6 +158,7 @@
|
|||
<Compile Include="SchedulerTasks\SendMailNotificationTask.cs" />
|
||||
<Compile Include="SchedulerTasks\SuspendOverdueInvoicesTask.cs" />
|
||||
<Compile Include="SchedulerTasks\SuspendOverusedPackagesTask.cs" />
|
||||
<Compile Include="SchedulerTasks\UserPasswordExpirationNotificationTask.cs" />
|
||||
<Compile Include="SchedulerTasks\ZipFilesTask.cs" />
|
||||
<Compile Include="Scheduling\Scheduler.cs" />
|
||||
<Compile Include="Scheduling\SchedulerController.cs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue