Version Notes
Hello World! :)
Download this release
Release Info
Developer | Alex Gusev |
Extension | Praxigento_LoginAs |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/Praxigento/LoginAs/Config.php +130 -0
- app/code/community/Praxigento/LoginAs/Helper/Data.php +30 -0
- app/code/community/Praxigento/LoginAs/Model/Logger.php +110 -0
- app/code/community/Praxigento/LoginAs/Model/Observer.php +169 -0
- app/code/community/Praxigento/LoginAs/Model/Package.php +159 -0
- app/code/community/Praxigento/LoginAs/Test/ConfigTest.php +60 -0
- app/code/community/Praxigento/LoginAs/Test/Model/LoggerTest.php +57 -0
- app/code/community/Praxigento/LoginAs/Test/phpunit.bootstrap.php +30 -0
- app/code/community/Praxigento/LoginAs/Test/phpunit.praxigento.loginas.xml +10 -0
- app/code/community/Praxigento/LoginAs/controllers/LoginController.php +107 -0
- app/code/community/Praxigento/LoginAs/controllers/RedirectController.php +86 -0
- app/code/community/Praxigento/LoginAs/etc/config.xml +166 -0
- app/code/community/Praxigento/LoginAs/etc/system.xml +118 -0
- app/code/community/Praxigento/LoginAs/sql/prxgt_lgas_setup/mysql4-install-1.0.0.php +49 -0
- app/code/community/Praxigento/LoginAs/sql/prxgt_lgas_setup/prxgt_install_func.php +74 -0
- app/design/adminhtml/default/default/layout/prxgt/lgas/loginas_adminhtml_layout.xml +32 -0
- app/design/adminhtml/default/default/template/prxgt/lgas/redirect.phtml +49 -0
- app/etc/modules/Praxigento_LoginAs.xml +30 -0
- app/locale/en_US/prxgt/lgas/prxgt_lgas.csv +17 -0
- package.xml +18 -0
app/code/community/Praxigento/LoginAs/Config.php
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2013, Praxigento
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
7 |
+
* following conditions are met:
|
8 |
+
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
9 |
+
* disclaimer.
|
10 |
+
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
11 |
+
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
12 |
+
*
|
13 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
14 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
15 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
16 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
17 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
18 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
19 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
20 |
+
*/
|
21 |
+
/**
|
22 |
+
* User: Alex Gusev <flancer64@gmail.com>
|
23 |
+
* Date: 13.10.2
|
24 |
+
* Time: 09:07
|
25 |
+
*/
|
26 |
+
class Praxigento_LoginAs_Config
|
27 |
+
{
|
28 |
+
/******************************************************************************************
|
29 |
+
* Attributes
|
30 |
+
*****************************************************************************************/
|
31 |
+
const ATTR_ORDER_CREATED_BY = 'prxgt_lgas_created_by';
|
32 |
+
/******************************************************************************************
|
33 |
+
* UI components
|
34 |
+
*****************************************************************************************/
|
35 |
+
const UI_BTN_LOGIN_AS = 'prxgt_lgas_button';
|
36 |
+
/******************************************************************************************
|
37 |
+
* POST/GET request parameters
|
38 |
+
*****************************************************************************************/
|
39 |
+
/** don't change value: see Observer/doCustomerGridActionAdd() */
|
40 |
+
const REQ_PARAM_LAS_ID = 'id';
|
41 |
+
/******************************************************************************************
|
42 |
+
* Routing (/[ctrl]/[action])
|
43 |
+
*****************************************************************************************/
|
44 |
+
const ROUTE_REDIRECT = '/redirect/';
|
45 |
+
const ROUTE_CUSTOMER_LOGINAS = '/login/as/';
|
46 |
+
/** **************************************************************************************
|
47 |
+
* Session parameters
|
48 |
+
************************************************************************************** */
|
49 |
+
const SESS_LOGGED_AS_OPERATOR = 'prxgtLoggedInAsOperator';
|
50 |
+
/******************************************************************************************
|
51 |
+
* Module's config.xml parameters
|
52 |
+
*****************************************************************************************/
|
53 |
+
const XMLCFG_ROUTER_ADMIN = 'prxgt_lgas_admin';
|
54 |
+
const XMLCFG_ROUTER_FRONT = 'prxgt_lgas_front';
|
55 |
+
|
56 |
+
/**
|
57 |
+
* 'true' - if admin user has right to view 'Created By' value.
|
58 |
+
* @return bool
|
59 |
+
*/
|
60 |
+
public static function canAccessCreatedBy()
|
61 |
+
{
|
62 |
+
return filter_var(Mage::getSingleton('admin/session')->isAllowed('sales/customer/prxgt_lgas_created_by_access'), FILTER_VALIDATE_BOOLEAN);
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* 'true' - if admin user has right to use 'Login As' feature.
|
67 |
+
* @return bool
|
68 |
+
*/
|
69 |
+
public static function canAccessLoginAs()
|
70 |
+
{
|
71 |
+
return filter_var(Mage::getSingleton('admin/session')->isAllowed('sales/customer/prxgt_lgas_access'), FILTER_VALIDATE_BOOLEAN);
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* 'true' - 'login as' feature is enabled, 'false' - otherwise.
|
76 |
+
* @return bool
|
77 |
+
*/
|
78 |
+
public static function cfgGeneralEnabled()
|
79 |
+
{
|
80 |
+
return filter_var(Mage::getStoreConfig('prxgt_lgas/general/enabled'), FILTER_VALIDATE_BOOLEAN);
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* 'true' - log events using Magento logger or Log4php logger (in case of Nmmlm_Log module is installed).
|
85 |
+
* @return bool
|
86 |
+
*/
|
87 |
+
public static function cfgGeneralLogEvents()
|
88 |
+
{
|
89 |
+
return filter_var(Mage::getStoreConfig('prxgt_lgas/general/log_events'), FILTER_VALIDATE_BOOLEAN);
|
90 |
+
}
|
91 |
+
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Display or not 'Login as Customer' action on the customers grid.
|
95 |
+
* @return bool
|
96 |
+
*/
|
97 |
+
public static function cfgUiCustomersGridActionEnabled()
|
98 |
+
{
|
99 |
+
return filter_var(Mage::getStoreConfig('prxgt_lgas/ui/action_enabled'), FILTER_VALIDATE_BOOLEAN);
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Display or not columns with 'Login As' data on the orders grid.
|
104 |
+
* @return bool
|
105 |
+
*/
|
106 |
+
public static function cfgUiOrdersGridColumnEnabled()
|
107 |
+
{
|
108 |
+
return filter_var(Mage::getStoreConfig('prxgt_lgas/ui/orders_grid_column_enabled'), FILTER_VALIDATE_BOOLEAN);
|
109 |
+
}
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Returns position of the created by column (by default - 5).
|
113 |
+
* @return int
|
114 |
+
*/
|
115 |
+
public static function cfgUiOrdersGridColumnPosition()
|
116 |
+
{
|
117 |
+
$val = Mage::getStoreConfig('prxgt_lgas/ui/orders_grid_column_position');
|
118 |
+
return (is_null($val)) ? 5 : (int)$val;
|
119 |
+
}
|
120 |
+
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Returns default helper for the module.
|
124 |
+
* @return Praxigento_LoginAs_Helper_Data
|
125 |
+
*/
|
126 |
+
public static function helper()
|
127 |
+
{
|
128 |
+
return Mage::helper('prxgt_lgas_helper');
|
129 |
+
}
|
130 |
+
}
|
app/code/community/Praxigento/LoginAs/Helper/Data.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2013, Praxigento
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
7 |
+
* following conditions are met:
|
8 |
+
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
9 |
+
* disclaimer.
|
10 |
+
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
11 |
+
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
12 |
+
*
|
13 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
14 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
15 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
16 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
17 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
18 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
19 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
20 |
+
*/
|
21 |
+
/**
|
22 |
+
* Default helper for the module.
|
23 |
+
* User: Flancer
|
24 |
+
* Date: 2/8/13
|
25 |
+
* Time: 6:00 PM
|
26 |
+
*/
|
27 |
+
class Praxigento_LoginAs_Helper_Data extends Mage_Core_Helper_Abstract
|
28 |
+
{
|
29 |
+
|
30 |
+
}
|
app/code/community/Praxigento/LoginAs/Model/Logger.php
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2013, Praxigento
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
7 |
+
* following conditions are met:
|
8 |
+
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
9 |
+
* disclaimer.
|
10 |
+
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
11 |
+
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
12 |
+
*
|
13 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
14 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
15 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
16 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
17 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
18 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
19 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
20 |
+
*/
|
21 |
+
/**
|
22 |
+
* Wrapper for loggers (Mage default or Log4php from Nmmlm_log module)
|
23 |
+
* User: Alex Gusev <flancer64@gmail.com>
|
24 |
+
* Date: 2/20/13
|
25 |
+
* Time: 9:38 AM
|
26 |
+
*/
|
27 |
+
class Praxigento_LoginAs_Model_Logger
|
28 |
+
{
|
29 |
+
/** @var bool 'true' - Log4php logging framework is used. */
|
30 |
+
private static $isLog4phpUsed = null;
|
31 |
+
/** @var string name for the current logger */
|
32 |
+
private $name;
|
33 |
+
/** @var Logger */
|
34 |
+
private $loggerLog4php;
|
35 |
+
|
36 |
+
|
37 |
+
function __construct($name)
|
38 |
+
{
|
39 |
+
self::$isLog4phpUsed = class_exists('Nmmlm_Log_Logger', false);
|
40 |
+
if (self::$isLog4phpUsed) {
|
41 |
+
$this->loggerLog4php = Nmmlm_Log_Logger::getLogger($name);
|
42 |
+
} else {
|
43 |
+
$this->name = is_object($name) ? get_class($name) : (string)$name;
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Override getter to use '$log = Nmmlm_Log_Logger::getLogger($this)' form in Mage classes.
|
49 |
+
* @static
|
50 |
+
*
|
51 |
+
* @param string $name
|
52 |
+
*
|
53 |
+
* @return Praxigento_LoginAs_Model_Logger
|
54 |
+
*/
|
55 |
+
public static function getLogger($name)
|
56 |
+
{
|
57 |
+
return new Praxigento_LoginAs_Model_Logger($name);
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Internal dispatcher for the called log method.
|
62 |
+
* @param $message
|
63 |
+
* @param $throwable
|
64 |
+
* @param $log4phpMethod
|
65 |
+
* @param $zendLevel
|
66 |
+
*/
|
67 |
+
private function doLog($message, $throwable, $log4phpMethod, $zendLevel)
|
68 |
+
{
|
69 |
+
if (Praxigento_LoginAs_Config::cfgGeneralLogEvents()) {
|
70 |
+
if (self::$isLog4phpUsed) {
|
71 |
+
$this->loggerLog4php->$log4phpMethod($message, $throwable);
|
72 |
+
} else {
|
73 |
+
Mage::log($this->name . ': ' . $message, $zendLevel);
|
74 |
+
if ($throwable instanceof Exception) {
|
75 |
+
Mage::logException($throwable);
|
76 |
+
}
|
77 |
+
}
|
78 |
+
}
|
79 |
+
}
|
80 |
+
|
81 |
+
public function trace($message, $throwable = null)
|
82 |
+
{
|
83 |
+
$this->doLog($message, $throwable, 'trace', Zend_Log::DEBUG);
|
84 |
+
}
|
85 |
+
|
86 |
+
public function debug($message, $throwable = null)
|
87 |
+
{
|
88 |
+
$this->doLog($message, $throwable, 'debug', Zend_Log::INFO);
|
89 |
+
}
|
90 |
+
|
91 |
+
public function info($message, $throwable = null)
|
92 |
+
{
|
93 |
+
$this->doLog($message, $throwable, 'info', Zend_Log::NOTICE);
|
94 |
+
}
|
95 |
+
|
96 |
+
public function warn($message, $throwable = null)
|
97 |
+
{
|
98 |
+
$this->doLog($message, $throwable, 'warn', Zend_Log::WARN);
|
99 |
+
}
|
100 |
+
|
101 |
+
public function error($message, $throwable = null)
|
102 |
+
{
|
103 |
+
$this->doLog($message, $throwable, 'error', Zend_Log::ERR);
|
104 |
+
}
|
105 |
+
|
106 |
+
public function fatal($message, $throwable = null)
|
107 |
+
{
|
108 |
+
$this->doLog($message, $throwable, 'fatal', Zend_Log::CRIT);
|
109 |
+
}
|
110 |
+
}
|
app/code/community/Praxigento/LoginAs/Model/Observer.php
ADDED
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2013, Praxigento
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
7 |
+
* following conditions are met:
|
8 |
+
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
9 |
+
* disclaimer.
|
10 |
+
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
11 |
+
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
12 |
+
*
|
13 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
14 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
15 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
16 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
17 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
18 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
19 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
20 |
+
*/
|
21 |
+
/**
|
22 |
+
* User: Alex Gusev <flancer64@gmail.com>
|
23 |
+
* Date: 2/20/13
|
24 |
+
* Time: 9:38 AM
|
25 |
+
*/
|
26 |
+
class Praxigento_LoginAs_Model_Observer extends Varien_Object
|
27 |
+
{
|
28 |
+
/**
|
29 |
+
* Adds 'Login As' button to the customer form.
|
30 |
+
* @param Varien_Event_Observer $observer
|
31 |
+
*/
|
32 |
+
public function onAdminhtmlWidgetContainerHtmlBefore(Varien_Event_Observer $observer)
|
33 |
+
{
|
34 |
+
/** validate availability & permissions */
|
35 |
+
if (
|
36 |
+
Praxigento_LoginAs_Config::cfgGeneralEnabled() &&
|
37 |
+
Praxigento_LoginAs_Config::canAccessLoginAs()
|
38 |
+
) {
|
39 |
+
/** add button to the form */
|
40 |
+
/** @var $block Mage_Adminhtml_Block_Customer_Edit */
|
41 |
+
$block = $observer->getEvent()->getBlock();
|
42 |
+
if ($block instanceof Mage_Adminhtml_Block_Customer_Edit) {
|
43 |
+
$customer = Mage::registry('current_customer');
|
44 |
+
if ($customer && $customer->getId()) {
|
45 |
+
/** get data and setup URL to redirection controller */
|
46 |
+
$customerId = $customer->getId();
|
47 |
+
$url = Mage::getModel('adminhtml/url')->getUrl(
|
48 |
+
Praxigento_LoginAs_Config::XMLCFG_ROUTER_ADMIN . Praxigento_LoginAs_Config::ROUTE_REDIRECT,
|
49 |
+
array(
|
50 |
+
Praxigento_LoginAs_Config::REQ_PARAM_LAS_ID => $customerId,
|
51 |
+
)
|
52 |
+
);
|
53 |
+
/** create UI button */
|
54 |
+
$level = 0;
|
55 |
+
$sortOrder = -1;
|
56 |
+
$area = 'header';
|
57 |
+
$block->addButton(Praxigento_LoginAs_Config::UI_BTN_LOGIN_AS,
|
58 |
+
array(
|
59 |
+
'label' => Praxigento_LoginAs_Config::helper()->__('Login as Customer'),
|
60 |
+
/** open in new window */
|
61 |
+
'onclick' => "window.open('$url')",
|
62 |
+
), $level, $sortOrder, $area);
|
63 |
+
}
|
64 |
+
}
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Add 'created by' data to order.
|
71 |
+
*
|
72 |
+
* @param Varien_Event_Observer $observer
|
73 |
+
*/
|
74 |
+
public function onSalesConvertQuoteAddressToOrder(Varien_Event_Observer $observer)
|
75 |
+
{
|
76 |
+
if (Praxigento_LoginAs_Config::cfgGeneralEnabled()) {
|
77 |
+
$order = $observer->getEvent()->getOrder();
|
78 |
+
/** @var $session Mage_Customer_Model_Session */
|
79 |
+
$session = Mage::getSingleton('customer/session');
|
80 |
+
$operator = $session->getData(Praxigento_LoginAs_Config::SESS_LOGGED_AS_OPERATOR);
|
81 |
+
if (!is_null($operator)) {
|
82 |
+
$order->setData(Praxigento_LoginAs_Config::ATTR_ORDER_CREATED_BY, $operator);
|
83 |
+
} else {
|
84 |
+
$order->setData(Praxigento_LoginAs_Config::ATTR_ORDER_CREATED_BY, '[Customer]');
|
85 |
+
}
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Extend UI blocks.
|
91 |
+
* @param Varien_Event_Observer $observer
|
92 |
+
*/
|
93 |
+
public function onAdminhtmlBlockHtmlBefore(Varien_Event_Observer $observer)
|
94 |
+
{
|
95 |
+
if (Praxigento_LoginAs_Config::cfgGeneralEnabled()) {
|
96 |
+
$block = $observer->getData('block');
|
97 |
+
if ($block instanceof Mage_Adminhtml_Block_Customer_Grid) {
|
98 |
+
$this->doCustomerGridActionAdd($block);
|
99 |
+
} elseif ($block instanceof Mage_Adminhtml_Block_Sales_Order_Grid) {
|
100 |
+
$this->doOrderGridColumnAdd($block);
|
101 |
+
}
|
102 |
+
}
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Add new action to customers grid.
|
107 |
+
* @param Mage_Adminhtml_Block_Customer_Grid $block
|
108 |
+
*/
|
109 |
+
private function doCustomerGridActionAdd(Mage_Adminhtml_Block_Customer_Grid $block)
|
110 |
+
{
|
111 |
+
/** validate availability & permissions */
|
112 |
+
if (Praxigento_LoginAs_Config::cfgUiCustomersGridActionEnabled() &&
|
113 |
+
Praxigento_LoginAs_Config::canAccessLoginAs()
|
114 |
+
) {
|
115 |
+
/** add action link to grid */
|
116 |
+
/** @var $cols array */
|
117 |
+
$cols = $block->getColumns();
|
118 |
+
/** @var $colAction Mage_Adminhtml_Block_Widget_Grid_Column */
|
119 |
+
$colAction = $cols['action'];
|
120 |
+
$actions = $colAction->getData('actions');
|
121 |
+
if (is_array($actions)) {
|
122 |
+
/** add new action */
|
123 |
+
$actions[] = array(
|
124 |
+
'caption' => Praxigento_LoginAs_Config::helper()->__('Login as...'),
|
125 |
+
'url' => array('base' => Praxigento_LoginAs_Config::XMLCFG_ROUTER_ADMIN . Praxigento_LoginAs_Config::ROUTE_REDIRECT),
|
126 |
+
'field' => Praxigento_LoginAs_Config::REQ_PARAM_LAS_ID,
|
127 |
+
'target' => '_blank',
|
128 |
+
);
|
129 |
+
$colAction->setData('actions', $actions);
|
130 |
+
/** reset default renderer */
|
131 |
+
$colAction->setData('renderer', 'adminhtml/customer_grid_renderer_multiaction');
|
132 |
+
}
|
133 |
+
}
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Add new column to orders grid.
|
138 |
+
* @param Mage_Adminhtml_Block_Sales_Order_Grid $grid
|
139 |
+
*/
|
140 |
+
private function doOrderGridColumnAdd(Mage_Adminhtml_Block_Sales_Order_Grid $grid)
|
141 |
+
{
|
142 |
+
/** validate availability & permissions */
|
143 |
+
if (Praxigento_LoginAs_Config::cfgUiOrdersGridColumnEnabled() &&
|
144 |
+
Praxigento_LoginAs_Config::canAccessCreatedBy()
|
145 |
+
) {
|
146 |
+
/** define position for the column */
|
147 |
+
$pos = Praxigento_LoginAs_Config::cfgUiOrdersGridColumnPosition();
|
148 |
+
$curr = 0;
|
149 |
+
$after = $grid->getLastColumnId();
|
150 |
+
foreach ($grid->getColumns() as $key => $value) {
|
151 |
+
$after = $key;
|
152 |
+
if (++$curr >= $pos) {
|
153 |
+
break;
|
154 |
+
}
|
155 |
+
}
|
156 |
+
/** add new column to grid */
|
157 |
+
$grid->addColumnAfter(Praxigento_LoginAs_Config::ATTR_ORDER_CREATED_BY,
|
158 |
+
array(
|
159 |
+
'header' => Praxigento_LoginAs_Config::helper()->__('Created by'),
|
160 |
+
'index' => Praxigento_LoginAs_Config::ATTR_ORDER_CREATED_BY,
|
161 |
+
/** 'renderer' => 'nmmlm_core_block/adminhtml_widget_grid_column_renderer_pv', */
|
162 |
+
'type' => 'text',
|
163 |
+
),
|
164 |
+
$after
|
165 |
+
);
|
166 |
+
$grid->sortColumnsByOrder();
|
167 |
+
}
|
168 |
+
}
|
169 |
+
}
|
app/code/community/Praxigento/LoginAs/Model/Package.php
ADDED
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2013, Praxigento
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
7 |
+
* following conditions are met:
|
8 |
+
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
9 |
+
* disclaimer.
|
10 |
+
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
11 |
+
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
12 |
+
*
|
13 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
14 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
15 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
16 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
17 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
18 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
19 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
20 |
+
*/
|
21 |
+
/**
|
22 |
+
* Authentication package to be send from adminhtml to the front through the file system.
|
23 |
+
* Also used as a block data bean on UI (to compose redirection form).
|
24 |
+
*
|
25 |
+
* See: http://stackoverflow.com/questions/4006183/magento-passing-data-between-a-controller-and-a-block.
|
26 |
+
* User: Alex Gusev <flancer64@gmail.com>
|
27 |
+
*/
|
28 |
+
class Praxigento_LoginAs_Model_Package extends Varien_Object
|
29 |
+
{
|
30 |
+
const PREFIX = 'las';
|
31 |
+
|
32 |
+
/** @var string administrator's name to be displayed in orders grid and logs */
|
33 |
+
private $adminName;
|
34 |
+
private $customerId;
|
35 |
+
private $customerName;
|
36 |
+
/** @var string ID of the package */
|
37 |
+
private $packageId;
|
38 |
+
/** @var string URL to use on form to redirect admin to the customer's website */
|
39 |
+
private $redirectUrl;
|
40 |
+
|
41 |
+
|
42 |
+
public function setCustomerId($customerId)
|
43 |
+
{
|
44 |
+
$this->customerId = $customerId;
|
45 |
+
}
|
46 |
+
|
47 |
+
public function getCustomerId()
|
48 |
+
{
|
49 |
+
return $this->customerId;
|
50 |
+
}
|
51 |
+
|
52 |
+
private $ip;
|
53 |
+
|
54 |
+
public function setAdminName($adminName)
|
55 |
+
{
|
56 |
+
$this->adminName = $adminName;
|
57 |
+
}
|
58 |
+
|
59 |
+
public function getAdminName()
|
60 |
+
{
|
61 |
+
return $this->adminName;
|
62 |
+
}
|
63 |
+
|
64 |
+
public function setCustomerName($customerName)
|
65 |
+
{
|
66 |
+
$this->customerName = $customerName;
|
67 |
+
}
|
68 |
+
|
69 |
+
public function getCustomerName()
|
70 |
+
{
|
71 |
+
return $this->customerName;
|
72 |
+
}
|
73 |
+
|
74 |
+
public function setIp($ip)
|
75 |
+
{
|
76 |
+
$this->ip = $ip;
|
77 |
+
}
|
78 |
+
|
79 |
+
public function getIp()
|
80 |
+
{
|
81 |
+
return $this->ip;
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Saves login data into file in the temporary directory and returns name of the tmp file including extension.
|
86 |
+
* @return string
|
87 |
+
*/
|
88 |
+
public function saveAsFile()
|
89 |
+
{
|
90 |
+
// generate unique filename and create file to save login data
|
91 |
+
$fname = tempnam(sys_get_temp_dir(), self::PREFIX);
|
92 |
+
$path_parts = pathinfo($fname);
|
93 |
+
$this->packageId = $path_parts['basename'];
|
94 |
+
$handle = fopen($fname, "w");
|
95 |
+
// write login data to file
|
96 |
+
$content = $this->adminName . "\n";
|
97 |
+
$content .= $this->customerId . "\n";
|
98 |
+
$content .= $this->customerName . "\n";
|
99 |
+
$content .= $this->ip . "\n";
|
100 |
+
fwrite($handle, $content);
|
101 |
+
fclose($handle);
|
102 |
+
return $this->packageId;
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Loads "Login As" parameters from file and removes file from disk.
|
107 |
+
* @param $filename
|
108 |
+
*/
|
109 |
+
public function loadFromFile($filename)
|
110 |
+
{
|
111 |
+
// load data
|
112 |
+
$this->packageId = $filename;
|
113 |
+
$fname = sys_get_temp_dir() . DS . $this->packageId;
|
114 |
+
$data = file($fname);
|
115 |
+
if (is_array($data) && sizeof($data >= 4)) {
|
116 |
+
$this->adminName = trim($data[0]);
|
117 |
+
$this->customerId = trim($data[1]);
|
118 |
+
$this->customerName = trim($data[2]);
|
119 |
+
$this->ip = trim($data[3]);
|
120 |
+
}
|
121 |
+
// remove file
|
122 |
+
unlink($fname);
|
123 |
+
$this->packageId = null;
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* @param string $packageId
|
128 |
+
*/
|
129 |
+
public function setPackageId($packageId)
|
130 |
+
{
|
131 |
+
$this->packageId = $packageId;
|
132 |
+
}
|
133 |
+
|
134 |
+
/**
|
135 |
+
* @return string
|
136 |
+
*/
|
137 |
+
public function getPackageId()
|
138 |
+
{
|
139 |
+
return $this->packageId;
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* @param string $redirectUrl
|
144 |
+
*/
|
145 |
+
public function setRedirectUrl($redirectUrl)
|
146 |
+
{
|
147 |
+
$this->redirectUrl = $redirectUrl;
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* @return string
|
152 |
+
*/
|
153 |
+
public function getRedirectUrl()
|
154 |
+
{
|
155 |
+
return $this->redirectUrl;
|
156 |
+
}
|
157 |
+
|
158 |
+
|
159 |
+
}
|
app/code/community/Praxigento/LoginAs/Test/ConfigTest.php
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2013, Praxigento
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
7 |
+
* following conditions are met:
|
8 |
+
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
9 |
+
* disclaimer.
|
10 |
+
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
11 |
+
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
12 |
+
*
|
13 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
14 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
15 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
16 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
17 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
18 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
19 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
20 |
+
*/
|
21 |
+
/**
|
22 |
+
* Created by JetBrains PhpStorm.
|
23 |
+
* User: Alex Gusev <flancer64@gmail.com>
|
24 |
+
* Date: 2/18/13
|
25 |
+
* Time: 6:05 PM
|
26 |
+
*/
|
27 |
+
class Praxigento_LoginAs_Test_ConfigTest extends PHPUnit_Framework_TestCase
|
28 |
+
{
|
29 |
+
/**
|
30 |
+
* Sets up the fixture, for example, opens a network connection.
|
31 |
+
* This method is called before a test is executed.
|
32 |
+
*/
|
33 |
+
protected function setUp()
|
34 |
+
{
|
35 |
+
if (!class_exists('Mage')) {
|
36 |
+
require_once '../../../../../Mage.php';
|
37 |
+
}
|
38 |
+
Mage::app();
|
39 |
+
}
|
40 |
+
|
41 |
+
public function testCfg()
|
42 |
+
{
|
43 |
+
// System / Configuration
|
44 |
+
// general
|
45 |
+
$this->assertTrue(is_bool(Praxigento_LoginAs_Config::cfgGeneralEnabled()));
|
46 |
+
$this->assertTrue(is_bool(Praxigento_LoginAs_Config::cfgGeneralLogEvents()));
|
47 |
+
// UI
|
48 |
+
$this->assertTrue(is_bool(Praxigento_LoginAs_Config::cfgUiCustomersGridActionEnabled()));
|
49 |
+
$this->assertTrue(is_bool(Praxigento_LoginAs_Config::cfgUiOrdersGridColumnEnabled()));
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Test default accessors for basic Magento components.
|
54 |
+
*/
|
55 |
+
public function test_defaults()
|
56 |
+
{
|
57 |
+
$helper = Praxigento_LoginAs_Config::helper();
|
58 |
+
$this->assertTrue($helper instanceof Mage_Core_Helper_Abstract);
|
59 |
+
}
|
60 |
+
}
|
app/code/community/Praxigento/LoginAs/Test/Model/LoggerTest.php
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2013, Praxigento
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
7 |
+
* following conditions are met:
|
8 |
+
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
9 |
+
* disclaimer.
|
10 |
+
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
11 |
+
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
12 |
+
*
|
13 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
14 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
15 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
16 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
17 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
18 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
19 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
20 |
+
*/
|
21 |
+
/**
|
22 |
+
* User: Alex Gusev <flancer64@gmail.com>
|
23 |
+
* Date: 2/18/13
|
24 |
+
* Time: 6:05 PM
|
25 |
+
*/
|
26 |
+
class Praxigento_LoginAs_Test_Model_LoggerTest extends PHPUnit_Framework_TestCase
|
27 |
+
{
|
28 |
+
/**
|
29 |
+
* Sets up the fixture, for example, opens a network connection.
|
30 |
+
* This method is called before a test is executed.
|
31 |
+
*/
|
32 |
+
protected function setUp()
|
33 |
+
{
|
34 |
+
if (!class_exists('Mage')) {
|
35 |
+
require_once '../../../../../../Mage.php';
|
36 |
+
}
|
37 |
+
Mage::app();
|
38 |
+
}
|
39 |
+
|
40 |
+
public function test_all()
|
41 |
+
{
|
42 |
+
$log = Praxigento_LoginAs_Model_Logger::getLogger($this);
|
43 |
+
$log->trace('trace');
|
44 |
+
$log->debug('debug');
|
45 |
+
$log->info('info');
|
46 |
+
$log->warn('warn');
|
47 |
+
$log->error('error');
|
48 |
+
$log->fatal('fatal');
|
49 |
+
$log->trace('trace', new Exception('test trace error'));
|
50 |
+
$log->debug('debug', new Exception('test debug error'));
|
51 |
+
$log->info('info', new Exception('test info error'));
|
52 |
+
$log->warn('warn', new Exception('test warn error'));
|
53 |
+
$log->error('error', new Exception('test error error'));
|
54 |
+
$log->fatal('fatal', new Exception('test fatal error'));
|
55 |
+
}
|
56 |
+
|
57 |
+
}
|
app/code/community/Praxigento/LoginAs/Test/phpunit.bootstrap.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2012, Praxigento
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
7 |
+
* following conditions are met:
|
8 |
+
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
9 |
+
* disclaimer.
|
10 |
+
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
11 |
+
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
12 |
+
*
|
13 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
14 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
15 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
16 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
17 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
18 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
19 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
20 |
+
*/
|
21 |
+
/**
|
22 |
+
* Bootstrap file for PHPUnit tests.
|
23 |
+
* User: Alex Gusev <flancer64@gmail.com>
|
24 |
+
* Date: 2013/02/18
|
25 |
+
*/
|
26 |
+
/** Load 'Mage' class to enable Magento autoloading. */
|
27 |
+
require_once '../../../../../Mage.php';
|
28 |
+
// buffer output to prevent errors when test suite is running.
|
29 |
+
ob_start();
|
30 |
+
?>
|
app/code/community/Praxigento/LoginAs/Test/phpunit.praxigento.loginas.xml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<phpunit bootstrap="phpunit.bootstrap.php">
|
2 |
+
<testsuites>
|
3 |
+
<testsuite name="Praxigento_LoginAs">
|
4 |
+
<directory>.</directory>
|
5 |
+
</testsuite>
|
6 |
+
</testsuites>
|
7 |
+
<php>
|
8 |
+
<includePath>../../../../../</includePath>
|
9 |
+
</php>
|
10 |
+
</phpunit>
|
app/code/community/Praxigento/LoginAs/controllers/LoginController.php
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2013, Praxigento
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
7 |
+
* following conditions are met:
|
8 |
+
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
9 |
+
* disclaimer.
|
10 |
+
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
11 |
+
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
12 |
+
*
|
13 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
14 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
15 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
16 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
17 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
18 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
19 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
20 |
+
*/
|
21 |
+
/**
|
22 |
+
* User: Alex Gusev <flancer64@gmail.com>
|
23 |
+
* Date: 2/20/13
|
24 |
+
* Time: 2:04 PM
|
25 |
+
*/
|
26 |
+
class Praxigento_LoginAs_LoginController extends Mage_Core_Controller_Front_Action
|
27 |
+
{
|
28 |
+
public function asAction()
|
29 |
+
{
|
30 |
+
/** event logger */
|
31 |
+
$log = Praxigento_LoginAs_Model_Logger::getLogger($this);
|
32 |
+
/** get filename from the request parameters */
|
33 |
+
$filename = $this->getRequest()->getPost(Praxigento_LoginAs_Config::REQ_PARAM_LAS_ID);
|
34 |
+
/** @var $authPack Praxigento_LoginAs_Model_Package */
|
35 |
+
$authPack = Mage::getSingleton('prxgt_lgas_model/package');
|
36 |
+
$authPack->loadFromFile($filename);
|
37 |
+
/** extract working data */
|
38 |
+
$customerId = $authPack->getCustomerId();
|
39 |
+
if (!is_null($customerId)) {
|
40 |
+
$customerName = $authPack->getCustomerName();
|
41 |
+
$operatorName = $authPack->getAdminName();
|
42 |
+
$operatorIp = $authPack->getIp();
|
43 |
+
$log->trace("Operator '$operatorName' trying to login as '$customerName' (id=$customerId) from ip '$operatorIp'...");
|
44 |
+
/** validate current customer's session or establish new session and validate request */
|
45 |
+
$session = Mage::getSingleton('customer/session');
|
46 |
+
$sessionCustomer = $session->getCustomer();
|
47 |
+
$sessionCustomerId = $sessionCustomer->getId();
|
48 |
+
/** this operator is already logged in as required customer */
|
49 |
+
if (($session->isLoggedIn()) && ($customerId == $sessionCustomerId)) {
|
50 |
+
$log->debug("Session for customer '$customerName' (id=$customerId) is already exist. Refreshing page...");
|
51 |
+
/** save operator's name into session to use in orders later */
|
52 |
+
$session->setData(Praxigento_LoginAs_Config::SESS_LOGGED_AS_OPERATOR, $operatorName);
|
53 |
+
} else {
|
54 |
+
/** establish new customer session */
|
55 |
+
$validatorData = $session->getValidatorData();
|
56 |
+
if ($this->getRequest()->isPost() && ($operatorIp == $validatorData['remote_addr'])) {
|
57 |
+
try {
|
58 |
+
/** @var $customer Mage_Customer_Model_Customer */
|
59 |
+
$customer = Mage::getModel('customer/customer')->load($customerId);
|
60 |
+
if ($customer->getId() == $customerId) {
|
61 |
+
/** check allowed websites */
|
62 |
+
$wsId = Mage::app()->getStore()->getWebsiteId();
|
63 |
+
$wsids = $customer->getSharedWebsiteIds();
|
64 |
+
$custWsId = $customer->getData('website_id');
|
65 |
+
if (
|
66 |
+
(in_array($wsId, $wsids)) ||
|
67 |
+
($wsId == $custWsId)
|
68 |
+
) {
|
69 |
+
$session->loginById($customerId);
|
70 |
+
/** save operator's name into session to use in orders later */
|
71 |
+
$session->setData(Praxigento_LoginAs_Config::SESS_LOGGED_AS_OPERATOR, $operatorName);
|
72 |
+
$log->info("New session for customer '$customerName' (id=$customerId) is established for operator '$operatorName'");
|
73 |
+
} else {
|
74 |
+
$msg = "Customer '$customerName' (id=$customerId) has no rights to access current website.";
|
75 |
+
$log->error($msg);
|
76 |
+
Mage::throwException($msg);
|
77 |
+
}
|
78 |
+
} else {
|
79 |
+
$msg = "Customer with id '$customerId' does not exists.";
|
80 |
+
$log->error($msg);
|
81 |
+
Mage::throwException($msg);
|
82 |
+
}
|
83 |
+
} catch (Mage_Core_Exception $e) {
|
84 |
+
switch ($e->getCode()) {
|
85 |
+
case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
|
86 |
+
$message = $e->getMessage();
|
87 |
+
break;
|
88 |
+
default:
|
89 |
+
$message = $e->getMessage();
|
90 |
+
}
|
91 |
+
$session->addError($message);
|
92 |
+
$session->setId(null);
|
93 |
+
$log->error('Session ID is reset due to error is occurred. Exception is not logged.');
|
94 |
+
} catch (Exception $e) {
|
95 |
+
/** Mage::logException($e); // PA DSS violation: this exception log can disclose customer password */
|
96 |
+
}
|
97 |
+
} else {
|
98 |
+
$log->warn("Authentication request failure: request type is not POST or operator's current ip (" .
|
99 |
+
$validatorData['remote_addr'] . ") is not equal to ip from authentication package ($operatorIp).");
|
100 |
+
}
|
101 |
+
}
|
102 |
+
} else {
|
103 |
+
$log->warn("Cannot get customer id for authentication package '$filename'.");
|
104 |
+
}
|
105 |
+
$this->_redirect('customer/account');
|
106 |
+
}
|
107 |
+
}
|
app/code/community/Praxigento/LoginAs/controllers/RedirectController.php
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2013, Praxigento
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
7 |
+
* following conditions are met:
|
8 |
+
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
9 |
+
* disclaimer.
|
10 |
+
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
11 |
+
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
12 |
+
*
|
13 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
14 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
15 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
16 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
17 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
18 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
19 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
20 |
+
*/
|
21 |
+
/**
|
22 |
+
* Controller to process operator's requests to redirect to the frontend to login as a customer.
|
23 |
+
*/
|
24 |
+
class Praxigento_LoginAs_RedirectController extends Mage_Adminhtml_Controller_Action
|
25 |
+
{
|
26 |
+
|
27 |
+
public function indexAction()
|
28 |
+
{
|
29 |
+
if (Praxigento_LoginAs_Config::cfgGeneralEnabled()) {
|
30 |
+
/** define operator name */
|
31 |
+
/** @var $session Mage_Admin_Model_Session */
|
32 |
+
$session = Mage::getSingleton('admin/session');
|
33 |
+
if ($session->isLoggedIn()) {
|
34 |
+
/** @var $user Mage_Admin_Model_User */
|
35 |
+
$user = $session->getUser();
|
36 |
+
$operator = $user->getName() . ' (' . $user->getEmail() . ')';
|
37 |
+
/** if there is customer data in request */
|
38 |
+
if (!is_null($this->getRequest()->getParams())) {
|
39 |
+
$params = $this->getRequest()->getParams();
|
40 |
+
if (!is_null($params[Praxigento_LoginAs_Config::REQ_PARAM_LAS_ID])) {
|
41 |
+
/** extract customer ID from request and load customer data */
|
42 |
+
$customerId = $params[Praxigento_LoginAs_Config::REQ_PARAM_LAS_ID];
|
43 |
+
/** @var $customer Mage_Customer_Model_Customer */
|
44 |
+
$customer = Mage::getModel('customer/customer')->load($customerId);
|
45 |
+
if ($customer->getId() == $customerId) {
|
46 |
+
$customerName = $customer->getName();
|
47 |
+
/** define URL to login to customer's website */
|
48 |
+
$wsId = $customer->getData('website_id');
|
49 |
+
if (is_null($wsId)) {
|
50 |
+
$wsId = Mage::app()->getStore()->getWebsiteId();
|
51 |
+
}
|
52 |
+
/** @var $website Mage_Core_Model_Website */
|
53 |
+
$website = Mage::getModel('core/website')->load($wsId);
|
54 |
+
$defStoreId = $website->getDefaultStore()->getId();
|
55 |
+
$baseTarget = Mage::getStoreConfig(Mage_Core_Model_Url::XML_PATH_SECURE_URL, $defStoreId);
|
56 |
+
$baseSource = Mage::getStoreConfig(Mage_Core_Model_Url::XML_PATH_SECURE_URL);
|
57 |
+
/** compose redirection URL and replace current base by target base */
|
58 |
+
$url = Mage::getModel('core/url')->getUrl(Praxigento_LoginAs_Config::XMLCFG_ROUTER_FRONT . Praxigento_LoginAs_Config::ROUTE_CUSTOMER_LOGINAS);
|
59 |
+
$url = str_replace($baseSource, $baseTarget, $url);
|
60 |
+
/** compose authentication package */
|
61 |
+
/** @var $authPack Praxigento_LoginAs_Model_Package */
|
62 |
+
$authPack = Mage::getSingleton('prxgt_lgas_model/package');
|
63 |
+
$authPack->setAdminName($operator);
|
64 |
+
$authPack->setCustomerId($customerId);
|
65 |
+
$authPack->setCustomerName($customerName);
|
66 |
+
$authPack->setRedirectUrl($url);
|
67 |
+
$validatorData = $session->getValidatorData();
|
68 |
+
$ip = $validatorData['remote_addr'];
|
69 |
+
$authPack->setIp($ip);
|
70 |
+
/** save login data to file */
|
71 |
+
$authPack->saveAsFile();
|
72 |
+
/** log event */
|
73 |
+
$log = Praxigento_LoginAs_Model_Logger::getLogger($this);
|
74 |
+
$log->trace("Operator '$operator' is redirected to front from ip '$ip' to login" .
|
75 |
+
" as customer '$customerName' ($customerId).");
|
76 |
+
}
|
77 |
+
/** load layout and render blocks */
|
78 |
+
$this->loadLayout()->renderLayout();
|
79 |
+
}
|
80 |
+
}
|
81 |
+
}
|
82 |
+
}
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
?>
|
app/code/community/Praxigento/LoginAs/etc/config.xml
ADDED
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Copyright (c) 2013, Praxigento
|
5 |
+
* All rights reserved.
|
6 |
+
*
|
7 |
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
8 |
+
* following conditions are met:
|
9 |
+
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
10 |
+
* disclaimer.
|
11 |
+
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
12 |
+
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
13 |
+
*
|
14 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
15 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
16 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
17 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
18 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
19 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
20 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
21 |
+
*/
|
22 |
+
-->
|
23 |
+
<config>
|
24 |
+
<modules>
|
25 |
+
<Praxigento_LoginAs>
|
26 |
+
<version>1.0.0</version>
|
27 |
+
</Praxigento_LoginAs>
|
28 |
+
</modules>
|
29 |
+
<admin>
|
30 |
+
<routers>
|
31 |
+
<prxgt_lgas_router>
|
32 |
+
<use>admin</use>
|
33 |
+
<args>
|
34 |
+
<module>Praxigento_LoginAs</module>
|
35 |
+
<frontName>prxgt_lgas_admin</frontName>
|
36 |
+
</args>
|
37 |
+
</prxgt_lgas_router>
|
38 |
+
</routers>
|
39 |
+
</admin>
|
40 |
+
<adminhtml>
|
41 |
+
<acl>
|
42 |
+
<resources>
|
43 |
+
<admin>
|
44 |
+
<children>
|
45 |
+
<sales>
|
46 |
+
<children>
|
47 |
+
<order>
|
48 |
+
<children>
|
49 |
+
<prxgt_lgas_created_by_access translate="title" module="prxgt_lgas_helper">
|
50 |
+
<title>Praxigento: 'Created by' access</title>
|
51 |
+
<sort_order>1024</sort_order>
|
52 |
+
</prxgt_lgas_created_by_access>
|
53 |
+
</children>
|
54 |
+
</order>
|
55 |
+
</children>
|
56 |
+
</sales>
|
57 |
+
<customer>
|
58 |
+
<children>
|
59 |
+
<!-- add entry under Customer section -->
|
60 |
+
<prxgt_lgas_access translate="title" module="prxgt_lgas_helper">
|
61 |
+
<title>Praxigento: 'Login as Customer' access</title>
|
62 |
+
<sort_order>1024</sort_order>
|
63 |
+
</prxgt_lgas_access>
|
64 |
+
</children>
|
65 |
+
</customer>
|
66 |
+
<system>
|
67 |
+
<children>
|
68 |
+
<config>
|
69 |
+
<children>
|
70 |
+
<!-- Section on the "System/Configuration" panel -->
|
71 |
+
<!-- place ACL to config sections here -->
|
72 |
+
<prxgt_lgas translate="title" module="prxgt_lgas_helper">
|
73 |
+
<title>Praxigento: Login As Customer Section</title>
|
74 |
+
<sort_order>10600</sort_order>
|
75 |
+
</prxgt_lgas>
|
76 |
+
</children>
|
77 |
+
</config>
|
78 |
+
</children>
|
79 |
+
</system>
|
80 |
+
</children>
|
81 |
+
</admin>
|
82 |
+
</resources>
|
83 |
+
</acl>
|
84 |
+
<events>
|
85 |
+
<adminhtml_block_html_before>
|
86 |
+
<observers>
|
87 |
+
<prxgt_lgas_observer>
|
88 |
+
<type>singleton</type>
|
89 |
+
<class>prxgt_lgas_model/observer</class>
|
90 |
+
<method>onAdminhtmlBlockHtmlBefore</method>
|
91 |
+
</prxgt_lgas_observer>
|
92 |
+
</observers>
|
93 |
+
</adminhtml_block_html_before>
|
94 |
+
<adminhtml_widget_container_html_before>
|
95 |
+
<observers>
|
96 |
+
<prxgt_lgas_observer>
|
97 |
+
<type>singleton</type>
|
98 |
+
<class>prxgt_lgas_model/observer</class>
|
99 |
+
<method>onAdminhtmlWidgetContainerHtmlBefore</method>
|
100 |
+
</prxgt_lgas_observer>
|
101 |
+
</observers>
|
102 |
+
</adminhtml_widget_container_html_before>
|
103 |
+
</events>
|
104 |
+
<layout>
|
105 |
+
<updates>
|
106 |
+
<prxgt_lgas_layout_admin>
|
107 |
+
<file>prxgt/lgas/loginas_adminhtml_layout.xml</file>
|
108 |
+
</prxgt_lgas_layout_admin>
|
109 |
+
</updates>
|
110 |
+
</layout>
|
111 |
+
<translate>
|
112 |
+
<modules>
|
113 |
+
<prxgt_lgas>
|
114 |
+
<files>
|
115 |
+
<default>prxgt/lgas/prxgt_lgas.csv</default>
|
116 |
+
</files>
|
117 |
+
</prxgt_lgas>
|
118 |
+
</modules>
|
119 |
+
</translate>
|
120 |
+
</adminhtml>
|
121 |
+
<frontend>
|
122 |
+
<routers>
|
123 |
+
<prxgt_lgas_router>
|
124 |
+
<use>standard</use>
|
125 |
+
<args>
|
126 |
+
<module>Praxigento_LoginAs</module>
|
127 |
+
<frontName>prxgt_lgas_front</frontName>
|
128 |
+
</args>
|
129 |
+
</prxgt_lgas_router>
|
130 |
+
</routers>
|
131 |
+
</frontend>
|
132 |
+
<global>
|
133 |
+
<events>
|
134 |
+
<sales_convert_quote_address_to_order>
|
135 |
+
<observers>
|
136 |
+
<prxgt_lgas_observer>
|
137 |
+
<type>singleton</type>
|
138 |
+
<class>prxgt_lgas_model/observer</class>
|
139 |
+
<method>onSalesConvertQuoteAddressToOrder</method>
|
140 |
+
</prxgt_lgas_observer>
|
141 |
+
</observers>
|
142 |
+
</sales_convert_quote_address_to_order>
|
143 |
+
</events>
|
144 |
+
<helpers>
|
145 |
+
<!-- Default helper for module (prevents errors like "Class 'Namespace_Module_Helper_Data' not found in") -->
|
146 |
+
<prxgt_lgas_helper>
|
147 |
+
<class>Praxigento_LoginAs_Helper</class>
|
148 |
+
</prxgt_lgas_helper>
|
149 |
+
</helpers>
|
150 |
+
<models>
|
151 |
+
<prxgt_lgas_model>
|
152 |
+
<class>Praxigento_LoginAs_Model</class>
|
153 |
+
</prxgt_lgas_model>
|
154 |
+
</models>
|
155 |
+
<resources>
|
156 |
+
<prxgt_lgas_setup>
|
157 |
+
<setup>
|
158 |
+
<module>Praxigento_LoginAs</module>
|
159 |
+
</setup>
|
160 |
+
<connection>
|
161 |
+
<use>core_setup</use>
|
162 |
+
</connection>
|
163 |
+
</prxgt_lgas_setup>
|
164 |
+
</resources>
|
165 |
+
</global>
|
166 |
+
</config>
|
app/code/community/Praxigento/LoginAs/etc/system.xml
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Copyright (c) 2013, Praxigento
|
5 |
+
* All rights reserved.
|
6 |
+
*
|
7 |
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
8 |
+
* following conditions are met:
|
9 |
+
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
10 |
+
* disclaimer.
|
11 |
+
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
12 |
+
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
13 |
+
*
|
14 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
15 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
16 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
17 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
18 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
19 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
20 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
21 |
+
*/
|
22 |
+
-->
|
23 |
+
<config>
|
24 |
+
<tabs>
|
25 |
+
<prxgt>
|
26 |
+
<!-- This is all module's common tab (should be the same for all modules) -->
|
27 |
+
<label>Praxigento</label>
|
28 |
+
<sort_order>1024</sort_order>
|
29 |
+
</prxgt>
|
30 |
+
</tabs>
|
31 |
+
<sections>
|
32 |
+
<prxgt_lgas translate="label comment" module="prxgt_lgas_helper">
|
33 |
+
<label>Login as Customer</label>
|
34 |
+
<tab>prxgt</tab>
|
35 |
+
<frontend_type>text</frontend_type>
|
36 |
+
<sort_order>10600</sort_order>
|
37 |
+
<show_in_default>1</show_in_default>
|
38 |
+
<show_in_website>1</show_in_website>
|
39 |
+
<show_in_store>1</show_in_store>
|
40 |
+
<groups>
|
41 |
+
<general>
|
42 |
+
<!-- ******* -->
|
43 |
+
<!-- General -->
|
44 |
+
<!-- ******* -->
|
45 |
+
<label>General</label>
|
46 |
+
<sort_order>100</sort_order>
|
47 |
+
<show_in_default>1</show_in_default>
|
48 |
+
<show_in_website>0</show_in_website>
|
49 |
+
<show_in_store>0</show_in_store>
|
50 |
+
<fields>
|
51 |
+
<enabled>
|
52 |
+
<label>Enable 'Login as Customer'</label>
|
53 |
+
<comment>Check ACL entries (System / Permissions / Roles) in case of feature is enabled but is not accessible.</comment>
|
54 |
+
<frontend_type>select</frontend_type>
|
55 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
56 |
+
<sort_order>100</sort_order>
|
57 |
+
<show_in_default>1</show_in_default>
|
58 |
+
<show_in_website>0</show_in_website>
|
59 |
+
<show_in_store>0</show_in_store>
|
60 |
+
</enabled>
|
61 |
+
<log_events>
|
62 |
+
<label>Log Events</label>
|
63 |
+
<comment>Log 'login as' events (log4php lib is used in case of Nmmlm_Log module is installed).</comment>
|
64 |
+
<frontend_type>select</frontend_type>
|
65 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
66 |
+
<sort_order>200</sort_order>
|
67 |
+
<show_in_default>1</show_in_default>
|
68 |
+
<show_in_website>0</show_in_website>
|
69 |
+
<show_in_store>0</show_in_store>
|
70 |
+
</log_events>
|
71 |
+
</fields>
|
72 |
+
</general>
|
73 |
+
<ui>
|
74 |
+
<!-- ******** -->
|
75 |
+
<!-- UI setup -->
|
76 |
+
<!-- ******** -->
|
77 |
+
<label>UI Setup</label>
|
78 |
+
<sort_order>200</sort_order>
|
79 |
+
<show_in_default>1</show_in_default>
|
80 |
+
<show_in_website>0</show_in_website>
|
81 |
+
<show_in_store>0</show_in_store>
|
82 |
+
<fields>
|
83 |
+
<action_enabled>
|
84 |
+
<label>Display 'Login as' Action</label>
|
85 |
+
<comment>Display action on the customers grid.</comment>
|
86 |
+
<frontend_type>select</frontend_type>
|
87 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
88 |
+
<sort_order>200</sort_order>
|
89 |
+
<show_in_default>1</show_in_default>
|
90 |
+
<show_in_website>0</show_in_website>
|
91 |
+
<show_in_store>0</show_in_store>
|
92 |
+
</action_enabled>
|
93 |
+
<orders_grid_column_enabled>
|
94 |
+
<label>Display 'Created by' Column</label>
|
95 |
+
<comment>Display column on the orders grid.</comment>
|
96 |
+
<frontend_type>select</frontend_type>
|
97 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
98 |
+
<sort_order>300</sort_order>
|
99 |
+
<show_in_default>1</show_in_default>
|
100 |
+
<show_in_website>0</show_in_website>
|
101 |
+
<show_in_store>0</show_in_store>
|
102 |
+
</orders_grid_column_enabled>
|
103 |
+
<orders_grid_column_position>
|
104 |
+
<label>Position for 'Created by' Column</label>
|
105 |
+
<comment>Setup position for the column on the orders grid.</comment>
|
106 |
+
<frontend_type>text</frontend_type>
|
107 |
+
<validate>required-entry validate-digits validate-digits-range digits-range-1-</validate>
|
108 |
+
<sort_order>400</sort_order>
|
109 |
+
<show_in_default>1</show_in_default>
|
110 |
+
<show_in_website>0</show_in_website>
|
111 |
+
<show_in_store>0</show_in_store>
|
112 |
+
</orders_grid_column_position>
|
113 |
+
</fields>
|
114 |
+
</ui>
|
115 |
+
</groups>
|
116 |
+
</prxgt_lgas>
|
117 |
+
</sections>
|
118 |
+
</config>
|
app/code/community/Praxigento/LoginAs/sql/prxgt_lgas_setup/mysql4-install-1.0.0.php
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2013, Praxigento
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
7 |
+
* following conditions are met:
|
8 |
+
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
9 |
+
* disclaimer.
|
10 |
+
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
11 |
+
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
12 |
+
*
|
13 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
14 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
15 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
16 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
17 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
18 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
19 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
20 |
+
*/
|
21 |
+
/**
|
22 |
+
* Initial installation script. Contains all upgrades
|
23 |
+
*/
|
24 |
+
/** include function to replace old columns with new ones */
|
25 |
+
include_once('prxgt_install_func.php');
|
26 |
+
|
27 |
+
|
28 |
+
const SQL_TYPE_VARCHAR = 'VARCHAR(255) DEFAULT NULL';
|
29 |
+
|
30 |
+
/** @var $installer Mage_Core_Model_Resource_Setup */
|
31 |
+
$installer = $this;
|
32 |
+
/** @var $coreSetup Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */
|
33 |
+
$coreSetup = new Mage_Eav_Model_Entity_Setup('core_setup');
|
34 |
+
/** @var $conn Varien_Db_Adapter_Interface */
|
35 |
+
$conn = $installer->getConnection();
|
36 |
+
|
37 |
+
/** ****************************************************************************************************************
|
38 |
+
* Create table columns for static attributes
|
39 |
+
***************************************************************************************************************** */
|
40 |
+
|
41 |
+
/** Sales Order */
|
42 |
+
prxgt_install_recreate_column($conn, $this->getTable('sales/order'),
|
43 |
+
Praxigento_LoginAs_Config::ATTR_ORDER_CREATED_BY, SQL_TYPE_VARCHAR . ' ' .
|
44 |
+
'COMMENT \'admin name/email if Praxigento Login As feature was used.\'');
|
45 |
+
|
46 |
+
/** Sales Order */
|
47 |
+
prxgt_install_recreate_column($conn, $this->getTable('sales/order_grid'),
|
48 |
+
Praxigento_LoginAs_Config::ATTR_ORDER_CREATED_BY, SQL_TYPE_VARCHAR . ' ' .
|
49 |
+
'COMMENT \'admin name/email if Praxigento Login As feature was used.\'');
|
app/code/community/Praxigento/LoginAs/sql/prxgt_lgas_setup/prxgt_install_func.php
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2013, Praxigento
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
7 |
+
* following conditions are met:
|
8 |
+
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
9 |
+
* disclaimer.
|
10 |
+
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
11 |
+
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
12 |
+
*
|
13 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
14 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
15 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
16 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
17 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
18 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
19 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
20 |
+
*/
|
21 |
+
/**
|
22 |
+
* Functions library to be used in install/upgrade scripts.
|
23 |
+
*
|
24 |
+
* User: Flancer
|
25 |
+
* Date: 1/9/13
|
26 |
+
* Time: 1:05 PM
|
27 |
+
*/
|
28 |
+
/** ===========================================================================================================================
|
29 |
+
* Functions section below...
|
30 |
+
* ========================================================================================================================== */
|
31 |
+
/**
|
32 |
+
* Backup data for existing column, re-create column and move data back. Removes 'columnOld' in case of new name
|
33 |
+
* for the column was applied.
|
34 |
+
*
|
35 |
+
* @param Varien_Db_Adapter_Interface $conn
|
36 |
+
* @param $table
|
37 |
+
* @param $column
|
38 |
+
* @param $columnDef
|
39 |
+
* @param null $columnOld old name for the column
|
40 |
+
*/
|
41 |
+
function prxgt_install_recreate_column(Varien_Db_Adapter_Pdo_Mysql $conn, $table, $column, $columnDef, $columnOld = null)
|
42 |
+
{
|
43 |
+
$columnTmp = $column . '_tmp';
|
44 |
+
$fetched = $conn->fetchAll("SELECT * FROM $table LIMIT 1");
|
45 |
+
|
46 |
+
// analyze old named column data
|
47 |
+
$oldColumnExists = (!is_null($columnOld) && is_array($fetched) && isset($fetched[0]) && array_key_exists($columnOld, $fetched[0]));
|
48 |
+
// analyze current column data
|
49 |
+
$columnExists = (is_array($fetched) && isset($fetched[0]) && array_key_exists($column, $fetched[0]));
|
50 |
+
// create backup column and backup data
|
51 |
+
if ($columnExists || $oldColumnExists) {
|
52 |
+
$conn->addColumn($table, $columnTmp, $columnDef);
|
53 |
+
if ($oldColumnExists) {
|
54 |
+
// backup old column data
|
55 |
+
$conn->query("UPDATE $table SET $columnTmp = $columnOld");
|
56 |
+
} else {
|
57 |
+
// backup current column data
|
58 |
+
$conn->query("UPDATE $table SET $columnTmp = $column");
|
59 |
+
}
|
60 |
+
}
|
61 |
+
// re-create current column
|
62 |
+
$conn->dropColumn($table, $column);
|
63 |
+
$conn->addColumn($table, $column, $columnDef);
|
64 |
+
// restore column data from backup
|
65 |
+
if ($columnExists || $oldColumnExists) {
|
66 |
+
// restore existed data
|
67 |
+
$conn->query("UPDATE $table SET $column = $columnTmp");
|
68 |
+
$conn->dropColumn($table, $columnTmp);
|
69 |
+
}
|
70 |
+
// drop old column (for case of empty table)
|
71 |
+
if (!is_null($columnOld) && ($oldColumnExists) && ($columnOld != $column)) {
|
72 |
+
$conn->dropColumn($table, $columnOld);
|
73 |
+
}
|
74 |
+
}
|
app/design/adminhtml/default/default/layout/prxgt/lgas/loginas_adminhtml_layout.xml
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Copyright (c) 2013, Praxigento
|
5 |
+
* All rights reserved.
|
6 |
+
*
|
7 |
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
8 |
+
* following conditions are met:
|
9 |
+
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
10 |
+
* disclaimer.
|
11 |
+
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
12 |
+
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
13 |
+
*
|
14 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
15 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
16 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
17 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
18 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
19 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
20 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
21 |
+
*/
|
22 |
+
-->
|
23 |
+
<layout version="0.1.0">
|
24 |
+
<!-- ****************************************************************************** -->
|
25 |
+
<!-- Handler name ([router][controller][action]): -->
|
26 |
+
<!-- ... [nmmlm_core_router]_[sync_products]_[index] -->
|
27 |
+
<!-- ... Nmmlm/Core/controllers/Sync/ProductsController.php:indexAction() -->
|
28 |
+
<!-- ****************************************************************************** -->
|
29 |
+
<prxgt_lgas_router_redirect_index>
|
30 |
+
<block type="adminhtml/template" name="root" template="prxgt/lgas/redirect.phtml"/>
|
31 |
+
</prxgt_lgas_router_redirect_index>
|
32 |
+
</layout>
|
app/design/adminhtml/default/default/template/prxgt/lgas/redirect.phtml
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2013, Praxigento
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
7 |
+
* following conditions are met:
|
8 |
+
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
9 |
+
* disclaimer.
|
10 |
+
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
11 |
+
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
12 |
+
*
|
13 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
14 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
15 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
16 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
17 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
18 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
19 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
20 |
+
*/
|
21 |
+
?>
|
22 |
+
<?php
|
23 |
+
/**
|
24 |
+
* Customer login form - auto redirect to account controller with custom LoginAs action.
|
25 |
+
*
|
26 |
+
* @see Nmmlm_Core_Block_Default
|
27 |
+
*/
|
28 |
+
?>
|
29 |
+
<?php
|
30 |
+
/** @var $this Mage_Adminhtml_Block_Template */
|
31 |
+
/** @var $authPack Praxigento_LoginAs_Model_Package */
|
32 |
+
$authPack = Mage::getSingleton('prxgt_lgas_model/package');
|
33 |
+
?>
|
34 |
+
<html>
|
35 |
+
<body>
|
36 |
+
<form action="<?php echo $authPack->getRedirectUrl() ?>"
|
37 |
+
method="post" id="login-form">
|
38 |
+
<?php /** Post file name with login parameters */?>
|
39 |
+
<input type="hidden" name="<?php echo Praxigento_LoginAs_Config::REQ_PARAM_LAS_ID ?>"
|
40 |
+
id="<?php echo Praxigento_LoginAs_Config::REQ_PARAM_LAS_ID ?>"
|
41 |
+
value="<?php echo $authPack->getPackageId() ?>"/>
|
42 |
+
</form>
|
43 |
+
<script type="text/javascript">
|
44 |
+
//<![CDATA[
|
45 |
+
document.getElementById("login-form").submit();
|
46 |
+
//]]>
|
47 |
+
</script>
|
48 |
+
</body>
|
49 |
+
</html>
|
app/etc/modules/Praxigento_LoginAs.xml
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Copyright (c) 2013, Praxigento
|
5 |
+
* All rights reserved.
|
6 |
+
*
|
7 |
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
8 |
+
* following conditions are met:
|
9 |
+
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
10 |
+
* disclaimer.
|
11 |
+
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
12 |
+
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
13 |
+
*
|
14 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
15 |
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
16 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
17 |
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
18 |
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
19 |
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
20 |
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
21 |
+
*/
|
22 |
+
-->
|
23 |
+
<config>
|
24 |
+
<modules>
|
25 |
+
<Praxigento_LoginAs>
|
26 |
+
<active>true</active>
|
27 |
+
<codePool>community</codePool>
|
28 |
+
</Praxigento_LoginAs>
|
29 |
+
</modules>
|
30 |
+
</config>
|
app/locale/en_US/prxgt/lgas/prxgt_lgas.csv
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"Login as Customer","Login as Customer"
|
2 |
+
"Login as...","Login as..."
|
3 |
+
"Created by","Created by"
|
4 |
+
"Praxigento: 'Created by' access","Praxigento: 'Created by' access"
|
5 |
+
"Praxigento: 'Login as Customer' access","Praxigento: 'Login as Customer' access"
|
6 |
+
"Praxigento: Login As Customer Section","Praxigento: Login As Customer Section"
|
7 |
+
"Enable 'Login as Customer'","Enable 'Login as Customer'"
|
8 |
+
"Check ACL entries (System / Permissions / Roles) in case of feature is enabled but is not accessible.","Check ACL entries (System / Permissions / Roles) in case of feature is enabled but is not accessible."
|
9 |
+
"Log Events","Log Events"
|
10 |
+
"Log 'login as' events (log4php lib is used in case of Nmmlm_Log module is installed).","Log 'login as' events (log4php lib is used in case of Nmmlm_Log module is installed)."
|
11 |
+
"UI Setup","UI Setup"
|
12 |
+
"Display 'Login as' Action","Display 'Login as' Action"
|
13 |
+
"Display action on the customers grid.","Display action on the customers grid."
|
14 |
+
"Display 'Created by' Column","Display 'Created by' Column"
|
15 |
+
"Display column on the orders grid.","Display column on the orders grid."
|
16 |
+
"Position for 'Created by' Column","Position for 'Created by' Column"
|
17 |
+
"Setup position for the column on the orders grid.","Setup position for the column on the orders grid."
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Praxigento_LoginAs</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://opensource.org/licenses/apachepl-1.1.php">ASF</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Login as Customer by Praxigento</summary>
|
10 |
+
<description>Allows store manager to login as a customer right from admin panel. No need for master password.</description>
|
11 |
+
<notes>Hello World! :)</notes>
|
12 |
+
<authors><author><name>Alex Gusev</name><user>praxigento</user><email>info@flancer.lv</email></author></authors>
|
13 |
+
<date>2013-02-28</date>
|
14 |
+
<time>08:54:50</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="Praxigento"><dir name="LoginAs"><file name="Config.php" hash="47ab33ba8197f2e952db00ee60a64e86"/><dir name="Helper"><file name="Data.php" hash="8953db573e1a359cce3177741a166024"/></dir><dir name="Model"><file name="Logger.php" hash="04ddc399d206a4f9c1c5f6088c8ad811"/><file name="Observer.php" hash="3b3e9128dfe7883344380956faff175c"/><file name="Package.php" hash="1c945f7061451eaec17ca7ba15d03590"/></dir><dir name="Test"><file name="ConfigTest.php" hash="bce99007796d30ee4086eba5a5c1fb08"/><dir name="Model"><file name="LoggerTest.php" hash="6f45e5a49612305912fd1fce72734008"/></dir><file name="phpunit.bootstrap.php" hash="b27a8bb387f22af87d3505d1ef6c0325"/><file name="phpunit.praxigento.loginas.xml" hash="8fdc08af610b56397ce4a026bbf1bf71"/></dir><dir name="controllers"><file name="LoginController.php" hash="bbb4de789aaec13af2f191a2015c728a"/><file name="RedirectController.php" hash="05133cd77c2d0cb9a99fe840d7247e73"/></dir><dir name="etc"><file name="config.xml" hash="8be7ad2f46c5d38ae4e5b743391e674f"/><file name="system.xml" hash="061cc6ca4787a71a07c6844c2efd7bf9"/></dir><dir name="sql"><dir name="prxgt_lgas_setup"><file name="mysql4-install-1.0.0.php" hash="e411ae4ef99146b606ddcdaf49020f8b"/><file name="prxgt_install_func.php" hash="17e7e7f7ac12da3c31eeb7ba37c3d524"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="prxgt"><dir name="lgas"><file name="loginas_adminhtml_layout.xml" hash="1c738335b661f3f5d68fa81520bd5d7a"/></dir></dir></dir><dir name="template"><dir name="prxgt"><dir name="lgas"><file name="redirect.phtml" hash="ccda9df924c7a0e79fdf85c163890674"/></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><dir name="prxgt"><dir name="lgas"><file name="prxgt_lgas.csv" hash="fa4a8396c84de6c3585b87d13c882085"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Praxigento_LoginAs.xml" hash="bbff13b9b95dfa4d1dd28bd2e25f74a3"/></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
18 |
+
</package>
|