-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from dnadesign/feature/refinements
Functional refinements to the module
- Loading branch information
Showing
6 changed files
with
216 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace DNADesign\IdleLock\Extensions; | ||
|
||
use SilverStripe\Forms\FieldList; | ||
use SilverStripe\Security\Member; | ||
use SilverStripe\ORM\DataExtension; | ||
use SilverStripe\Core\Config\Config; | ||
use SilverStripe\Forms\NumericField; | ||
use SilverStripe\Forms\CheckboxField; | ||
use SilverStripe\Security\Group; | ||
use SilverStripe\Security\Permission; | ||
|
||
class GroupLockoutExtension extends DataExtension | ||
{ | ||
private static $db = [ | ||
'LockoutEnabled' => 'Boolean', | ||
'LockoutExempt' => 'Boolean', | ||
'LockoutThresholdDays' => 'Int', | ||
]; | ||
|
||
public function updateCMSFields(FieldList $fields) | ||
{ | ||
$fields->removeByName([ | ||
'LockoutEnabled', | ||
'LockoutExempt', | ||
'LockoutThresholdDays' | ||
]); | ||
|
||
if (Permission::check('ADMIN')) { | ||
// If configured, groups may exempt members from the idle-lockout feature | ||
if (Config::inst()->get(Group::class, 'lockout_exempt')) { | ||
$fields->insertAfter( | ||
'Description', | ||
CheckboxField::create('LockoutExempt', 'Lockout exempt') | ||
->setDescription('Membership of this group exempts members from the idle-lockout feature'), | ||
); | ||
} | ||
|
||
} | ||
// Enable lockout for this group | ||
if (!$this->owner->LockoutExempt) { | ||
$fields->insertAfter( | ||
'Description', | ||
CheckboxField::create('LockoutEnabled', 'Enable lockout') | ||
->setDescription('Activates the idle-lockout feature for members of this group'), | ||
); | ||
} | ||
|
||
// Set the lockout threshold | ||
if ($this->owner->LockoutEnabled) { | ||
$fields->insertAfter( | ||
'LockoutEnabled', | ||
NumericField::create('LockoutThresholdDays', 'Lockout threshold in days') | ||
->setDescription(sprintf( | ||
'Inactive time in days. Members of this group will be locked out if they | ||
do not log in for this amount of time.<br>Set to 0 to use the default of | ||
%s days.', Config::inst()->get(Member::class, 'lockout_threshold_days'))) | ||
->setAttribute('max', 999), | ||
); | ||
} | ||
} | ||
|
||
public function onBeforeWrite() | ||
{ | ||
parent::onBeforeWrite(); | ||
|
||
if ($this->owner->LockoutExempt) { | ||
$this->owner->LockoutEnabled = false; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace DNADesign\IdleLock\Extensions; | ||
|
||
use SilverStripe\Forms\FieldList; | ||
use SilverStripe\Forms\TextField; | ||
use SilverStripe\Security\Member; | ||
use SilverStripe\ORM\DataExtension; | ||
use SilverStripe\Core\Config\Config; | ||
|
||
/** | ||
* Allow a CMS override for the login screen message displayed to locked users | ||
*/ | ||
class SiteConfigLockoutExtension extends DataExtension | ||
{ | ||
private static $db = [ | ||
'LockoutMessage' => 'Varchar(255)', | ||
]; | ||
|
||
public function updateCMSFields(FieldList $fields) | ||
{ | ||
$fields->addFieldToTab('Root.Access', | ||
TextField::create('LockoutMessage') | ||
->setDescription(sprintf( | ||
'Override the login screen message displayed to locked users.<br><strong>Default:</strong> %s', | ||
Config::inst()->get(Member::class, 'lockout_message') | ||
)) | ||
); | ||
} | ||
} |