Completed
Push — master ( 8d7136...b7ad45 )
by Rain
02:14 queued 34s
created

RestChangePasswordPlugin   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 76
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Init() 0 4 1
A MainFabrica() 0 27 4
A configMapping() 0 33 1
1
<?php
2
3
class RestChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
4
{
5
    public function Init()
6
    {
7
        $this->addHook('main.fabrica', 'MainFabrica');
8
    }
9
10
    /**
11
     * @param string $sName
12
     * @param mixed $oProvider
13
     */
14
    public function MainFabrica($sName, &$oProvider)
15
    {
16
        switch ($sName)
17
        {
18
            case 'change-password':
19
20
                $sUrl = \trim($this->Config()->Get('plugin', 'rest_url', ''));
21
                $sKey = \trim($this->Config()->Get('plugin', 'rest_key', ''));
22
23
                $sFieldEmail = \trim($this->Config()->Get('plugin', 'rest_field_email', ''));
24
                $sFieldOldpassword = \trim($this->Config()->Get('plugin', 'rest_field_oldpassword', ''));
25
                $sFieldNewpassword = \trim($this->Config()->Get('plugin', 'rest_field_newpassword', ''));
26
27
                if (!empty($sHost) && (!empty($sKey)))
0 ignored issues
show
Bug introduced by
The variable $sHost seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
28
                {
29
                    include_once __DIR__.'/RestChangePasswordDriver.php';
30
31
                    $oProvider = new RestChangePasswordDriver();
32
                    $oProvider->SetLogger($this->Manager()->Actions()->Logger());
33
                    $oProvider->SetConfig($sUrl, $sKey);
34
                    $oProvider->SetFieldNames($sFieldEmail, $sFieldOldpassword, $sFieldNewpassword);
35
                    $oProvider->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))));
36
                }
37
38
                break;
39
        }
40
    }
41
42
    /**
43
     * @return array
44
     */
45
    public function configMapping()
46
    {
47
        return array(
48
            \RainLoop\Plugins\Property::NewInstance('rest_url')
49
                ->SetLabel('REST API Url')
50
                ->SetDefaultValue('')
51
                ->SetDescription('Ex: http://localhost:8080/api/change_password or https://domain.com/api/user/passsword_update'),
52
            \RainLoop\Plugins\Property::NewInstance('rest_key')
53
                ->SetLabel('REST API key')
54
                ->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
55
                ->SetDescription('REST API Key for authentication, if you have "user" and "passsword" enter it as "user:password"')
56
                ->SetDefaultValue(''),
57
            \RainLoop\Plugins\Property::NewInstance('rest_field_email')
58
                ->SetLabel('Field "email" name')
59
                ->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
60
                ->SetDescription('Enter the name of the REST field name for email')
61
                ->SetDefaultValue('email'),
62
            \RainLoop\Plugins\Property::NewInstance('rest_field_oldpassword')
63
                ->SetLabel('Field "oldpassword" name')
64
                ->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
65
                ->SetDescription('Enter the name of the REST field name for oldpassword')
66
                ->SetDefaultValue('oldpassword'),
67
            \RainLoop\Plugins\Property::NewInstance('rest_field_newpassword')
68
                ->SetLabel('Field "newpassword" name')
69
                ->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
70
                ->SetDescription('Enter the name of the REST field name for newpassword')
71
                ->SetDefaultValue('newpassword'),
72
            \RainLoop\Plugins\Property::NewInstance('allowed_emails')->SetLabel('Allowed emails')
73
                ->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
74
                ->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: [email protected] [email protected] *@domain2.net')
75
                ->SetDefaultValue('*')
76
        );
77
    }
78
}
79