show license message depending on setting

This commit is contained in:
Roland Gruber 2020-04-03 16:53:55 +02:00
parent 365389cd0b
commit ffb8fca488
6 changed files with 35 additions and 5 deletions

View File

@ -1,6 +1,7 @@
June 2020 7.2 June 2020 7.2
- LAM Pro: - LAM Pro:
-> EMail sending can be done via SMTP without local mail server -> EMail sending can be done via SMTP without local mail server
-> License expiration warning can be sent via email or disabled
17.03.2020 7.1 17.03.2020 7.1

View File

@ -60,6 +60,10 @@
<para>When you entered the license key then the license details can be <para>When you entered the license key then the license details can be
seen on LAM configuration overview page.</para> seen on LAM configuration overview page.</para>
<para>By default, LAM Pro will show a warning message on the login page
3 weeks before expiration. You can disable this here and/or send out an
email instead.</para>
<screenshot> <screenshot>
<mediaobject> <mediaobject>
<imageobject> <imageobject>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 70 KiB

View File

@ -3166,6 +3166,18 @@ class LAMCfgMain {
return ($type === self::LICENSE_WARNING_ALL) || ($type === self::LICENSE_WARNING_EMAIL); return ($type === self::LICENSE_WARNING_ALL) || ($type === self::LICENSE_WARNING_EMAIL);
} }
/**
* Returns if the license warning was already sent.
*
* @param int $timeStamp time stamp
*/
public function wasLicenseWarningSent($timeStamp) {
if (empty($this->licenseEmailDateSent)) {
return false;
}
return $timeStamp == $this->licenseEmailDateSent;
}
} }
?> ?>

View File

@ -452,9 +452,19 @@ function display_LoginPage($licenseValidator, $error_message) {
?> ?>
<br><br> <br><br>
<?PHP <?PHP
if (isLAMProVersion() && $cfgMain->showLicenseWarningOnScreen() && $licenseValidator->isExpiringSoon()) { if (isLAMProVersion() && $licenseValidator->isExpiringSoon()) {
$licenseMessage = sprintf(_('Your licence expires on %s. You need to purchase a new licence to be able to use LAM Pro after this date.'), $licenseValidator->getLicense()->getExpirationDate()->format('Y-m-d')); $expirationDate = $licenseValidator->getLicense()->getExpirationDate()->format('Y-m-d');
StatusMessage('WARN', $licenseMessage); $expirationTimeStamp = $licenseValidator->getLicense()->getExpirationDate()->getTimestamp();
if ($cfgMain->showLicenseWarningOnScreen()) {
$licenseMessage = sprintf(_('Your licence expires on %s. You need to purchase a new licence to be able to use LAM Pro after this date.'), $expirationDate);
StatusMessage('WARN', $licenseMessage);
}
if ($cfgMain->sendLicenseWarningByEmail() && !$cfgMain->wasLicenseWarningSent($expirationTimeStamp)) {
$cfgMain->licenseEmailDateSent = $expirationTimeStamp;
$cfgMain->save();
$mailer = new \LAM\ENV\LicenseWarningMailer($cfgMain);
$mailer->sendMail($expirationDate);
}
} }
?> ?>
<br><br> <br><br>

View File

@ -75,19 +75,22 @@ class LAMCfgMainTest extends TestCase {
* License related settings. * License related settings.
*/ */
public function testLicense() { public function testLicense() {
$timestamp = '12345';
$this->assertEquals(LAMCfgMain::LICENSE_WARNING_SCREEN, $this->conf->getLicenseWarningType()); $this->assertEquals(LAMCfgMain::LICENSE_WARNING_SCREEN, $this->conf->getLicenseWarningType());
$this->assertFalse($this->conf->wasLicenseWarningSent($timestamp));
$this->conf->licenseEmailTo = 'TO'; $this->conf->licenseEmailTo = 'TO';
$this->conf->licenseEmailFrom = 'FROM'; $this->conf->licenseEmailFrom = 'FROM';
$this->conf->licenseEmailDateSent = 'date';
$this->conf->licenseWarningType = LAMCfgMain::LICENSE_WARNING_ALL; $this->conf->licenseWarningType = LAMCfgMain::LICENSE_WARNING_ALL;
$this->conf->setLicenseLines(array('123', '456')); $this->conf->setLicenseLines(array('123', '456'));
$this->conf->licenseEmailDateSent = $timestamp;
$this->conf->save(); $this->conf->save();
$this->conf = new LAMCfgMain($this->file); $this->conf = new LAMCfgMain($this->file);
$this->assertEquals('TO', $this->conf->licenseEmailTo); $this->assertEquals('TO', $this->conf->licenseEmailTo);
$this->assertEquals('FROM', $this->conf->licenseEmailFrom); $this->assertEquals('FROM', $this->conf->licenseEmailFrom);
$this->assertEquals('date', $this->conf->licenseEmailDateSent); $this->assertEquals($timestamp, $this->conf->licenseEmailDateSent);
$this->assertTrue($this->conf->wasLicenseWarningSent($timestamp));
$this->assertEquals(LAMCfgMain::LICENSE_WARNING_ALL, $this->conf->licenseWarningType); $this->assertEquals(LAMCfgMain::LICENSE_WARNING_ALL, $this->conf->licenseWarningType);
$this->assertEquals(array('123', '456'), $this->conf->getLicenseLines()); $this->assertEquals(array('123', '456'), $this->conf->getLicenseLines());
} }