DataFeedWatch_Connector - Version 0.1.0

Version Notes

DataFeedWatch

Download this release

Release Info

Developer DataFeedWatch
Extension DataFeedWatch_Connector
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/DataFeedWatch/Connector/Block/Adminhtml/Connectorbackend.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class DataFeedWatch_Connector_Block_Adminhtml_Connectorbackend extends Mage_Adminhtml_Block_Template {
4
+ protected $email = 'magento@datafeedwatch.com';
5
+
6
+ public function __construct() {
7
+ parent::__construct();
8
+ $this->assign('user', $this->getUser());
9
+ }
10
+
11
+ public function getCreateUserUrl() {
12
+ return $this->getUrl('*/*/createuser');
13
+ }
14
+
15
+ public function getUpdateTokenUrl() {
16
+ return $this->getUrl('*/*/updatetoken');
17
+ }
18
+
19
+ public function getUser() {
20
+ $model = Mage::getModel('api/user');
21
+ return $model->load($this->email, 'email');
22
+ }
23
+ }
app/code/local/DataFeedWatch/Connector/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class DataFeedWatch_Connector_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ }
5
+
app/code/local/DataFeedWatch/Connector/controllers/Adminhtml/ConnectorbackendController.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class DataFeedWatch_Connector_Adminhtml_ConnectorbackendController extends Mage_Adminhtml_Controller_Action {
3
+ protected $username = 'datafeedwatch';
4
+ protected $firstname = 'Api Access';
5
+ protected $lastname = 'DataFeedWatch';
6
+ protected $email = 'magento@datafeedwatch.com';
7
+ protected $register_url = 'https://my.datafeedwatch.com/platforms/magento/sessions/finalize';
8
+
9
+ public function indexAction() {
10
+ $this->loadLayout();
11
+ $this->_title($this->__("DataFeedWatch"));
12
+ $this->renderLayout();
13
+ }
14
+
15
+ public function createuserAction() {
16
+ $api_key = $this->_generateApiKey();
17
+
18
+ $data = array(
19
+ 'username' => $this->username,
20
+ 'firstname' => $this->firstname,
21
+ 'lastname' => $this->lastname,
22
+ 'email' => $this->email,
23
+ 'api_key' => $api_key,
24
+ 'api_key_confirmation' => $api_key,
25
+ 'is_active' => 1
26
+ );
27
+
28
+ $role = Mage::getModel('api/roles')->load($this->lastname, 'role_name');
29
+
30
+ if ($role->isObjectNew()) {
31
+ $role = $role
32
+ ->setName($this->lastname)
33
+ ->setPid(false)
34
+ ->setRoleType('G')
35
+ ->save();
36
+
37
+ $resource = array("all");
38
+
39
+ Mage::getModel("api/rules")
40
+ ->setRoleId($role->getId())
41
+ ->setResources($resource)
42
+ ->saveRel();
43
+ }
44
+
45
+
46
+ $user = Mage::getModel('api/user');
47
+ $user->setData($data);
48
+ $user->save();
49
+
50
+ $user->setRoleId($role->getId())->setUserId($user->getId());
51
+ $user->add();
52
+
53
+ $this->getResponse()->setRedirect($this->_registerUrl($api_key));
54
+ return;
55
+ }
56
+
57
+ public function updatetokenAction() {
58
+ $api_key = $this->_generateApiKey();
59
+ $model = $this->getUser();
60
+
61
+ $data = array(
62
+ 'user_id' => $model->getId(),
63
+ 'username' => $this->username,
64
+ 'firstname' => $this->firstname,
65
+ 'lastname' => $this->lastname,
66
+ 'email' => $this->email,
67
+ 'api_key' => $api_key,
68
+ 'api_key_confirmation' => $api_key
69
+ );
70
+
71
+ $model->setData($data);
72
+ $model->save();
73
+
74
+ $this->getResponse()->setRedirect($this->_registerUrl($api_key));
75
+ return;
76
+ }
77
+
78
+ public function getUser() {
79
+ $model = Mage::getModel('api/user');
80
+ return $model->load($this->email, 'email');
81
+ }
82
+
83
+ private function _generateApiKey() {
84
+ return sha1(time()+substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 32));
85
+ }
86
+
87
+ private function _registerUrl($api_key) {
88
+ return $this->register_url.'?shop='.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'&token='.$api_key;
89
+ }
90
+ }
app/code/local/DataFeedWatch/Connector/etc/config.xml ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <DataFeedWatch_Connector>
5
+ <version>0.1.0</version>
6
+ </DataFeedWatch_Connector>
7
+ </modules>
8
+ <admin>
9
+ <routers>
10
+ <connector>
11
+ <use>admin</use>
12
+ <args>
13
+ <module>DataFeedWatch_Connector</module>
14
+ <frontName>connector</frontName>
15
+ </args>
16
+ </connector>
17
+ </routers>
18
+ </admin>
19
+ <adminhtml>
20
+ <menu>
21
+ <catalog translate="title" module="adminhtml">
22
+ <children>
23
+ <connectorbackend translate="title" module="connector">
24
+ <title>DataFeedWatch</title>
25
+ <action>connector/adminhtml_connectorbackend</action>
26
+ </connectorbackend>
27
+ </children>
28
+ </catalog>
29
+ </menu>
30
+ <acl>
31
+ <resources>
32
+ <admin>
33
+ <catalog>
34
+ <children>
35
+ <connectorbackend translate="title" module="connector">
36
+ <title>DataFeedWatch</title>
37
+ </connectorbackend>
38
+ </children>
39
+ </catalog>
40
+ </admin>
41
+ </resources>
42
+ </acl>
43
+ <layout>
44
+ <updates>
45
+ <connector>
46
+ <file>connector.xml</file>
47
+ </connector>
48
+ </updates>
49
+ </layout>
50
+ </adminhtml>
51
+ <global>
52
+ <helpers>
53
+ <connector>
54
+ <class>DataFeedWatch_Connector_Helper</class>
55
+ </connector>
56
+ </helpers>
57
+ <blocks>
58
+ <connector>
59
+ <class>DataFeedWatch_Connector_Block</class>
60
+ </connector>
61
+ </blocks>
62
+ <resources>
63
+ <datafeedwatch_connector_setup>
64
+ <setup>
65
+ <module>DataFeedWatch_Connector</module>
66
+ </setup>
67
+ <connection>
68
+ <use>core_setup</use>
69
+ </connection>
70
+ </datafeedwatch_connector_setup>
71
+ </resources>
72
+ </global>
73
+ </config>
app/code/local/DataFeedWatch/Connector/etc/system.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <datafeedwatch translate="label" module="connector">
5
+ <label>DataFeedWatch</label>
6
+ <sort_order>666</sort_order>
7
+ </datafeedwatch>
8
+ </tabs>
9
+ </config>
app/design/adminhtml/default/default/layout/connector.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <connector_adminhtml_connectorbackend_index>
4
+ <reference name="content">
5
+ <block type="connector/adminhtml_connectorbackend" name="connectorbackend" template="connector/connectorbackend.phtml"/>
6
+ </reference>
7
+ </connector_adminhtml_connectorbackend_index>
8
+ </layout>
app/design/adminhtml/default/default/template/connector/connectorbackend.phtml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <h1>Demo Backend Page Content</h1>
2
+ <br/>
3
+ <br/>
4
+ <?php
5
+ if ($user->isObjectNew()) {
6
+ ?>
7
+ DataFeedWatch api user is not created, please create one in order to connect.
8
+ <br/><br/>
9
+ <a href="<?=$this->getCreateUserUrl()?>">Register in DataFeedWatch</a>
10
+ <?php
11
+ } else {
12
+ ?>
13
+ DataFeedWatch api user is already created.
14
+ <br/>
15
+ <a href="<?=$this->getUpdateTokenUrl()?>">Re-register in DataFeedWatch</a>
16
+ <?php
17
+ }
18
+ ?>
app/etc/modules/DataFeedWatch_Connector.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <DataFeedWatch_Connector>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </DataFeedWatch_Connector>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>DataFeedWatch_Connector</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license>GPL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>DataFeedWatch</summary>
10
+ <description>DataFeedWatch</description>
11
+ <notes>DataFeedWatch</notes>
12
+ <authors><author><name>DataFeedWatch</name><user>datafeedwatch</user><email>support@datafeedwatch.com</email></author></authors>
13
+ <date>2013-02-07</date>
14
+ <time>16:26:28</time>
15
+ <contents><target name="magelocal"><dir name="DataFeedWatch"><dir name="Connector"><dir name="Block"><dir name="Adminhtml"><file name="Connectorbackend.php" hash="afe5bd4888768229d5b668f466b770b5"/></dir></dir><dir name="Helper"><file name="Data.php" hash="983d7ad023616b365dce180680e4f9f0"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="ConnectorbackendController.php" hash="dfa561302ef7eebe656b229fe275a2eb"/></dir></dir><dir name="etc"><file name="config.xml" hash="d0acf798ce2cca1669a54db93ee207d6"/><file name="system.xml" hash="ab5e8d56d032ba69c930ab7879484212"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="connector.xml" hash="14d59b8e9f66fba5d7c1f8d0f62dfc3c"/></dir><dir name="template"><dir name="connector"><file name="connectorbackend.phtml" hash="f5ec823243774408a1b65e74af144f5b"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="DataFeedWatch_Connector.xml" hash="a8d7c5380f228369550b2b0db81bd82a"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>