Completed
Push — master ( 023bd4...0eb96d )
by Simon
01:43
created

MemberExtension::onBeforeWrite()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace Firesphere\GraphQLJWT;
4
5
use SilverStripe\Forms\CheckboxField;
6
use SilverStripe\Forms\FieldList;
7
use SilverStripe\ORM\DataExtension;
8
9
/**
10
 * Class MemberExtension
11
 * Add a unique token to the Member for extra validation
12
 */
13
class MemberExtension extends DataExtension
14
{
15
    private static $db = [
0 ignored issues
show
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
        'JWTUniqueID' => 'Varchar(255)',
17
    ];
18
19
    private static $indexes = [
0 ignored issues
show
Unused Code introduced by
The property $indexes is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
20
        'JWTUniqueID' => 'unique'
21
    ];
22
23
    public function updateCMSFields(FieldList $fields)
24
    {
25
        parent::updateCMSFields($fields);
26
        $fields->removeByName(['JWTUniqueID']);
27
        if ($this->owner->JWTUniqueID) {
28
            $fields->addFieldsToTab(
29
                'Root.Main',
30
                [
31
                    CheckboxField::create('reset', 'Reset the Token ID to disable this user\'s remote login')
32
                ]
33
            );
34
        }
35
    }
36
37
    public function onBeforeWrite()
38
    {
39
        parent::onBeforeWrite();
40
        if ($this->owner->reset) {
41
            $this->owner->JWTUniqueID = null;
42
        }
43
    }
44
}
45