Issues (13)

src/Extensions/MemberExtension.php (2 issues)

1
<?php
2
3
namespace Firesphere\YubiAuth\Extensions;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\Forms\NumericField;
7
use SilverStripe\ORM\DataExtension;
8
9
/**
10
 * Class YubiAuthMemberExtension
11
 *
12
 * Enable yubikey authentication disabling temporarily
13
 *
14
 * @property MemberExtension $owner
15
 * @property string $Yubikey
16
 * @property int $NoYubikeyCount
17
 */
18
class MemberExtension extends DataExtension
19
{
20
    private static $db = [
0 ignored issues
show
The private property $db is not used, and could be removed.
Loading history...
21
        'Yubikey'        => 'Varchar(255)',
22
        'NoYubikeyCount' => 'Int'
23
    ];
24
25
    /**
26
     * @inheritdoc
27
     * @param array $labels
28
     */
29
    public function updateFieldLabels(&$labels)
30
    {
31
        $labels['Yubikey'] = _t(self::class . '.YUBIKEY', 'Yubikey code');
32
        $labels['NoYubikeyCount'] = _t(self::class . '.NOYUBIKEYCOUNT', 'Login count without yubikey');
33
    }
34
35
    /**
36
     * @inheritdoc
37
     * @param FieldList $fields
38
     */
39
    public function updateCMSFields(FieldList $fields)
40
    {
41
        $fields->removeByName(['NoYubikeyCount', 'Yubikey']);
42
        $yubiCount = NumericField::create('NoYubikeyCount');
43
44
        $fields->addFieldsToTab('Root.MFA', [$yubiCount]);
45
46
        return $fields;
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function onBeforeWrite()
53
    {
54
        // Empty the yubikey field on member write, if the yubiauth is not required
55
        // Maybe the user lost the key? So a new one will be set next time it's logged in with key
56
        if (!$this->owner->MFAEnabled) {
0 ignored issues
show
Bug Best Practice introduced by
The property MFAEnabled does not exist on Firesphere\YubiAuth\Extensions\MemberExtension. Did you maybe forget to declare it?
Loading history...
57
            $this->owner->Yubikey = '';
58
        }
59
    }
60
}
61