|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class DemoAccountPlugin extends \RainLoop\Plugins\AbstractPlugin |
|
4
|
|
|
{ |
|
5
|
|
|
/** |
|
6
|
|
|
* @return void |
|
7
|
|
|
*/ |
|
8
|
|
|
public function Init() |
|
9
|
|
|
{ |
|
10
|
|
|
$this->addHook('filter.app-data', 'FilterAppData'); |
|
11
|
|
|
$this->addHook('filter.action-params', 'FilterActionParams'); |
|
12
|
|
|
$this->addHook('ajax.action-pre-call', 'AjaxActionPreCall'); |
|
13
|
|
|
$this->addHook('filter.send-message', 'FilterSendMessage'); |
|
14
|
|
|
$this->addHook('main.fabrica', 'MainFabrica'); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @return array |
|
19
|
|
|
*/ |
|
20
|
|
View Code Duplication |
protected function configMapping() |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
|
|
return array( |
|
23
|
|
|
\RainLoop\Plugins\Property::NewInstance('email')->SetLabel('Demo Email') |
|
24
|
|
|
->SetDefaultValue('[email protected]'), |
|
25
|
|
|
\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('Demo Password') |
|
26
|
|
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD) |
|
27
|
|
|
); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @return void |
|
32
|
|
|
*/ |
|
33
|
|
|
public function FilterAppData($bAdmin, &$aResult) |
|
34
|
|
|
{ |
|
35
|
|
|
if (!$bAdmin && \is_array($aResult) && isset($aResult['Auth']) && !$aResult['Auth']) |
|
36
|
|
|
{ |
|
37
|
|
|
$aResult['DevEmail'] = $this->Config()->Get('plugin', 'email', $aResult['DevEmail']); |
|
38
|
|
|
$aResult['DevPassword'] = APP_DUMMY; |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return void |
|
44
|
|
|
*/ |
|
45
|
|
|
public function FilterActionParams($sMethodName, &$aActionParams) |
|
46
|
|
|
{ |
|
47
|
|
|
if ('DoLogin' === $sMethodName && isset($aActionParams['Email']) && isset($aActionParams['Password'])) |
|
48
|
|
|
{ |
|
49
|
|
|
if ($this->Config()->Get('plugin', 'email') === $aActionParams['Email']) |
|
50
|
|
|
{ |
|
51
|
|
|
$aActionParams['Password'] = $this->Config()->Get('plugin', 'password'); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param \RainLoop\Model\Account $oAccount |
|
58
|
|
|
* |
|
59
|
|
|
* @return bool |
|
60
|
|
|
*/ |
|
61
|
|
|
public function isDemoAccount($oAccount) |
|
62
|
|
|
{ |
|
63
|
|
|
return ($oAccount && $oAccount->Email() === $this->Config()->Get('plugin', 'email')); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function AjaxActionPreCall($sAction) |
|
67
|
|
|
{ |
|
68
|
|
|
if ('AccountSetup' === $sAction && |
|
69
|
|
|
$this->isDemoAccount($this->Manager()->Actions()->GetAccount())) |
|
70
|
|
|
{ |
|
71
|
|
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoAccountError); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function FilterSendMessage(&$oMessage) |
|
76
|
|
|
{ |
|
77
|
|
|
if ($oMessage && $this->isDemoAccount($this->Manager()->Actions()->GetAccount())) |
|
78
|
|
|
{ |
|
79
|
|
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DemoSendMessageError); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param string $sName |
|
85
|
|
|
* @param mixed $oDriver |
|
86
|
|
|
*/ |
|
87
|
|
|
public function MainFabrica($sName, &$oDriver) |
|
88
|
|
|
{ |
|
89
|
|
|
switch ($sName) |
|
90
|
|
|
{ |
|
91
|
|
|
case 'storage': |
|
92
|
|
|
case 'storage-local': |
|
93
|
|
|
if (\class_exists('\\RainLoop\\Providers\\Storage\\TemproryApcStorage') && |
|
94
|
|
|
\function_exists('apc_store')) |
|
95
|
|
|
{ |
|
96
|
|
|
$oAccount = $this->Manager()->Actions()->GetAccount(); |
|
97
|
|
|
if ($this->isDemoAccount($oAccount)) |
|
98
|
|
|
{ |
|
99
|
|
|
$oDriver = new \RainLoop\Providers\Storage\TemproryApcStorage(APP_PRIVATE_DATA.'storage', |
|
100
|
|
|
$sName === 'storage-local'); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
break; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.