Version Notes
First Release
Download this release
Release Info
Developer | OneAll |
Extension | OneAll_SingleSignOn |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/OneAll/SingleSignOn/Block/Adminhtml/System/Config/Fieldset/General.php +85 -0
- app/code/community/OneAll/SingleSignOn/Helper/Data.php +1662 -0
- app/code/community/OneAll/SingleSignOn/Model/Apiautodetect.php +146 -0
- app/code/community/OneAll/SingleSignOn/Model/Apiconnectionhandler.php +48 -0
- app/code/community/OneAll/SingleSignOn/Model/Apiconnectionport.php +48 -0
- app/code/community/OneAll/SingleSignOn/Model/Apiverify.php +135 -0
- app/code/community/OneAll/SingleSignOn/Model/Autocreateaccounts.php +44 -0
- app/code/community/OneAll/SingleSignOn/Model/Autocreatesendmail.php +44 -0
- app/code/community/OneAll/SingleSignOn/Model/Autolinkaccounts.php +44 -0
- app/code/community/OneAll/SingleSignOn/Model/Autolinkunverified.php +44 -0
- app/code/community/OneAll/SingleSignOn/Model/Observer.php +290 -0
- app/code/community/OneAll/SingleSignOn/Model/Resource/Session.php +34 -0
- app/code/community/OneAll/SingleSignOn/Model/Resource/Session/Collection.php +33 -0
- app/code/community/OneAll/SingleSignOn/Model/Resource/User.php +34 -0
- app/code/community/OneAll/SingleSignOn/Model/Resource/User/Collection.php +33 -0
- app/code/community/OneAll/SingleSignOn/Model/Session.php +34 -0
- app/code/community/OneAll/SingleSignOn/Model/Sessionlifetime.php +92 -0
- app/code/community/OneAll/SingleSignOn/Model/Sessionsubrealm.php +44 -0
- app/code/community/OneAll/SingleSignOn/Model/Subdomain.php +47 -0
- app/code/community/OneAll/SingleSignOn/Model/User.php +34 -0
- app/code/community/OneAll/SingleSignOn/controllers/AjaxController.php +168 -0
- app/code/community/OneAll/SingleSignOn/etc/adminhtml.xml +22 -0
- app/code/community/OneAll/SingleSignOn/etc/config.xml +162 -0
- app/code/community/OneAll/SingleSignOn/etc/system.xml +228 -0
- app/code/community/OneAll/SingleSignOn/sql/oneall_singlesignon_setup/mysql4-install-1.0.0.php +60 -0
- app/design/frontend/base/default/layout/oneall-singlesignon.xml +13 -0
- app/design/frontend/base/default/template/oneall/singlesignon/loggedin.phtml +74 -0
- app/design/frontend/base/default/template/oneall/singlesignon/loggedout.phtml +144 -0
- app/etc/modules/OneAll_SingleSignOn.xml +35 -0
- package.xml +22 -0
app/code/community/OneAll/SingleSignOn/Block/Adminhtml/System/Config/Fieldset/General.php
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
class OneAll_SingleSignOn_Block_Adminhtml_System_Config_Fieldset_General extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
|
27 |
+
{
|
28 |
+
protected function _getHeaderHtml ($element)
|
29 |
+
{
|
30 |
+
if (method_exists ($this, '_getHeaderTitleHtml'))
|
31 |
+
{
|
32 |
+
if ($element->getIsNested ())
|
33 |
+
{
|
34 |
+
$html = '<tr class="nested"><td colspan="4"><div class="' . $this->_getFrontendClass ($element) . '">';
|
35 |
+
}
|
36 |
+
else
|
37 |
+
{
|
38 |
+
$html = '<div class="' . $this->_getFrontendClass ($element) . '">';
|
39 |
+
}
|
40 |
+
|
41 |
+
$html .= $this->_getHeaderTitleHtml ($element);
|
42 |
+
$html .= '<input id="' . $element->getHtmlId () . '-state" name="config_state[' . $element->getId () . ']" type="hidden" value="' . (int) $this->_getCollapseState ($element) . '" />';
|
43 |
+
$html .= '<fieldset class="' . $this->_getFieldsetCss ($element) . '" id="' . $element->getHtmlId () . '">';
|
44 |
+
$html .= '<legend>' . $element->getLegend () . '</legend>';
|
45 |
+
$html .= $this->_getHeaderCommentHtml ($element);
|
46 |
+
|
47 |
+
// field label column
|
48 |
+
$html .= '<table cellspacing="0" class="form-list"><colgroup class="label" /><colgroup class="value" />';
|
49 |
+
if ($this->getRequest ()->getParam ('website') || $this->getRequest ()->getParam ('store'))
|
50 |
+
{
|
51 |
+
$html .= '<colgroup class="use-default" />';
|
52 |
+
}
|
53 |
+
$html .= '<colgroup class="scope-label" /><colgroup class="" /><tbody>';
|
54 |
+
}
|
55 |
+
else
|
56 |
+
{
|
57 |
+
$default = ! $this->getRequest ()->getParam ('website') && ! $this->getRequest ()->getParam ('store');
|
58 |
+
$html = '<div class="entry-edit-head collapseable" >';
|
59 |
+
$html .= '<a id="' . $element->getHtmlId () . '-head" href="#" onclick="Fieldset.toggleCollapse(\'' . $element->getHtmlId () . '\', \'' . $this->getUrl ('*/*/state') . '\'); return false;">' . $element->getLegend () . '</a></div>';
|
60 |
+
$html .= '<input id="' . $element->getHtmlId () . '-state" name="config_state[' . $element->getId () . ']" type="hidden" value="' . (int) $this->_getCollapseState ($element) . '" />';
|
61 |
+
$html .= '<fieldset class="' . $this->_getFieldsetCss () . '" id="' . $element->getHtmlId () . '">';
|
62 |
+
$html .= '<legend>' . $element->getLegend () . '</legend>';
|
63 |
+
|
64 |
+
if ($element->getComment ())
|
65 |
+
{
|
66 |
+
$html .= '<div class="comment">' . $element->getComment () . '</div>';
|
67 |
+
}
|
68 |
+
|
69 |
+
// Field label column
|
70 |
+
$html .= '<table cellspacing="0" class="form-list"><colgroup class="label" /><colgroup class="value" />';
|
71 |
+
if (! $default)
|
72 |
+
{
|
73 |
+
$html .= '<colgroup class="use-default" />';
|
74 |
+
}
|
75 |
+
$html .= '<colgroup class="scope-label" /><colgroup class="" /><tbody>';
|
76 |
+
}
|
77 |
+
return $html;
|
78 |
+
}
|
79 |
+
|
80 |
+
protected function _getFieldsetCss ($element = null)
|
81 |
+
{
|
82 |
+
$configCss = (string) $this->getGroup ($element)->fieldset_css;
|
83 |
+
return 'config collapseable' . ($configCss ? ' ' . $configCss : '');
|
84 |
+
}
|
85 |
+
}
|
app/code/community/OneAll/SingleSignOn/Helper/Data.php
ADDED
@@ -0,0 +1,1662 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
class OneAll_SingleSignOn_Helper_Data extends Mage_Core_Helper_Abstract
|
26 |
+
{
|
27 |
+
const USER_AGENT = 'SingleSignOn/1.0.0 Magento/1.x (+http://www.oneall.com/)';
|
28 |
+
const ENABLE_LOGGING = true;
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Add a log to our log file.
|
32 |
+
*/
|
33 |
+
public function add_log ($contents, $level = null)
|
34 |
+
{
|
35 |
+
if (self::ENABLE_LOGGING)
|
36 |
+
{
|
37 |
+
Mage::log ($contents, $level, 'oneall_singlesignon.log');
|
38 |
+
}
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Return the extension settings.
|
43 |
+
*/
|
44 |
+
public function get_settings ()
|
45 |
+
{
|
46 |
+
$settings = array();
|
47 |
+
|
48 |
+
// API Connection Handler.
|
49 |
+
$settings ['connection_handler'] = (Mage::getStoreConfig ('oneall_singlesignon/connection/handler') == 'fsockopen' ? 'fsockopen' : 'curl');
|
50 |
+
$settings ['connection_port'] = (Mage::getStoreConfig ('oneall_singlesignon/connection/port') == 80 ? 80 : 443);
|
51 |
+
$settings ['connection_protocol'] = ($settings ['connection_port'] == 80 ? 'http' : 'https');
|
52 |
+
|
53 |
+
// API Settings.
|
54 |
+
$settings ['subdomain'] = trim (strval (Mage::getStoreConfig ('oneall_singlesignon/general/subdomain')));
|
55 |
+
$settings ['key'] = trim (strval (Mage::getStoreConfig ('oneall_singlesignon/general/key')));
|
56 |
+
$settings ['secret'] = trim (strval (Mage::getStoreConfig ('oneall_singlesignon/general/secret')));
|
57 |
+
|
58 |
+
// Automatic Account Creation.
|
59 |
+
$settings ['accounts_autocreate'] = (Mage::getStoreConfig ('oneall_singlesignon/accounts_create/automatic') == 0 ? false : true);
|
60 |
+
$settings ['accounts_sendmail'] = (Mage::getStoreConfig ('oneall_singlesignon/accounts_create/sendmail') == 1 ? true : false);
|
61 |
+
|
62 |
+
// Automatic Account Link.
|
63 |
+
$settings ['accounts_autolink'] = (Mage::getStoreConfig ('oneall_singlesignon/accounts_link/automatic') == 0 ? false : true);
|
64 |
+
$settings ['accounts_linkunverified'] = (Mage::getStoreConfig ('oneall_singlesignon/accounts_link/unverified') == 1 ? true : false);
|
65 |
+
|
66 |
+
// SSO Session Settings.
|
67 |
+
$settings ['session_lifetime'] = trim (strval (Mage::getStoreConfig ('oneall_singlesignon/settings/sessionlifetime')));
|
68 |
+
$settings ['session_lifetime'] = ((empty ($settings ['session_lifetime']) || $settings ['session_lifetime'] < 0) ? 86400 : $settings ['session_lifetime']);
|
69 |
+
$settings ['session_top_realm'] = trim (strval (Mage::getStoreConfig ('oneall_singlesignon/settings/sessiontoprealm')));
|
70 |
+
$settings ['session_sub_realm'] = (empty ($settings ['session_top_realm']) ? '' : trim (strval (Mage::getStoreConfig ('oneall_singlesignon/settings/sessionsubrealm'))));
|
71 |
+
|
72 |
+
// Helper Settings.
|
73 |
+
$settings ['base_url'] = ($settings ['subdomain'] . '.api.oneall.com');
|
74 |
+
$settings ['api_url'] = ($settings ['connection_protocol'] . '://' . $settings ['base_url']);
|
75 |
+
|
76 |
+
// Done
|
77 |
+
return $settings;
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Generate a random email address.
|
82 |
+
*/
|
83 |
+
protected function create_random_email ()
|
84 |
+
{
|
85 |
+
$customer = Mage::getModel ('customer/customer');
|
86 |
+
$customer->setWebsiteId (Mage::app ()->getWebsite ()->getId ());
|
87 |
+
|
88 |
+
do
|
89 |
+
{
|
90 |
+
// Create a random email.
|
91 |
+
$email = md5 (uniqid (rand (10000, 99000))) . "@example.com";
|
92 |
+
|
93 |
+
// Try to load a customer for it
|
94 |
+
$customer->loadByEmail ($email);
|
95 |
+
$customer_id = $customer->getId ();
|
96 |
+
}
|
97 |
+
while ( !empty ($customer_id) );
|
98 |
+
|
99 |
+
// Done
|
100 |
+
return $email;
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Hash a password.
|
105 |
+
*/
|
106 |
+
protected function hash_password ($password)
|
107 |
+
{
|
108 |
+
// Read settings.
|
109 |
+
$ext_settings = $this->get_settings ();
|
110 |
+
|
111 |
+
// We cannot make a connection without the subdomain.
|
112 |
+
if ( ! empty ($ext_settings ['key']) && !empty ($ext_settings ['subdomain']))
|
113 |
+
{
|
114 |
+
return sha1 ($ext_settings ['key'] . $password . $ext_settings ['subdomain']);
|
115 |
+
}
|
116 |
+
|
117 |
+
// Error
|
118 |
+
return null;
|
119 |
+
}
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Remove a Single Sign-On session for the given identity_token.
|
123 |
+
*/
|
124 |
+
public function api_remove_session_for_identity_token ($identity_token)
|
125 |
+
{
|
126 |
+
// Result container.
|
127 |
+
$status = new stdClass ();
|
128 |
+
$status->action = null;
|
129 |
+
$status->is_successfull = false;
|
130 |
+
|
131 |
+
// We need the identity_token to remove the session.
|
132 |
+
if (!empty ($identity_token))
|
133 |
+
{
|
134 |
+
// Read settings.
|
135 |
+
$ext_settings = $this->get_settings ();
|
136 |
+
|
137 |
+
// We cannot make a connection without the subdomain.
|
138 |
+
if (!empty ($ext_settings ['subdomain']))
|
139 |
+
{
|
140 |
+
// API Endpoint: http://docs.oneall.com/api/resources/sso/identity/destroy-session/
|
141 |
+
$api_resource_url = $ext_settings ['api_url'] . '/sso/sessions/identities/' . $identity_token . '.json?confirm_deletion=true';
|
142 |
+
|
143 |
+
// API Options
|
144 |
+
$api_options = array(
|
145 |
+
'api_key' => $ext_settings ['key'],
|
146 |
+
'api_secret' => $ext_settings ['secret']
|
147 |
+
);
|
148 |
+
|
149 |
+
// Delete Session.
|
150 |
+
$result = $this->do_api_request ($ext_settings ['connection_handler'], $api_resource_url, 'DELETE', $api_options);
|
151 |
+
|
152 |
+
// Check result.
|
153 |
+
if (is_object ($result) && property_exists ($result, 'http_code') && $result->http_code == 200)
|
154 |
+
{
|
155 |
+
// Success
|
156 |
+
$status->action = 'session_deleted';
|
157 |
+
$status->is_successfull = true;
|
158 |
+
|
159 |
+
// Add Log
|
160 |
+
$this->add_log ('Session for identity_token [' . $identity_token . '] deleted');
|
161 |
+
}
|
162 |
+
}
|
163 |
+
// Extension not setup
|
164 |
+
else
|
165 |
+
{
|
166 |
+
$status->action = 'extension_not_setup';
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
// Done
|
171 |
+
return $status;
|
172 |
+
}
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Remove a Single Sign-On session for the given sso_session_token.
|
176 |
+
*/
|
177 |
+
public function api_remove_session_for_sso_session_token ($sso_session_token)
|
178 |
+
{
|
179 |
+
// Result container.
|
180 |
+
$status = new stdClass ();
|
181 |
+
$status->action = null;
|
182 |
+
$status->is_successfull = false;
|
183 |
+
|
184 |
+
// We need the sso_session_token to remove the session.
|
185 |
+
if (!empty ($sso_session_token))
|
186 |
+
{
|
187 |
+
// Read settings.
|
188 |
+
$ext_settings = $this->get_settings ();
|
189 |
+
|
190 |
+
// We cannot make a connection without the subdomain.
|
191 |
+
if (!empty ($ext_settings ['subdomain']))
|
192 |
+
{
|
193 |
+
// API Endpoint: http://docs.oneall.com/api/resources/sso/delete-session/
|
194 |
+
$api_resource_url = $ext_settings ['api_url'] . '/sso/sessions/' . $sso_session_token . '.json?confirm_deletion=true';
|
195 |
+
|
196 |
+
// API Options
|
197 |
+
$api_options = array(
|
198 |
+
'api_key' => $ext_settings ['key'],
|
199 |
+
'api_secret' => $ext_settings ['secret']
|
200 |
+
);
|
201 |
+
|
202 |
+
// Delete Session.
|
203 |
+
$result = $this->do_api_request ($ext_settings ['connection_handler'], $api_resource_url, 'DELETE', $api_options);
|
204 |
+
|
205 |
+
// Check result.
|
206 |
+
if (is_object ($result) && property_exists ($result, 'http_code') && $result->http_code == 200)
|
207 |
+
{
|
208 |
+
// Success
|
209 |
+
$status->action = 'session_deleted';
|
210 |
+
$status->is_successfull = true;
|
211 |
+
|
212 |
+
// Add Log
|
213 |
+
$this->add_log ('Session for sso_session-token [' . $sso_session_token . '] deleted');
|
214 |
+
}
|
215 |
+
}
|
216 |
+
// Extension not setup
|
217 |
+
else
|
218 |
+
{
|
219 |
+
$status->action = 'extension_not_setup';
|
220 |
+
}
|
221 |
+
}
|
222 |
+
|
223 |
+
// Done
|
224 |
+
return $status;
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* Start a new Single Sign-On session for the given identity_token.
|
229 |
+
*/
|
230 |
+
public function api_start_session_for_identity_token ($identity_token)
|
231 |
+
{
|
232 |
+
// Result Container.
|
233 |
+
$status = new stdClass ();
|
234 |
+
$status->is_successfull = false;
|
235 |
+
|
236 |
+
// We need the identity_token to create a session.
|
237 |
+
if (!empty ($identity_token))
|
238 |
+
{
|
239 |
+
// Read settings.
|
240 |
+
$ext_settings = $this->get_settings ();
|
241 |
+
|
242 |
+
// We cannot make a connection without the subdomain.
|
243 |
+
if (!empty ($ext_settings ['subdomain']))
|
244 |
+
{
|
245 |
+
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
246 |
+
// Start a new Single Sign-On Session
|
247 |
+
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
248 |
+
|
249 |
+
// API Endpoint: http://docs.oneall.com/api/resources/sso/identity/start-session/
|
250 |
+
$api_resource_url = $ext_settings ['api_url'] . '/sso/sessions/identities/' . $identity_token . '.json';
|
251 |
+
|
252 |
+
// API Options.
|
253 |
+
$api_options = array(
|
254 |
+
'api_key' => $ext_settings ['key'],
|
255 |
+
'api_secret' => $ext_settings ['secret'],
|
256 |
+
'api_data' => @json_encode (array(
|
257 |
+
'request' => array(
|
258 |
+
'sso_session' => array(
|
259 |
+
'top_realm' => $ext_settings ['session_top_realm'],
|
260 |
+
'sub_realm' => $ext_settings ['session_sub_realm'],
|
261 |
+
'lifetime' => $ext_settings ['session_lifetime']
|
262 |
+
)
|
263 |
+
)
|
264 |
+
))
|
265 |
+
);
|
266 |
+
|
267 |
+
// Create Session
|
268 |
+
$result = $this->do_api_request ($ext_settings ['connection_handler'], $api_resource_url, 'PUT', $api_options);
|
269 |
+
|
270 |
+
// Check result. 201 Returned !!!
|
271 |
+
if (is_object ($result) && property_exists ($result, 'http_code') && $result->http_code == 201 && property_exists ($result, 'http_data'))
|
272 |
+
{
|
273 |
+
// Decode result
|
274 |
+
$decoded_result = @json_decode ($result->http_data);
|
275 |
+
|
276 |
+
// Check result
|
277 |
+
if (is_object ($decoded_result) && isset ($decoded_result->response->result->data->sso_session))
|
278 |
+
{
|
279 |
+
// Success
|
280 |
+
$status->action = 'session_started';
|
281 |
+
$status->sso_session_token = $decoded_result->response->result->data->sso_session->sso_session_token;
|
282 |
+
$status->is_successfull = true;
|
283 |
+
|
284 |
+
// Add Log
|
285 |
+
$this->add_log ('[START SESSION] Session [' . $status->sso_session_token . '] started for identity [' . $identity_token . ']');
|
286 |
+
}
|
287 |
+
}
|
288 |
+
}
|
289 |
+
// Extension not setup
|
290 |
+
else
|
291 |
+
{
|
292 |
+
$status->action = 'extension_not_setup';
|
293 |
+
}
|
294 |
+
}
|
295 |
+
|
296 |
+
// Done
|
297 |
+
return $status;
|
298 |
+
}
|
299 |
+
|
300 |
+
/**
|
301 |
+
* Update the given customer in the cloud storage.
|
302 |
+
*/
|
303 |
+
public function api_update_customer_cloud_storage ($user_token, $customer)
|
304 |
+
{
|
305 |
+
// Read settings
|
306 |
+
$ext_settings = $this->get_settings ();
|
307 |
+
|
308 |
+
// We cannot make a connection without a subdomain
|
309 |
+
if (!empty ($ext_settings ['subdomain']))
|
310 |
+
{
|
311 |
+
// API Endpoint: http://docs.oneall.com/api/resources/storage/users/update-user/
|
312 |
+
$api_resource_url = $ext_settings ['api_url'] . '/storage/users/' . $user_token . '.json';
|
313 |
+
|
314 |
+
// API Options
|
315 |
+
$api_options = array(
|
316 |
+
'api_key' => $ext_settings ['key'],
|
317 |
+
'api_secret' => $ext_settings ['secret'],
|
318 |
+
'api_data' => @json_encode (array(
|
319 |
+
'request' => array(
|
320 |
+
'update_mode' => 'replace',
|
321 |
+
'user' => array(
|
322 |
+
'login' => $customer->getEmail ()
|
323 |
+
)
|
324 |
+
)
|
325 |
+
))
|
326 |
+
);
|
327 |
+
|
328 |
+
// User Update
|
329 |
+
$result = $this->do_api_request ($ext_settings ['connection_handler'], $api_resource_url, 'POST', $api_options);
|
330 |
+
}
|
331 |
+
}
|
332 |
+
|
333 |
+
/**
|
334 |
+
* Update the given customer's password in this cloud storage.
|
335 |
+
*/
|
336 |
+
public function api_update_customer_cloud_password ($customer, $password)
|
337 |
+
{
|
338 |
+
// Result Container.
|
339 |
+
$status = new stdClass ();
|
340 |
+
$status->password_updated = false;
|
341 |
+
|
342 |
+
// Read settings.
|
343 |
+
$ext_settings = $this->get_settings ();
|
344 |
+
|
345 |
+
// We cannot make a connection without the subdomain.
|
346 |
+
if (!empty ($ext_settings ['subdomain']))
|
347 |
+
{
|
348 |
+
// Read customer's tokens.
|
349 |
+
$tokens = Mage::helper ('oneall_singlesignon')->get_local_storage_tokens_for_customer ($customer);
|
350 |
+
|
351 |
+
// Without a token nothing can and needs to be done.
|
352 |
+
if ($tokens->have_been_retrieved === true)
|
353 |
+
{
|
354 |
+
// API Endpoint: http://docs.oneall.com/api/resources/storage/users/update-user/
|
355 |
+
$api_resource_url = $ext_settings ['api_url'] . '/storage/users/' . $tokens->user_token . '.json';
|
356 |
+
|
357 |
+
// API Options.
|
358 |
+
$api_options = array(
|
359 |
+
'api_key' => $ext_settings ['key'],
|
360 |
+
'api_secret' => $ext_settings ['secret'],
|
361 |
+
'api_data' => @json_encode (array(
|
362 |
+
'request' => array(
|
363 |
+
'user' => array(
|
364 |
+
'password' => $this->hash_password ($password)
|
365 |
+
)
|
366 |
+
)
|
367 |
+
))
|
368 |
+
);
|
369 |
+
|
370 |
+
// Update user.
|
371 |
+
$result = $this->do_api_request ($ext_settings ['connection_handler'], $api_resource_url, 'PUT', $api_options);
|
372 |
+
|
373 |
+
// Check result.
|
374 |
+
if (is_object ($result) && property_exists ($result, 'http_code') && $result->http_code == 200)
|
375 |
+
{
|
376 |
+
// Update status.
|
377 |
+
$status->action = 'customer_cloud_storage_password_updated';
|
378 |
+
$status->password_updated = true;
|
379 |
+
|
380 |
+
// Add Log
|
381 |
+
$this->add_log ('Password for customer [' . $customer->getId () . '] updated in cloud storage');
|
382 |
+
}
|
383 |
+
}
|
384 |
+
// No cloud storage user
|
385 |
+
else
|
386 |
+
{
|
387 |
+
$status->action = 'customer_not_in_cloud_storage';
|
388 |
+
}
|
389 |
+
}
|
390 |
+
// Extension not setup
|
391 |
+
else
|
392 |
+
{
|
393 |
+
$status->action = 'extension_not_setup';
|
394 |
+
}
|
395 |
+
|
396 |
+
// Done
|
397 |
+
return $status;
|
398 |
+
}
|
399 |
+
|
400 |
+
/**
|
401 |
+
* Check if a given customer has a cloud storage account and if the given password is valid for it
|
402 |
+
*/
|
403 |
+
public function api_check_customer_cloud_password ($customer, $password)
|
404 |
+
{
|
405 |
+
// Result Container.
|
406 |
+
$status = new stdClass ();
|
407 |
+
$status->is_valid = false;
|
408 |
+
|
409 |
+
// Read settings.
|
410 |
+
$ext_settings = $this->get_settings ();
|
411 |
+
|
412 |
+
// We cannot make a connection without the subdomain.
|
413 |
+
if (!empty ($ext_settings ['subdomain']))
|
414 |
+
{
|
415 |
+
// Read customer's tokens.
|
416 |
+
$tokens = Mage::helper ('oneall_singlesignon')->get_local_storage_tokens_for_customer ($customer);
|
417 |
+
|
418 |
+
// Without a token nothing can and needs to be done.
|
419 |
+
if ($tokens->have_been_retrieved === true)
|
420 |
+
{
|
421 |
+
// API Endpoint: http://docs.oneall.com/api/resources/storage/users/lookup-user/
|
422 |
+
$api_resource_url = $ext_settings ['api_url'] . '/storage/users/user/lookup.json';
|
423 |
+
|
424 |
+
// API Options.
|
425 |
+
$api_options = array(
|
426 |
+
'api_key' => $ext_settings ['key'],
|
427 |
+
'api_secret' => $ext_settings ['secret'],
|
428 |
+
'api_data' => @json_encode (array(
|
429 |
+
'request' => array(
|
430 |
+
'user' => array(
|
431 |
+
'user_token' => $tokens->user_token,
|
432 |
+
'password' => $this->hash_password ($password),
|
433 |
+
)
|
434 |
+
)
|
435 |
+
))
|
436 |
+
);
|
437 |
+
|
438 |
+
// User Lookup.
|
439 |
+
$result = $this->do_api_request ($ext_settings ['connection_handler'], $api_resource_url, 'POST', $api_options);
|
440 |
+
|
441 |
+
// Check result
|
442 |
+
if (is_object ($result) && property_exists ($result, 'http_code') && $result->http_code == 200 && property_exists ($result, 'http_data'))
|
443 |
+
{
|
444 |
+
// Decode result.
|
445 |
+
$decoded_result = @json_decode ($result->http_data);
|
446 |
+
|
447 |
+
// Check result.
|
448 |
+
if (is_object ($decoded_result) && isset ($decoded_result->response->result->data->user))
|
449 |
+
{
|
450 |
+
$status->action = 'customer_cloud_storage_valid_password';
|
451 |
+
$status->is_valid = true;
|
452 |
+
|
453 |
+
// Add Log
|
454 |
+
$this->add_log ('Customer [' . $customer->getId () . '] has entered correct cloud storage password for user_token [' . $tokens->user_token . ']');
|
455 |
+
}
|
456 |
+
}
|
457 |
+
}
|
458 |
+
// No cloud storage user
|
459 |
+
else
|
460 |
+
{
|
461 |
+
$status->action = 'customer_not_in_cloud_storage';
|
462 |
+
|
463 |
+
// Add Log
|
464 |
+
$this->add_log ('Customer [' . $customer->getId () . '] has no cloud storage identity');
|
465 |
+
}
|
466 |
+
}
|
467 |
+
// Extension not setup
|
468 |
+
else
|
469 |
+
{
|
470 |
+
$status->action = 'extension_not_setup';
|
471 |
+
}
|
472 |
+
|
473 |
+
// Done
|
474 |
+
return $status;
|
475 |
+
}
|
476 |
+
|
477 |
+
/**
|
478 |
+
* Try to login a customer using his cloud data.
|
479 |
+
*/
|
480 |
+
public function try_customer_cloud_login ($email, $password)
|
481 |
+
{
|
482 |
+
// Result Container
|
483 |
+
$status = new stdClass ();
|
484 |
+
$status->is_successfull = false;
|
485 |
+
|
486 |
+
// Read settings.
|
487 |
+
$ext_settings = $this->get_settings ();
|
488 |
+
|
489 |
+
// We cannot make a connection without the subdomain.
|
490 |
+
if (!empty ($ext_settings ['subdomain']))
|
491 |
+
{
|
492 |
+
// Try to load customer.
|
493 |
+
$customer = Mage::getModel ('customer/customer');
|
494 |
+
$customer->setWebsiteId (Mage::app ()->getWebsite ()->getId ());
|
495 |
+
$customer->loadByEmail ($email);
|
496 |
+
$customer_id = $customer->getId ();
|
497 |
+
|
498 |
+
// Customer found.
|
499 |
+
if (!empty ($customer_id))
|
500 |
+
{
|
501 |
+
// Read tokens of this customer.
|
502 |
+
$user = Mage::getModel ('oneall_singlesignon/user')->load ($customer_id, 'customer_id');
|
503 |
+
$user_token = $user->getData ('user_token');
|
504 |
+
|
505 |
+
// This is a cloud user.
|
506 |
+
if (!empty ($user_token))
|
507 |
+
{
|
508 |
+
// API Endpoint: http://docs.oneall.com/api/resources/storage/users/lookup-user/
|
509 |
+
$api_resource_url = $ext_settings ['api_url'] . '/storage/users/user/lookup.json';
|
510 |
+
|
511 |
+
// API Options.
|
512 |
+
$api_options = array(
|
513 |
+
'api_key' => $ext_settings ['key'],
|
514 |
+
'api_secret' => $ext_settings ['secret'],
|
515 |
+
'api_data' => @json_encode (array(
|
516 |
+
'request' => array(
|
517 |
+
'user' => array(
|
518 |
+
'user_token' => $user_token,
|
519 |
+
'password' => $this->hash_password ($password)
|
520 |
+
)
|
521 |
+
)
|
522 |
+
))
|
523 |
+
);
|
524 |
+
|
525 |
+
// User Lookup.
|
526 |
+
$result = $this->do_api_request ($ext_settings ['connection_handler'], $api_resource_url, 'POST', $api_options);
|
527 |
+
|
528 |
+
// Check result
|
529 |
+
if (is_object ($result) and property_exists ($result, 'http_code'))
|
530 |
+
{
|
531 |
+
// Wrong password entered.
|
532 |
+
if ($result->http_code == 401)
|
533 |
+
{
|
534 |
+
// Add Log
|
535 |
+
$this->add_log ('Login with [' . $email . '] failed, customer [' . $customer_id . '] has entered wrong cloud password.');
|
536 |
+
}
|
537 |
+
// Correct password entered.
|
538 |
+
elseif ($result->http_code == 200)
|
539 |
+
{
|
540 |
+
// Decode result.
|
541 |
+
$decoded_result = @json_decode ($result->http_data);
|
542 |
+
|
543 |
+
// Check result.
|
544 |
+
if (is_object ($decoded_result) && isset ($decoded_result->response->result->data->user))
|
545 |
+
{
|
546 |
+
// Add Log.
|
547 |
+
$this->add_log ('Login with [' . $email . '] succeeded, customer [' . $customer_id . '] has user_token [' . $user_token . ']');
|
548 |
+
|
549 |
+
// Login.
|
550 |
+
Mage::getSingleton ('customer/session')->loginById ($customer_id);
|
551 |
+
|
552 |
+
// Success
|
553 |
+
$status->is_successfull = true;
|
554 |
+
}
|
555 |
+
}
|
556 |
+
}
|
557 |
+
}
|
558 |
+
else
|
559 |
+
{
|
560 |
+
// Add Log
|
561 |
+
$this->add_log ('Login with [' . $email . '] failed, customer [' . $customer_id . '] has no cloud identity.');
|
562 |
+
}
|
563 |
+
}
|
564 |
+
else
|
565 |
+
{
|
566 |
+
// Add Log
|
567 |
+
$this->add_log ('Login with [' . $email . '] failed, no such customer.');
|
568 |
+
}
|
569 |
+
}
|
570 |
+
|
571 |
+
// Done
|
572 |
+
return $status;
|
573 |
+
}
|
574 |
+
|
575 |
+
/**
|
576 |
+
* Add a customer to the cloud storage.
|
577 |
+
*/
|
578 |
+
public function api_add_customer_to_cloud_storage ($customer, $email = null, $password = null)
|
579 |
+
{
|
580 |
+
// Result Container
|
581 |
+
$status = new stdClass ();
|
582 |
+
$status->is_successfull = false;
|
583 |
+
$status->identity_token = null;
|
584 |
+
$status->user_token = null;
|
585 |
+
|
586 |
+
// Read settings
|
587 |
+
$ext_settings = $this->get_settings ();
|
588 |
+
|
589 |
+
// We cannot make a connection without the subdomain.
|
590 |
+
if (!empty ($ext_settings ['subdomain']))
|
591 |
+
{
|
592 |
+
// Add Log
|
593 |
+
$this->add_log ('Adding customer [' . $customer->getId () . '] to cloud storage');
|
594 |
+
|
595 |
+
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
596 |
+
// First make sure that we don't create duplicate users!
|
597 |
+
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
598 |
+
|
599 |
+
// API Endpoint: http://docs.oneall.com/api/resources/storage/users/lookup-user/
|
600 |
+
$api_resource_url = $ext_settings ['api_url'] . '/storage/users/user/lookup.json';
|
601 |
+
|
602 |
+
// API Options
|
603 |
+
$api_options = array(
|
604 |
+
'api_key' => $ext_settings ['key'],
|
605 |
+
'api_secret' => $ext_settings ['secret'],
|
606 |
+
'api_data' => @json_encode (array(
|
607 |
+
'request' => array(
|
608 |
+
'user' => array(
|
609 |
+
'login' => $customer->getEmail ()
|
610 |
+
)
|
611 |
+
)
|
612 |
+
))
|
613 |
+
);
|
614 |
+
|
615 |
+
// User Lookup
|
616 |
+
$result = $this->do_api_request ($ext_settings ['connection_handler'], $api_resource_url, 'POST', $api_options);
|
617 |
+
|
618 |
+
// Check result.
|
619 |
+
if (is_object ($result) and property_exists ($result, 'http_code') and $result->http_code == 200 and property_exists ($result, 'http_data'))
|
620 |
+
{
|
621 |
+
// Decode result.
|
622 |
+
$decoded_result = @json_decode ($result->http_data);
|
623 |
+
|
624 |
+
// Check data.
|
625 |
+
if (is_object ($decoded_result) and isset ($decoded_result->response->result->data->user))
|
626 |
+
{
|
627 |
+
// Update status.
|
628 |
+
$status->action = 'existing_user_read';
|
629 |
+
$status->is_successfull = true;
|
630 |
+
$status->user_token = $decoded_result->response->result->data->user->user_token;
|
631 |
+
$status->identity_token = $decoded_result->response->result->data->user->identity->identity_token;
|
632 |
+
|
633 |
+
// Add Log.
|
634 |
+
$this->add_log ('Email [' . $customer->getEmail () . '] found in cloud storage, user_token [' . $status->user_token . '] and identity_token [' . $status->identity_token . '] assigned');
|
635 |
+
|
636 |
+
// Done.
|
637 |
+
return $status;
|
638 |
+
}
|
639 |
+
}
|
640 |
+
|
641 |
+
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
642 |
+
// If we are getting here, then a new identity needs to be added
|
643 |
+
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
644 |
+
|
645 |
+
// Customer Name.
|
646 |
+
$customer_name = array(
|
647 |
+
'honorificPrefix' => strval ($customer->getPrefix ()),
|
648 |
+
'givenName' => strval ($customer->getFirstname ()),
|
649 |
+
'middleName' => strval ($customer->getMiddlename ()),
|
650 |
+
'familyName' => strval ($customer->getLastname ()),
|
651 |
+
'honorificSuffix' => strval ($customer->getSuffix ())
|
652 |
+
);
|
653 |
+
|
654 |
+
// Customer Email.
|
655 |
+
$customer_emails = array(
|
656 |
+
array(
|
657 |
+
'value' => $customer->getEmail (),
|
658 |
+
'is_verified' => $customer->getCustomerActivated ()
|
659 |
+
)
|
660 |
+
);
|
661 |
+
|
662 |
+
// Customer Account.
|
663 |
+
$customer_accounts = array(
|
664 |
+
array(
|
665 |
+
'domain' => Mage::getBaseUrl (),
|
666 |
+
'userid' => $customer->getId ()
|
667 |
+
)
|
668 |
+
);
|
669 |
+
|
670 |
+
// Customer Addresses.
|
671 |
+
$customer_addresses = array();
|
672 |
+
|
673 |
+
// Customer Address
|
674 |
+
foreach (array('billing', 'shipping') as $type)
|
675 |
+
{
|
676 |
+
$getter = 'getPrimary' . ucfirst (strtolower ($type)) . 'Address';
|
677 |
+
$address = $customer->$getter ();
|
678 |
+
$address_id = $address->getId ();
|
679 |
+
|
680 |
+
if (!empty ($address_id))
|
681 |
+
{
|
682 |
+
$customer_addresses [] = array(
|
683 |
+
'type' => $type,
|
684 |
+
'companyName' => strval ($address->getCompany ()),
|
685 |
+
'firstName' => strval ($address->getFirstname ()),
|
686 |
+
'middleName' => strval ($address->getMiddlename ()),
|
687 |
+
'lastName' => strval ($address->getLastname ()),
|
688 |
+
'phoneNumber' => strval ($address->getTelephone ()),
|
689 |
+
'faxNumber' => strval ($address->getFax ()),
|
690 |
+
'streetAddress' => strval ($address->getStreet (1)),
|
691 |
+
'complement' => strval ($address->getStreet (2)),
|
692 |
+
'locality' => strval ($address->getCity ()),
|
693 |
+
'region' => strval ($address->getRegion ()),
|
694 |
+
'postalCode' => strval ($address->getPostcode ()),
|
695 |
+
'code' => strval ($address->getCountry_id ())
|
696 |
+
);
|
697 |
+
}
|
698 |
+
}
|
699 |
+
|
700 |
+
// API Endpoint: http://docs.oneall.com/api/resources/storage/users/create-user/
|
701 |
+
$api_resource_url = $ext_settings ['api_url'] . '/storage/users.json';
|
702 |
+
|
703 |
+
// API Options.
|
704 |
+
$api_options = array(
|
705 |
+
'api_key' => $ext_settings ['key'],
|
706 |
+
'api_secret' => $ext_settings ['secret'],
|
707 |
+
'api_data' => @json_encode (array(
|
708 |
+
'request' => array(
|
709 |
+
'user' => array(
|
710 |
+
'login' => $customer->getEmail (),
|
711 |
+
'password' => $this->hash_password ($password),
|
712 |
+
'identity' => array(
|
713 |
+
'name' => $customer_name,
|
714 |
+
'emails' => $customer_emails,
|
715 |
+
'accounts' => $customer_accounts,
|
716 |
+
'addresses' => $customer_addresses
|
717 |
+
)
|
718 |
+
)
|
719 |
+
)
|
720 |
+
))
|
721 |
+
);
|
722 |
+
|
723 |
+
// Add User.
|
724 |
+
$result = $this->do_api_request ($ext_settings ['connection_handler'], $api_resource_url, 'POST', $api_options);
|
725 |
+
|
726 |
+
// Check result. 201 Returned !!!
|
727 |
+
if (is_object ($result) and property_exists ($result, 'http_code') and $result->http_code == 201 and property_exists ($result, 'http_data'))
|
728 |
+
{
|
729 |
+
// Decode result.
|
730 |
+
$decoded_result = @json_decode ($result->http_data);
|
731 |
+
|
732 |
+
// Check data.
|
733 |
+
if (is_object ($decoded_result) and isset ($decoded_result->response->result->data->user))
|
734 |
+
{
|
735 |
+
// Update status.
|
736 |
+
$status->action = 'new_user_created';
|
737 |
+
$status->is_successfull = true;
|
738 |
+
$status->user_token = $decoded_result->response->result->data->user->user_token;
|
739 |
+
$status->identity_token = $decoded_result->response->result->data->user->identity->identity_token;
|
740 |
+
|
741 |
+
// Add Log.
|
742 |
+
$this->add_log ('Customer [' . $customer->getId () . '] added to cloud storage, user_token [' . $status->user_token . '] and identity_token [' . $status->identity_token . '] assigned');
|
743 |
+
|
744 |
+
// Done.
|
745 |
+
return $status;
|
746 |
+
}
|
747 |
+
}
|
748 |
+
}
|
749 |
+
|
750 |
+
// Error.
|
751 |
+
return $status;
|
752 |
+
}
|
753 |
+
|
754 |
+
/**
|
755 |
+
* Remove the single sign-on session for the given customer.
|
756 |
+
*/
|
757 |
+
public function remove_session_for_customer ($customer)
|
758 |
+
{
|
759 |
+
// Result Container.
|
760 |
+
$status = new stdClass ();
|
761 |
+
$status->is_successfull = false;
|
762 |
+
|
763 |
+
// Read the session of this customer.
|
764 |
+
$session = Mage::getModel ('oneall_singlesignon/session')->load ($customer->getId (), 'customer_id');
|
765 |
+
$sso_session_token = $session->getData ('sso_session_token');
|
766 |
+
$identity_token = $session->getData ('identity_token');
|
767 |
+
|
768 |
+
// Session found.
|
769 |
+
if (!empty ($sso_session_token))
|
770 |
+
{
|
771 |
+
// Remove session from database.
|
772 |
+
$session->delete ();
|
773 |
+
|
774 |
+
// Remove session from cloud.
|
775 |
+
$remove_session = $this->api_remove_session_for_identity_token ($identity_token);
|
776 |
+
|
777 |
+
// Remove session from cloud (This one should not be necessary as already covered above)
|
778 |
+
// $remove_session = $this->api_remove_session_for_sso_session_token ($sso_session_token);
|
779 |
+
|
780 |
+
// Success.
|
781 |
+
$status->is_successfull = true;
|
782 |
+
}
|
783 |
+
|
784 |
+
// Done.
|
785 |
+
return $status;
|
786 |
+
}
|
787 |
+
|
788 |
+
/**
|
789 |
+
* Add the cloud storage tokens of a customer to the local database.
|
790 |
+
*/
|
791 |
+
public function add_local_storage_tokens_for_customer ($customer, $user_token, $identity_token)
|
792 |
+
{
|
793 |
+
// Result Container.
|
794 |
+
$status = new stdClass ();
|
795 |
+
$status->have_been_added = false;
|
796 |
+
|
797 |
+
// Verify customer object.
|
798 |
+
if (is_object ($customer) && $customer->getId ())
|
799 |
+
{
|
800 |
+
// Load customer's tokens.
|
801 |
+
$model = Mage::getModel ('oneall_singlesignon/user')->load ($customer->getId (), 'customer_id');
|
802 |
+
$customer_id = $model->getData ('customer_id');
|
803 |
+
|
804 |
+
// New Entry.
|
805 |
+
if (empty ($customer_id))
|
806 |
+
{
|
807 |
+
$model->setData ('customer_id', $customer->getId ());
|
808 |
+
$model->setData ('added_at', Mage::getSingleton('core/date')->gmtDate());
|
809 |
+
}
|
810 |
+
// Existing Entry.
|
811 |
+
else
|
812 |
+
{
|
813 |
+
$model->setData ('modified_at', Mage::getSingleton('core/date')->gmtDate());
|
814 |
+
}
|
815 |
+
|
816 |
+
// Setup Tokens.
|
817 |
+
$model->setData ('user_token', $user_token);
|
818 |
+
$model->setData ('identity_token', $identity_token);
|
819 |
+
|
820 |
+
// Save.
|
821 |
+
$model->save ();
|
822 |
+
|
823 |
+
// Update Status.
|
824 |
+
$status->identity_token = $model->getData ('identity_token');
|
825 |
+
$status->user_token = $model->getData ('user_token');
|
826 |
+
$status->have_been_added = true;
|
827 |
+
}
|
828 |
+
|
829 |
+
// Done
|
830 |
+
return $status;
|
831 |
+
}
|
832 |
+
|
833 |
+
/**
|
834 |
+
* Return the cloud storage tokens of a customer stored in the local database.
|
835 |
+
*/
|
836 |
+
public function get_local_storage_tokens_for_customer ($customer)
|
837 |
+
{
|
838 |
+
// Result Container
|
839 |
+
$status = new stdClass ();
|
840 |
+
$status->have_been_retrieved = false;
|
841 |
+
|
842 |
+
// Verify customer object
|
843 |
+
if (is_object ($customer))
|
844 |
+
{
|
845 |
+
// Load customer's tokens.
|
846 |
+
$model = Mage::getModel ('oneall_singlesignon/user')->load ($customer->getId (), 'customer_id');
|
847 |
+
$customer_id = $model->getData ('customer_id');
|
848 |
+
|
849 |
+
// Tokens found.
|
850 |
+
if (!empty ($customer_id))
|
851 |
+
{
|
852 |
+
// Update Status.
|
853 |
+
$status->identity_token = $model->getData ('identity_token');
|
854 |
+
$status->user_token = $model->getData ('user_token');
|
855 |
+
$status->have_been_retrieved = true;
|
856 |
+
}
|
857 |
+
}
|
858 |
+
|
859 |
+
// Done
|
860 |
+
return $status;
|
861 |
+
}
|
862 |
+
|
863 |
+
/**
|
864 |
+
* Open a new single sign-on session for the given customer
|
865 |
+
*/
|
866 |
+
public function create_session_for_customer ($customer, $email = null, $password = null)
|
867 |
+
{
|
868 |
+
// Result Container
|
869 |
+
$status = new stdClass ();
|
870 |
+
$status->is_successfull = false;
|
871 |
+
|
872 |
+
// Read customer's tokens.
|
873 |
+
$tokens = Mage::helper ('oneall_singlesignon')->get_local_storage_tokens_for_customer ($customer);
|
874 |
+
|
875 |
+
// Customer has no tokens yet.
|
876 |
+
if (!$tokens->have_been_retrieved)
|
877 |
+
{
|
878 |
+
// Add Log.
|
879 |
+
$this->add_log ('[CREATE SESSION] Customer [' . $customer->getId () . '] has no tokens yet. Creating tokens now.');
|
880 |
+
|
881 |
+
// Add customer to cloud storage.
|
882 |
+
$add_customer = $this->api_add_customer_to_cloud_storage ($customer, $email, $password);
|
883 |
+
|
884 |
+
// Customer added.
|
885 |
+
if ($add_customer->is_successfull === true)
|
886 |
+
{
|
887 |
+
// Update Status
|
888 |
+
$status->identity_token = $add_customer->identity_token;
|
889 |
+
$status->user_token = $add_customer->user_token;
|
890 |
+
|
891 |
+
// Add Log.
|
892 |
+
$this->add_log ('[CREATE SESSION] Tokens for customer [' . $customer->getId () . '] created: user_token ['.$status->user_token.'], identity_token ['.$status->identity_token.']');
|
893 |
+
|
894 |
+
// Add to database.
|
895 |
+
$add_tokens = Mage::helper ('oneall_singlesignon')->add_local_storage_tokens_for_customer ($customer, $status->user_token, $status->identity_token);
|
896 |
+
}
|
897 |
+
}
|
898 |
+
// Customer has already tokens.
|
899 |
+
else
|
900 |
+
{
|
901 |
+
// Update Status.
|
902 |
+
$status->identity_token = $tokens->identity_token;
|
903 |
+
$status->user_token = $tokens->user_token;
|
904 |
+
|
905 |
+
// Add Log.
|
906 |
+
$this->add_log ('[CREATE SESSION] Customer [' . $customer->getId () . '] has already tokens: user_token ['.$status->user_token.'], identity_token ['.$status->identity_token.']');
|
907 |
+
}
|
908 |
+
|
909 |
+
// Start Session
|
910 |
+
if ( ! empty ($status->identity_token))
|
911 |
+
{
|
912 |
+
// Add Log.
|
913 |
+
$this->add_log ('[CREATE SESSION] Starting session for customer [' . $customer->getId () . '] with identity_token ['.$status->identity_token.']');
|
914 |
+
|
915 |
+
// Start a new session.
|
916 |
+
$start_session = $this->api_start_session_for_identity_token ($status->identity_token);
|
917 |
+
|
918 |
+
// Session started.
|
919 |
+
if ($start_session->is_successfull === true)
|
920 |
+
{
|
921 |
+
// Update Status
|
922 |
+
$status->sso_session_token = $start_session->sso_session_token;
|
923 |
+
$status->is_successfull = true;
|
924 |
+
|
925 |
+
// Add Log.
|
926 |
+
$this->add_log ('[CREATE SESSION] Session ['.$status->sso_session_token .'] for customer [' . $customer->getId () . '] started');
|
927 |
+
|
928 |
+
// Create or update session data.
|
929 |
+
$model = Mage::getModel ('oneall_singlesignon/session')->load ($customer->getId (), 'customer_id');
|
930 |
+
$customer_id = $model->getData ('customer_id');
|
931 |
+
|
932 |
+
// New Entry.
|
933 |
+
if (empty ($customer_id))
|
934 |
+
{
|
935 |
+
$model->setData ('customer_id', $customer->getId ());
|
936 |
+
$model->setData ('added_at', Mage::getSingleton('core/date')->gmtDate());
|
937 |
+
}
|
938 |
+
// Existing Entry.
|
939 |
+
else
|
940 |
+
{
|
941 |
+
$model->setData ('modified_at', Mage::getSingleton('core/date')->gmtDate());
|
942 |
+
}
|
943 |
+
|
944 |
+
// Set Data.
|
945 |
+
$model->setData ('sso_session_token', $status->sso_session_token );
|
946 |
+
$model->setData ('identity_token', $status->identity_token);
|
947 |
+
|
948 |
+
// Create/Update.
|
949 |
+
$model->save ();
|
950 |
+
}
|
951 |
+
}
|
952 |
+
|
953 |
+
// Created session
|
954 |
+
return $status;
|
955 |
+
}
|
956 |
+
|
957 |
+
/**
|
958 |
+
* Check if a login is being made over SSO (Callback Handler).
|
959 |
+
*/
|
960 |
+
public function check_for_sso_login ()
|
961 |
+
{
|
962 |
+
// Result Container.
|
963 |
+
$status = new stdClass ();
|
964 |
+
|
965 |
+
// Read URL parameters.
|
966 |
+
$action = strtolower (trim (strval (Mage::app ()->getRequest ()->getParam ('oa_action'))));
|
967 |
+
$connection_token = Mage::app ()->getRequest ()->getParam ('connection_token');
|
968 |
+
|
969 |
+
// Callback Handler.
|
970 |
+
if ($action == 'single_sign_on' and !empty ($connection_token))
|
971 |
+
{
|
972 |
+
// Add Log
|
973 |
+
$this->add_log ('[SSO Callback] Callback for connection_token [' . $connection_token . '] detected');
|
974 |
+
|
975 |
+
// Read settings
|
976 |
+
$ext_settings = $this->get_settings ();
|
977 |
+
|
978 |
+
// We cannot make a connection without a subdomain
|
979 |
+
if (!empty ($ext_settings ['subdomain']))
|
980 |
+
{
|
981 |
+
// See: http://docs.oneall.com/api/resources/connections/read-connection-details/
|
982 |
+
$api_resource_url = $ext_settings ['api_url'] . '/connections/' . $connection_token . '.json';
|
983 |
+
|
984 |
+
// API options.
|
985 |
+
$api_options = array(
|
986 |
+
'api_key' => $ext_settings ['key'],
|
987 |
+
'api_secret' => $ext_settings ['secret']
|
988 |
+
);
|
989 |
+
|
990 |
+
// Read connection details.
|
991 |
+
$result = $this->do_api_request ($ext_settings ['connection_handler'], $api_resource_url, 'GET', $api_options);
|
992 |
+
|
993 |
+
// Check result.
|
994 |
+
if (is_object ($result) and property_exists ($result, 'http_code') and $result->http_code == 200 and property_exists ($result, 'http_data'))
|
995 |
+
{
|
996 |
+
// Decode result.
|
997 |
+
$decoded_result = @json_decode ($result->http_data);
|
998 |
+
|
999 |
+
// Check data.
|
1000 |
+
if (is_object ($decoded_result) and isset ($decoded_result->response->result->data->user))
|
1001 |
+
{
|
1002 |
+
// Extract user data.
|
1003 |
+
$data = $decoded_result->response->result->data;
|
1004 |
+
|
1005 |
+
// The user_token uniquely identifies the user.
|
1006 |
+
$user_token = $data->user->user_token;
|
1007 |
+
|
1008 |
+
// The identity_token uniquely identifies the user's data.
|
1009 |
+
$identity_token = $data->user->identity->identity_token;
|
1010 |
+
|
1011 |
+
// Add Log.
|
1012 |
+
$this->add_log ('[SSO Callback] Token user_token [' . $user_token . '] / identity_token [' . $identity_token . '] retrieved or connection_token [' . $connection_token . ']');
|
1013 |
+
|
1014 |
+
// Check if we have a customer for this user_token.
|
1015 |
+
$user = Mage::getModel ('oneall_singlesignon/user')->load ($user_token, 'user_token');
|
1016 |
+
$customer_id = $user->getData ('customer_id');
|
1017 |
+
|
1018 |
+
// Customer found.
|
1019 |
+
if (!empty ($customer_id))
|
1020 |
+
{
|
1021 |
+
// Load customer.
|
1022 |
+
$customer = Mage::getModel ('customer/customer')->load ($customer_id);
|
1023 |
+
|
1024 |
+
// Customer no longer exists.
|
1025 |
+
if (!$customer->getId ())
|
1026 |
+
{
|
1027 |
+
// Add Log.
|
1028 |
+
$this->add_log ('[SSO Callback] Removing orphan customer_id [' . $customer_id . '] for user_token [' . $user_token . ']');
|
1029 |
+
|
1030 |
+
// Cleanup our table.
|
1031 |
+
$user->delete ();
|
1032 |
+
|
1033 |
+
// Reset customer id.
|
1034 |
+
$customer_id = null;
|
1035 |
+
}
|
1036 |
+
// Customer exists.
|
1037 |
+
else
|
1038 |
+
{
|
1039 |
+
// Add Log.
|
1040 |
+
$this->add_log ('[SSO Callback] Customer [' . $customer_id . '] logged in for user_token [' . $user_token . ']');
|
1041 |
+
|
1042 |
+
// Update (This is just to make sure that the table is always correct).
|
1043 |
+
$user->setData ('identity_token', $identity_token);
|
1044 |
+
$user->save ();
|
1045 |
+
|
1046 |
+
// Login.
|
1047 |
+
Mage::getSingleton ('customer/session')->loginById ($customer_id);
|
1048 |
+
|
1049 |
+
// Update status.
|
1050 |
+
$status->action = 'existing_user_login_user_token';
|
1051 |
+
$status->user_token = $user_token;
|
1052 |
+
$status->identity_token = $identity_token;
|
1053 |
+
$status->customer = $customer;
|
1054 |
+
|
1055 |
+
// Done.
|
1056 |
+
return $status;
|
1057 |
+
}
|
1058 |
+
}
|
1059 |
+
|
1060 |
+
// Add Log.
|
1061 |
+
$this->add_log ('[SSO Callback] No customer found for user_token [' . $user_token . ']. Trying email lookup.');
|
1062 |
+
|
1063 |
+
// Retrieve email from identity.
|
1064 |
+
if (isset ($data->user->identity->emails) && is_array ($data->user->identity->emails) && count ($data->user->identity->emails) > 0)
|
1065 |
+
{
|
1066 |
+
// Email Details.
|
1067 |
+
$email = $data->user->identity->emails [0]->value;
|
1068 |
+
$email_verified = $data->user->identity->emails [0]->is_verified;
|
1069 |
+
|
1070 |
+
// Try to load customer.
|
1071 |
+
$customer = Mage::getModel ('customer/customer');
|
1072 |
+
$customer->setWebsiteId (Mage::app ()->getWebsite ()->getId ());
|
1073 |
+
$customer->loadByEmail ($email);
|
1074 |
+
$customer_id = $customer->getId ();
|
1075 |
+
|
1076 |
+
// Customer identifier found.
|
1077 |
+
if (!empty ($customer_id))
|
1078 |
+
{
|
1079 |
+
// Add Log.
|
1080 |
+
$this->add_log ('[SSO Callback] Customer [' . $customer_id . '] found for email [' . $email . ']');
|
1081 |
+
|
1082 |
+
// Automatic Link is disabled.
|
1083 |
+
if ($ext_settings ['accounts_autolink'] == false)
|
1084 |
+
{
|
1085 |
+
// Add Log.
|
1086 |
+
$this->add_log ('[SSO Callback] Autolink disabled. Cannot link user_token [' . $user_token . '] to customer [' . $customer_id . ']');
|
1087 |
+
|
1088 |
+
// Update Status.
|
1089 |
+
$status->action = 'existing_user_no_login_autolink_off';
|
1090 |
+
$status->customer = $customer;
|
1091 |
+
}
|
1092 |
+
// Automatic Link is enabled.
|
1093 |
+
else
|
1094 |
+
{
|
1095 |
+
// The email has been verified.
|
1096 |
+
if ($email_verified)
|
1097 |
+
{
|
1098 |
+
// Add Log.
|
1099 |
+
$this->add_log ('[SSO Callback] [Verified] Autolink enabled/Email verified. Linking user_token [' . $user_token . '] to customer [' . $customer_id . ']');
|
1100 |
+
|
1101 |
+
// Add to database.
|
1102 |
+
$add_tokens = Mage::helper ('oneall_singlesignon')->add_local_storage_tokens_for_customer ($customer, $user_token, $identity_token);
|
1103 |
+
|
1104 |
+
// Login.
|
1105 |
+
Mage::getSingleton ('customer/session')->loginById ($customer_id);
|
1106 |
+
|
1107 |
+
// Update Status.
|
1108 |
+
$status->action = 'existing_user_login_email_verified';
|
1109 |
+
$status->user_token = $user_token;
|
1110 |
+
$status->identity_token = $identity_token;
|
1111 |
+
$status->customer = $customer;
|
1112 |
+
}
|
1113 |
+
// The email has NOT been verified.
|
1114 |
+
else
|
1115 |
+
{
|
1116 |
+
// We can use unverified emails.
|
1117 |
+
if ($ext_settings ['accounts_linkunverified'] == true)
|
1118 |
+
{
|
1119 |
+
// Add Log.
|
1120 |
+
$this->add_log ('[SSO Callback] [Unverified] Autolink enabled/Unverified email allowed. Linking user_token [' . $user_token . '] to customer [' . $customer_id . ']');
|
1121 |
+
|
1122 |
+
// Add to database.
|
1123 |
+
$add_tokens = Mage::helper ('oneall_singlesignon')->add_local_storage_tokens_for_customer ($customer, $user_token, $identity_token);
|
1124 |
+
|
1125 |
+
// Login.
|
1126 |
+
Mage::getSingleton ('customer/session')->loginById ($customer_id);
|
1127 |
+
|
1128 |
+
// Update Status.
|
1129 |
+
$status->action = 'existing_user_login_email_unverified';
|
1130 |
+
$status->user_token = $user_token;
|
1131 |
+
$status->identity_token = $identity_token;
|
1132 |
+
$status->customer = $customer;
|
1133 |
+
}
|
1134 |
+
// We cannot use unverified emails.
|
1135 |
+
else
|
1136 |
+
{
|
1137 |
+
// Add Log.
|
1138 |
+
$this->add_log ('[SSO Callback] [Unverified] Autolink enabled/Unverified email not allowed. Cannot link user_token [' . $user_token . '] to customer [' . $customer_id . ']');
|
1139 |
+
|
1140 |
+
// Update Status.
|
1141 |
+
$status->action = 'existing_user_no_login_autolink_off_unverified_emails';
|
1142 |
+
$status->user_token = $user_token;
|
1143 |
+
$status->identity_token = $identity_token;
|
1144 |
+
$status->customer = $customer;
|
1145 |
+
}
|
1146 |
+
}
|
1147 |
+
}
|
1148 |
+
|
1149 |
+
// Done
|
1150 |
+
return $status;
|
1151 |
+
}
|
1152 |
+
// No customer found
|
1153 |
+
else
|
1154 |
+
{
|
1155 |
+
// Add Log
|
1156 |
+
$this->add_log ('[SSO Callback] No customer found for email [' . $email . ']');
|
1157 |
+
}
|
1158 |
+
}
|
1159 |
+
else
|
1160 |
+
{
|
1161 |
+
// Create Random email.
|
1162 |
+
$email = $this->create_random_email ();
|
1163 |
+
$email_is_random = true;
|
1164 |
+
|
1165 |
+
// Add Log.
|
1166 |
+
$this->add_log ('[SSO Callback] Email lookup failed, identity provides no email address. Random address ['.$email.'] generated.');
|
1167 |
+
}
|
1168 |
+
|
1169 |
+
// /////////////////////////////////////////////////////////////////////////
|
1170 |
+
// This is a new user
|
1171 |
+
// /////////////////////////////////////////////////////////////////////////
|
1172 |
+
|
1173 |
+
// We cannot create new accounts
|
1174 |
+
if ($ext_settings ['accounts_autocreate'] === false)
|
1175 |
+
{
|
1176 |
+
// Add Log
|
1177 |
+
$this->add_log ('[SSO Callback] New user, but account creation disabled. Cannot create customer for user_token [' . $user_token . ']');
|
1178 |
+
|
1179 |
+
// Update Status
|
1180 |
+
$status->action = 'new_user_no_login_autocreate_off';
|
1181 |
+
|
1182 |
+
// Done
|
1183 |
+
return $status;
|
1184 |
+
}
|
1185 |
+
else
|
1186 |
+
{
|
1187 |
+
// Add Log
|
1188 |
+
$this->add_log ('[SSO Callback] New user, account creation enabled. Creating customer for user_token [' . $user_token . ']');
|
1189 |
+
}
|
1190 |
+
|
1191 |
+
// Create a new customer.
|
1192 |
+
$customer = Mage::getModel ('customer/customer');
|
1193 |
+
|
1194 |
+
// Generate a password for the customer.
|
1195 |
+
$password = $customer->generatePassword (8);
|
1196 |
+
|
1197 |
+
// First Name
|
1198 |
+
$first_name = 'unknown';
|
1199 |
+
if (!empty ($data->user->identity->name->givenName))
|
1200 |
+
{
|
1201 |
+
$first_name = $data->user->identity->name->givenName;
|
1202 |
+
}
|
1203 |
+
else if (!empty ($data->user->identity->displayName))
|
1204 |
+
{
|
1205 |
+
$names = explode (' ', $data->user->identity->displayName);
|
1206 |
+
$first_name = $names [0];
|
1207 |
+
}
|
1208 |
+
else if (!empty ($data->user->identity->name->formatted))
|
1209 |
+
{
|
1210 |
+
$names = explode (' ', $data->user->identity->name->formatted);
|
1211 |
+
$first_name = $names [0];
|
1212 |
+
}
|
1213 |
+
|
1214 |
+
// Last Name
|
1215 |
+
$last_name = 'unknown';
|
1216 |
+
if (!empty ($data->user->identity->name->familyName))
|
1217 |
+
{
|
1218 |
+
$last_name = $data->user->identity->name->familyName;
|
1219 |
+
}
|
1220 |
+
else if (!empty ($data->user->identity->displayName))
|
1221 |
+
{
|
1222 |
+
$names = explode (' ', $data->user->identity->displayName);
|
1223 |
+
if (!empty ($names [1]))
|
1224 |
+
{
|
1225 |
+
$last_name = $names [1];
|
1226 |
+
}
|
1227 |
+
}
|
1228 |
+
else if (!empty ($data->user->identity->name->formatted))
|
1229 |
+
{
|
1230 |
+
$names = explode (' ', $data->user->identity->name->formatted);
|
1231 |
+
if (!empty ($names [1]))
|
1232 |
+
{
|
1233 |
+
$last_name = $names [1];
|
1234 |
+
}
|
1235 |
+
}
|
1236 |
+
|
1237 |
+
// Customer Details.
|
1238 |
+
$customer->setFirstname ($first_name);
|
1239 |
+
$customer->setLastname ($last_name);
|
1240 |
+
$customer->setEmail ($email);
|
1241 |
+
$customer->setPassword ($password);
|
1242 |
+
$customer->setPasswordConfirmation ($password);
|
1243 |
+
|
1244 |
+
// Validate user details.
|
1245 |
+
$errors = $customer->validate ();
|
1246 |
+
|
1247 |
+
// Do we have any errors?
|
1248 |
+
if (is_array ($errors) && count ($errors) > 0)
|
1249 |
+
{
|
1250 |
+
// Display Errors
|
1251 |
+
Mage::getSingleton ('core/session')->addError (implode (' ', $errors));
|
1252 |
+
|
1253 |
+
// Done
|
1254 |
+
return 'new_user_errors';
|
1255 |
+
}
|
1256 |
+
|
1257 |
+
// Save user.
|
1258 |
+
$customer->save ();
|
1259 |
+
|
1260 |
+
// Confirm (The two saves are necessary).
|
1261 |
+
$customer->setConfirmation (null);
|
1262 |
+
$customer->save ();
|
1263 |
+
|
1264 |
+
// Add log.
|
1265 |
+
$this->add_log ('[SSO Callback] New user, customer [' . $customer->getId () . '] created for user_token [' . $user_token . ']');
|
1266 |
+
|
1267 |
+
// Do we have any addresses?
|
1268 |
+
if (isset ($data->user->identity->addresses) && is_array ($data->user->identity->addresses))
|
1269 |
+
{
|
1270 |
+
foreach ($data->user->identity->addresses as $address)
|
1271 |
+
{
|
1272 |
+
if (isset ($address->type) && in_array ($address->type, array('billing', 'shipping')))
|
1273 |
+
{
|
1274 |
+
try
|
1275 |
+
{
|
1276 |
+
// Address Data.
|
1277 |
+
$address_data = array(
|
1278 |
+
'company' => (isset ($address->companyName) ? $address->companyName : null),
|
1279 |
+
'firstname' => (isset ($address->firstName) ? $address->firstName : $customer->getFirstname ()),
|
1280 |
+
'middlename' => (isset ($address->middleName) ? $address->middleName : $customer->getMiddlename ()),
|
1281 |
+
'lastname' => (isset ($address->lastName) ? $address->lastName : $customer->getLastname ()),
|
1282 |
+
'telephone' => (isset ($address->phoneNumber) ? $address->phoneNumber : null),
|
1283 |
+
'fax' => (isset ($address->faxNumber) ? $address->faxNumber : null),
|
1284 |
+
'street' => array(
|
1285 |
+
'0' => (isset ($address->streetAddress) ? $address->streetAddress : null),
|
1286 |
+
'1' => (isset ($address->complement) ? $address->complement : null)
|
1287 |
+
),
|
1288 |
+
'city' => (isset ($address->locality) ? $address->locality : null),
|
1289 |
+
'region' => (isset ($address->region) ? $address->region : null),
|
1290 |
+
'postcode' => (isset ($address->postalCode) ? $address->postalCode : null),
|
1291 |
+
'country_id' => (isset ($address->code) ? $address->code : null)
|
1292 |
+
);
|
1293 |
+
|
1294 |
+
// Add for customer.
|
1295 |
+
$customer_address = Mage::getModel ('customer/address');
|
1296 |
+
$customer_address->setData ($address_data);
|
1297 |
+
$customer_address->setCustomerId ($customer->getId ());
|
1298 |
+
|
1299 |
+
if ($address->type == 'billing')
|
1300 |
+
{
|
1301 |
+
$customer_address->setIsDefaultBilling (1);
|
1302 |
+
}
|
1303 |
+
else
|
1304 |
+
{
|
1305 |
+
$customer_address->setIsDefaultShipping (1);
|
1306 |
+
}
|
1307 |
+
|
1308 |
+
$customer_address->setSaveInAddressBook (1);
|
1309 |
+
$customer_address->save ();
|
1310 |
+
|
1311 |
+
// Add Log.
|
1312 |
+
$this->add_log ('[SSO Callback] ' . ucfirst ($address->type) . ' address [' . $customer_address->getId () . '] added for customer [' . $customer->getId () . ']');
|
1313 |
+
}
|
1314 |
+
catch (Exception $e)
|
1315 |
+
{
|
1316 |
+
}
|
1317 |
+
}
|
1318 |
+
}
|
1319 |
+
}
|
1320 |
+
|
1321 |
+
// Send registration email?
|
1322 |
+
if ($ext_settings ['accounts_sendmail'])
|
1323 |
+
{
|
1324 |
+
// We cannot send emails to random email addresses.
|
1325 |
+
if (!$email_is_random)
|
1326 |
+
{
|
1327 |
+
// Send Email.
|
1328 |
+
$customer->sendNewAccountEmail ('registered');
|
1329 |
+
|
1330 |
+
// Add log.
|
1331 |
+
$this->add_log ('[SSO Callback] New user, registration email send to customer [' . $customer->getId () . ']');
|
1332 |
+
}
|
1333 |
+
}
|
1334 |
+
|
1335 |
+
// Add customer tokens to database.
|
1336 |
+
$add_tokens = Mage::helper ('oneall_singlesignon')->add_local_storage_tokens_for_customer ($customer, $user_token, $identity_token);
|
1337 |
+
|
1338 |
+
// Login customer.
|
1339 |
+
Mage::getSingleton ('customer/session')->loginById ($customer->getId ());
|
1340 |
+
|
1341 |
+
// Update status.
|
1342 |
+
$status->action = 'new_user_login';
|
1343 |
+
$status->identity_token = $identity_token;
|
1344 |
+
$status->customer = $customer;
|
1345 |
+
|
1346 |
+
// Done.
|
1347 |
+
return $status;
|
1348 |
+
}
|
1349 |
+
}
|
1350 |
+
}
|
1351 |
+
}
|
1352 |
+
|
1353 |
+
// Update status.
|
1354 |
+
$status->action = 'no_callback_data_received';
|
1355 |
+
|
1356 |
+
// Done.
|
1357 |
+
return $status;
|
1358 |
+
}
|
1359 |
+
|
1360 |
+
/**
|
1361 |
+
* Return the list of disabled PHP functions.
|
1362 |
+
*/
|
1363 |
+
public function get_disabled_php_functions ()
|
1364 |
+
{
|
1365 |
+
$disabled_functions = trim (ini_get ('disable_functions'));
|
1366 |
+
if (strlen ($disabled_functions) == 0)
|
1367 |
+
{
|
1368 |
+
$disabled_functions = array();
|
1369 |
+
}
|
1370 |
+
else
|
1371 |
+
{
|
1372 |
+
$disabled_functions = explode (',', $disabled_functions);
|
1373 |
+
$disabled_functions = array_map ('trim', $disabled_functions);
|
1374 |
+
}
|
1375 |
+
return $disabled_functions;
|
1376 |
+
}
|
1377 |
+
|
1378 |
+
/**
|
1379 |
+
* Send an API request by using the given handler
|
1380 |
+
*/
|
1381 |
+
public function do_api_request ($handler, $url, $method = 'GET', $options = array(), $timeout = 25)
|
1382 |
+
{
|
1383 |
+
// FSOCKOPEN
|
1384 |
+
if ($handler == 'fsockopen')
|
1385 |
+
{
|
1386 |
+
return $this->do_fsockopen_request ($url, $method, $options, $timeout);
|
1387 |
+
}
|
1388 |
+
// CURL
|
1389 |
+
else
|
1390 |
+
{
|
1391 |
+
return $this->do_curl_request ($url, $method, $options, $timeout);
|
1392 |
+
}
|
1393 |
+
}
|
1394 |
+
|
1395 |
+
/**
|
1396 |
+
* Check if fsockopen is available.
|
1397 |
+
*/
|
1398 |
+
public function is_fsockopen_available ()
|
1399 |
+
{
|
1400 |
+
// Make sure fsockopen has been loaded
|
1401 |
+
if (function_exists ('fsockopen') and function_exists ('fwrite'))
|
1402 |
+
{
|
1403 |
+
// Read the disabled functions
|
1404 |
+
$disabled_functions = $this->get_disabled_php_functions ();
|
1405 |
+
|
1406 |
+
// Make sure fsockopen has not been disabled
|
1407 |
+
if (!in_array ('fsockopen', $disabled_functions) and !in_array ('fwrite', $disabled_functions))
|
1408 |
+
{
|
1409 |
+
// Loaded and enabled
|
1410 |
+
return true;
|
1411 |
+
}
|
1412 |
+
}
|
1413 |
+
|
1414 |
+
// Not loaded or disabled
|
1415 |
+
return false;
|
1416 |
+
}
|
1417 |
+
|
1418 |
+
/**
|
1419 |
+
* Check if fsockopen is enabled and can be used to connect to OneAll.
|
1420 |
+
*/
|
1421 |
+
public function is_api_connection_fsockopen_ok ($secure = true)
|
1422 |
+
{
|
1423 |
+
if ($this->is_fsockopen_available ())
|
1424 |
+
{
|
1425 |
+
$result = $this->do_fsockopen_request (($secure ? 'https' : 'http') . '://www.oneall.com/ping.html');
|
1426 |
+
if (is_object ($result) and property_exists ($result, 'http_code') and $result->http_code == 200)
|
1427 |
+
{
|
1428 |
+
if (property_exists ($result, 'http_data'))
|
1429 |
+
{
|
1430 |
+
if (strtolower ($result->http_data) == 'ok')
|
1431 |
+
{
|
1432 |
+
return true;
|
1433 |
+
}
|
1434 |
+
}
|
1435 |
+
}
|
1436 |
+
}
|
1437 |
+
return false;
|
1438 |
+
}
|
1439 |
+
|
1440 |
+
/**
|
1441 |
+
* Send an fsockopen request.
|
1442 |
+
*/
|
1443 |
+
public function do_fsockopen_request ($url, $method = 'GET', $options = array(), $timeout = 15)
|
1444 |
+
{
|
1445 |
+
// Store the result
|
1446 |
+
$result = new stdClass ();
|
1447 |
+
|
1448 |
+
// Make sure that this is a valid URL
|
1449 |
+
if (($uri = parse_url ($url)) == false)
|
1450 |
+
{
|
1451 |
+
$result->http_code = -1;
|
1452 |
+
$result->http_data = null;
|
1453 |
+
$result->http_error = 'invalid_uri';
|
1454 |
+
return $result;
|
1455 |
+
}
|
1456 |
+
|
1457 |
+
// Make sure that we can handle the scheme
|
1458 |
+
switch ($uri ['scheme'])
|
1459 |
+
{
|
1460 |
+
case 'http' :
|
1461 |
+
$port = (isset ($uri ['port']) ? $uri ['port'] : 80);
|
1462 |
+
$host = ($uri ['host'] . ($port != 80 ? ':' . $port : ''));
|
1463 |
+
$fp = @fsockopen ($uri ['host'], $port, $errno, $errstr, $timeout);
|
1464 |
+
break;
|
1465 |
+
|
1466 |
+
case 'https' :
|
1467 |
+
$port = (isset ($uri ['port']) ? $uri ['port'] : 443);
|
1468 |
+
$host = ($uri ['host'] . ($port != 443 ? ':' . $port : ''));
|
1469 |
+
$fp = @fsockopen ('ssl://' . $uri ['host'], $port, $errno, $errstr, $timeout);
|
1470 |
+
break;
|
1471 |
+
|
1472 |
+
default :
|
1473 |
+
$result->http_code = -1;
|
1474 |
+
$result->http_data = null;
|
1475 |
+
$result->http_error = 'invalid_schema';
|
1476 |
+
return $result;
|
1477 |
+
break;
|
1478 |
+
}
|
1479 |
+
|
1480 |
+
// Make sure that the socket has been opened properly
|
1481 |
+
if (!$fp)
|
1482 |
+
{
|
1483 |
+
$result->http_code = -$errno;
|
1484 |
+
$result->http_data = null;
|
1485 |
+
$result->http_error = trim ($errstr);
|
1486 |
+
return $result;
|
1487 |
+
}
|
1488 |
+
|
1489 |
+
// Construct the path to act on
|
1490 |
+
$path = (isset ($uri ['path']) ? $uri ['path'] : '/');
|
1491 |
+
if (isset ($uri ['query']))
|
1492 |
+
{
|
1493 |
+
$path .= '?' . $uri ['query'];
|
1494 |
+
}
|
1495 |
+
|
1496 |
+
// Send request headers.
|
1497 |
+
fwrite ($fp, strtoupper ($method) . " " . $path . " HTTP/1.1\r\n");
|
1498 |
+
fwrite ($fp, "Host: " . $host . "\r\n");
|
1499 |
+
fwrite ($fp, "User-Agent: " . self::USER_AGENT . "\r\n");
|
1500 |
+
|
1501 |
+
// Add POST data ?
|
1502 |
+
if (isset ($options ['api_data']) && ! empty ($options ['api_data']))
|
1503 |
+
{
|
1504 |
+
fwrite($fp, "Content-length: ". strlen($options ['api_data']) ."\r\n");
|
1505 |
+
}
|
1506 |
+
|
1507 |
+
// Enable basic authentication?
|
1508 |
+
if (isset ($options ['api_key']) && isset ($options ['api_secret']))
|
1509 |
+
{
|
1510 |
+
fwrite ($fp, "Authorization: Basic " . base64_encode ($options ['api_key'] . ":" . $options ['api_secret'])."\r\n");
|
1511 |
+
}
|
1512 |
+
|
1513 |
+
// Close request.
|
1514 |
+
fwrite ($fp, "Connection: close\r\n\r\n");
|
1515 |
+
|
1516 |
+
// Add POST data ?
|
1517 |
+
if (isset ($options ['api_data']))
|
1518 |
+
{
|
1519 |
+
fwrite ($fp, $options ['api_data']);
|
1520 |
+
}
|
1521 |
+
|
1522 |
+
// Fetch response
|
1523 |
+
$response = '';
|
1524 |
+
while ( !feof ($fp) )
|
1525 |
+
{
|
1526 |
+
$response .= fread ($fp, 1024);
|
1527 |
+
}
|
1528 |
+
|
1529 |
+
// Close connection
|
1530 |
+
fclose ($fp);
|
1531 |
+
|
1532 |
+
// Parse response
|
1533 |
+
list ($response_header, $response_body) = explode ("\r\n\r\n", $response, 2);
|
1534 |
+
|
1535 |
+
// Parse header
|
1536 |
+
$response_header = preg_split ("/\r\n|\n|\r/", $response_header);
|
1537 |
+
list ($header_protocol, $header_code, $header_status_message) = explode (' ', trim (array_shift ($response_header)), 3);
|
1538 |
+
|
1539 |
+
// Build result
|
1540 |
+
$result->http_code = $header_code;
|
1541 |
+
$result->http_data = $response_body;
|
1542 |
+
|
1543 |
+
// Done
|
1544 |
+
return $result;
|
1545 |
+
}
|
1546 |
+
|
1547 |
+
/**
|
1548 |
+
* Check if CURL has been loaded and is not disabled.
|
1549 |
+
*/
|
1550 |
+
public function is_curl_available ()
|
1551 |
+
{
|
1552 |
+
// Make sure CURL has been loaded.
|
1553 |
+
if (in_array ('curl', get_loaded_extensions ()) and function_exists ('curl_init') and function_exists ('curl_exec'))
|
1554 |
+
{
|
1555 |
+
// Read the disabled functions.
|
1556 |
+
$disabled_functions = $this->get_disabled_php_functions ();
|
1557 |
+
|
1558 |
+
// Make sure CURL has not been disabled.
|
1559 |
+
if (!in_array ('curl_init', $disabled_functions) and !in_array ('curl_exec', $disabled_functions))
|
1560 |
+
{
|
1561 |
+
// Loaded and enabled.
|
1562 |
+
return true;
|
1563 |
+
}
|
1564 |
+
}
|
1565 |
+
|
1566 |
+
// Not loaded or disabled.
|
1567 |
+
return false;
|
1568 |
+
}
|
1569 |
+
|
1570 |
+
/**
|
1571 |
+
* Check if CURL is available and can be used to connect to OneAll
|
1572 |
+
*/
|
1573 |
+
public function is_api_connection_curl_ok ($secure = true)
|
1574 |
+
{
|
1575 |
+
// Is CURL available and enabled?
|
1576 |
+
if ($this->is_curl_available ())
|
1577 |
+
{
|
1578 |
+
// Make a request to the OneAll API.
|
1579 |
+
$result = $this->do_curl_request (($secure ? 'https' : 'http') . '://www.oneall.com/ping.html');
|
1580 |
+
if (is_object ($result) and property_exists ($result, 'http_code') and $result->http_code == 200)
|
1581 |
+
{
|
1582 |
+
if (property_exists ($result, 'http_data'))
|
1583 |
+
{
|
1584 |
+
if (strtolower ($result->http_data) == 'ok')
|
1585 |
+
{
|
1586 |
+
return true;
|
1587 |
+
}
|
1588 |
+
}
|
1589 |
+
}
|
1590 |
+
}
|
1591 |
+
return false;
|
1592 |
+
}
|
1593 |
+
|
1594 |
+
/**
|
1595 |
+
* Send a CURL request.
|
1596 |
+
*/
|
1597 |
+
public function do_curl_request ($url, $method = 'GET', $options = array(), $timeout = 15)
|
1598 |
+
{
|
1599 |
+
// Store the result
|
1600 |
+
$result = new stdClass ();
|
1601 |
+
|
1602 |
+
// Send request
|
1603 |
+
$curl = curl_init ();
|
1604 |
+
curl_setopt ($curl, CURLOPT_URL, $url);
|
1605 |
+
curl_setopt ($curl, CURLOPT_HEADER, 0);
|
1606 |
+
curl_setopt ($curl, CURLOPT_TIMEOUT, $timeout);
|
1607 |
+
curl_setopt ($curl, CURLOPT_VERBOSE, 0);
|
1608 |
+
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
|
1609 |
+
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
1610 |
+
curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);
|
1611 |
+
curl_setopt ($curl, CURLOPT_USERAGENT, self::USER_AGENT);
|
1612 |
+
|
1613 |
+
// HTTP Method
|
1614 |
+
switch (strtoupper ($method))
|
1615 |
+
{
|
1616 |
+
case 'DELETE' :
|
1617 |
+
curl_setopt ($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
|
1618 |
+
break;
|
1619 |
+
|
1620 |
+
case 'PUT' :
|
1621 |
+
curl_setopt ($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
|
1622 |
+
break;
|
1623 |
+
|
1624 |
+
case 'POST' :
|
1625 |
+
curl_setopt ($curl, CURLOPT_POST, 1);
|
1626 |
+
break;
|
1627 |
+
|
1628 |
+
default :
|
1629 |
+
curl_setopt ($curl, CURLOPT_HTTPGET, 1);
|
1630 |
+
break;
|
1631 |
+
}
|
1632 |
+
|
1633 |
+
// HTTP AUTH
|
1634 |
+
if (isset ($options ['api_key']) and isset ($options ['api_secret']))
|
1635 |
+
{
|
1636 |
+
curl_setopt ($curl, CURLOPT_USERPWD, $options ['api_key'] . ":" . $options ['api_secret']);
|
1637 |
+
}
|
1638 |
+
|
1639 |
+
// POST Data
|
1640 |
+
if (isset ($options ['api_data']))
|
1641 |
+
{
|
1642 |
+
curl_setopt ($curl, CURLOPT_POSTFIELDS, $options ['api_data']);
|
1643 |
+
}
|
1644 |
+
|
1645 |
+
// Make request
|
1646 |
+
if (($http_data = curl_exec ($curl)) !== false)
|
1647 |
+
{
|
1648 |
+
$result->http_code = curl_getinfo ($curl, CURLINFO_HTTP_CODE);
|
1649 |
+
$result->http_data = $http_data;
|
1650 |
+
$result->http_error = null;
|
1651 |
+
}
|
1652 |
+
else
|
1653 |
+
{
|
1654 |
+
$result->http_code = -1;
|
1655 |
+
$result->http_data = null;
|
1656 |
+
$result->http_error = curl_error ($curl);
|
1657 |
+
}
|
1658 |
+
|
1659 |
+
// Done
|
1660 |
+
return $result;
|
1661 |
+
}
|
1662 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/Apiautodetect.php
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// Autodetects the API connection Handler
|
27 |
+
class OneAll_SingleSignOn_Model_Apiautodetect
|
28 |
+
{
|
29 |
+
public function toOptionArray ()
|
30 |
+
{
|
31 |
+
$helper = Mage::helper ('oneall_singlesignon');
|
32 |
+
}
|
33 |
+
|
34 |
+
public function getCommentText ()
|
35 |
+
{
|
36 |
+
$base_url = Mage::getBaseUrl ();
|
37 |
+
|
38 |
+
return <<<HTML
|
39 |
+
|
40 |
+
<script language="javascript">
|
41 |
+
|
42 |
+
var button = document.getElementById("oneall_singlesignon_connection_autodetect");
|
43 |
+
button.value = "Autodetect API Connection";
|
44 |
+
button.onclick = function ()
|
45 |
+
{
|
46 |
+
autodetect_api_connection();
|
47 |
+
}
|
48 |
+
|
49 |
+
var autodetect_api_connection = function ()
|
50 |
+
{
|
51 |
+
var div = document.getElementById('oneall_singlesignon_api_test_result');
|
52 |
+
div.innerHTML = 'Loading ...';
|
53 |
+
autodetect_ajax('{$base_url}oneall_singlesignon_ajax/ajax', autodetect_complete);
|
54 |
+
}
|
55 |
+
|
56 |
+
var autodetect_ajax = function (url, callback_function)
|
57 |
+
{
|
58 |
+
var request = new XMLHttpRequest();
|
59 |
+
|
60 |
+
request.open("GET", url, true);
|
61 |
+
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
62 |
+
request.onreadystatechange = function()
|
63 |
+
{
|
64 |
+
if (request.readyState == 4 && request.status == 200)
|
65 |
+
{
|
66 |
+
if (request.responseText)
|
67 |
+
{
|
68 |
+
callback_function(request.responseText);
|
69 |
+
}
|
70 |
+
}
|
71 |
+
};
|
72 |
+
request.send();
|
73 |
+
}
|
74 |
+
|
75 |
+
var autodetect_complete = function (text)
|
76 |
+
{
|
77 |
+
var is_success,result_container, e, handler, port;
|
78 |
+
|
79 |
+
result_container = document.getElementById('oneall_singlesignon_api_test_result');
|
80 |
+
|
81 |
+
handler = document.getElementById('oneall_singlesignon_connection_handler');
|
82 |
+
handler.value = '';
|
83 |
+
|
84 |
+
port = document.getElementById('oneall_singlesignon_connection_port');
|
85 |
+
port.value = '';
|
86 |
+
|
87 |
+
/* CURL detected, HTTPS */
|
88 |
+
if (text == 'success_autodetect_api_curl_https')
|
89 |
+
{
|
90 |
+
is_success = true;
|
91 |
+
result_container.innerHTML = '<strong style="color:#3d6611">Detected CURL on port 443/HTTPS</strong>';
|
92 |
+
handler.value = 'curl';
|
93 |
+
port.value = '443';
|
94 |
+
}
|
95 |
+
/* CURL detected, HTTP */
|
96 |
+
else if (text == 'success_autodetect_api_curl_http')
|
97 |
+
{
|
98 |
+
is_success = true;
|
99 |
+
result_container.innerHTML = '<strong style="color:#3d6611">Detected CURL on port 80/HTTP</strong>';
|
100 |
+
handler.value = 'curl';
|
101 |
+
port.value = '80';
|
102 |
+
}
|
103 |
+
/* CURL detected, ports closed */
|
104 |
+
else if (text == 'error_autodetect_api_curl_ports_blocked')
|
105 |
+
{
|
106 |
+
is_success = false;
|
107 |
+
result_container.innerHTML = '<strong style="color:#eb5e00">Detected CURL but both ports 80/443 are blocked</strong>';
|
108 |
+
handler.value = 'curl'
|
109 |
+
}
|
110 |
+
/* FSOCKOPEN detected, HTTPS */
|
111 |
+
else if (text == 'success_autodetect_api_fsockopen_https')
|
112 |
+
{
|
113 |
+
is_success = true;
|
114 |
+
result_container.innerHTML = '<strong style="color:#3d6611">Detected FSOCKOPEN on port 443/HTTPS</strong>';
|
115 |
+
handler.value = 'fsockopen';
|
116 |
+
port.value = '80';
|
117 |
+
}
|
118 |
+
/* FSOCKOPEN detected, HTTP */
|
119 |
+
else if (text == 'success_autodetect_api_fsockopen_http')
|
120 |
+
{
|
121 |
+
is_success = true;
|
122 |
+
result_container.innerHTML = '<strong style="color:#3d6611">Detected FSOCKOPEN on port 80/HTTP</strong>';
|
123 |
+
handler.value = 'fsockopen';
|
124 |
+
port.value = '80';
|
125 |
+
}
|
126 |
+
/* FSOCKOPEN detected, ports closed */
|
127 |
+
else if (text == 'error_autodetect_api_fsockopen_ports_blocked')
|
128 |
+
{
|
129 |
+
is_success = false;
|
130 |
+
result_container.innerHTML = '<strong style="color:#eb5e00">Detected FSOCKOPEN but both ports 80/443 are blocked</strong>';
|
131 |
+
handler.value = 'fsockopen';
|
132 |
+
}
|
133 |
+
/* No handler detected */
|
134 |
+
else
|
135 |
+
{
|
136 |
+
is_success = false;
|
137 |
+
result_container.innerHTML = '<strong style="color:#eb5e00">No connection handler detected</strong>';
|
138 |
+
}
|
139 |
+
}
|
140 |
+
|
141 |
+
</script>
|
142 |
+
<div id="oneall_singlesignon_api_test_result"></div>
|
143 |
+
|
144 |
+
HTML;
|
145 |
+
}
|
146 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/Apiconnectionhandler.php
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// API Connection Handler Dropdown
|
27 |
+
class OneAll_SingleSignOn_Model_Apiconnectionhandler
|
28 |
+
{
|
29 |
+
public function toOptionArray ()
|
30 |
+
{
|
31 |
+
$helper = Mage::helper ('oneall_singlesignon');
|
32 |
+
|
33 |
+
return array(
|
34 |
+
array(
|
35 |
+
'value' => '',
|
36 |
+
'label' => ''
|
37 |
+
),
|
38 |
+
array(
|
39 |
+
'value' => 'curl',
|
40 |
+
'label' => $helper->__ ('Use PHP CURL to communicate with the API')
|
41 |
+
),
|
42 |
+
array(
|
43 |
+
'value' => 'fsockopen',
|
44 |
+
'label' => $helper->__ ('Use PHP FSOCKOPEN to communicate with the API')
|
45 |
+
)
|
46 |
+
);
|
47 |
+
}
|
48 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/Apiconnectionport.php
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// API Connection Port Dropdown
|
27 |
+
class OneAll_SingleSignOn_Model_Apiconnectionport
|
28 |
+
{
|
29 |
+
public function toOptionArray ()
|
30 |
+
{
|
31 |
+
$helper = Mage::helper ('oneall_singlesignon');
|
32 |
+
|
33 |
+
return array(
|
34 |
+
array(
|
35 |
+
'value' => '',
|
36 |
+
'label' => ''
|
37 |
+
),
|
38 |
+
array(
|
39 |
+
'value' => 443,
|
40 |
+
'label' => $helper->__ ('Communication via HTTPS on port 443')
|
41 |
+
),
|
42 |
+
array(
|
43 |
+
'value' => 80,
|
44 |
+
'label' => $helper->__ ('Communication via HTTP on port 80')
|
45 |
+
)
|
46 |
+
);
|
47 |
+
}
|
48 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/Apiverify.php
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// Verifies the API Settings
|
27 |
+
class OneAll_SingleSignOn_Model_Apiverify
|
28 |
+
{
|
29 |
+
public function toOptionArray ()
|
30 |
+
{
|
31 |
+
$helper = Mage::helper ('oneall_singlesignon');
|
32 |
+
}
|
33 |
+
|
34 |
+
public function getCommentText ()
|
35 |
+
{
|
36 |
+
$base_url = Mage::getBaseUrl ();
|
37 |
+
|
38 |
+
return <<<HTML
|
39 |
+
|
40 |
+
<script language="javascript">
|
41 |
+
|
42 |
+
var button = document.getElementById("oneall_singlesignon_general_verify");
|
43 |
+
button.value = "Verify API Settings ";
|
44 |
+
button.onclick = function ()
|
45 |
+
{
|
46 |
+
verify_api_settings();
|
47 |
+
}
|
48 |
+
|
49 |
+
var verify_ajax = function (url, callback_function)
|
50 |
+
{
|
51 |
+
var request = new XMLHttpRequest();
|
52 |
+
|
53 |
+
request.open("GET", url, true);
|
54 |
+
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
55 |
+
request.onreadystatechange = function()
|
56 |
+
{
|
57 |
+
if (request.readyState == 4 && request.status == 200)
|
58 |
+
{
|
59 |
+
if (request.responseText)
|
60 |
+
{
|
61 |
+
callback_function(request.responseText);
|
62 |
+
}
|
63 |
+
}
|
64 |
+
};
|
65 |
+
request.send();
|
66 |
+
}
|
67 |
+
|
68 |
+
var verify_api_settings = function ()
|
69 |
+
{
|
70 |
+
var e, result_container, api_connection_handler, api_port, api_key, api_secret, api_connection_handler;
|
71 |
+
|
72 |
+
e = document.getElementById('oneall_singlesignon_connection_handler');
|
73 |
+
api_connection_handler = e.options[e.selectedIndex].value;
|
74 |
+
|
75 |
+
e = document.getElementById('oneall_singlesignon_connection_port');
|
76 |
+
api_connection_port = e.options[e.selectedIndex].value;
|
77 |
+
|
78 |
+
api_key = document.getElementById('oneall_singlesignon_general_key').value;
|
79 |
+
api_secret = document.getElementById('oneall_singlesignon_general_secret').value;
|
80 |
+
api_subdomain = document.getElementById('oneall_singlesignon_general_subdomain').value;
|
81 |
+
|
82 |
+
var result_container = document.getElementById('oneall_singlesignon_api_verify_result');
|
83 |
+
result_container.innerHTML = '<strong>Loading ...</strong>';
|
84 |
+
verify_ajax('{$base_url}oneall_singlesignon_ajax/ajax/verify?api_key=' + api_key + '&api_subdomain=' + api_subdomain + '&api_secret='+ api_secret +'&api_connection_handler='+ api_connection_handler +'&api_connection_port=' + api_connection_port, verify_complete);
|
85 |
+
}
|
86 |
+
|
87 |
+
var verify_complete = function (text)
|
88 |
+
{
|
89 |
+
var result_container;
|
90 |
+
|
91 |
+
result_container = document.getElementById('oneall_singlesignon_api_verify_result');
|
92 |
+
|
93 |
+
if (text == 'error_selected_handler_faulty')
|
94 |
+
{
|
95 |
+
result_container.innerHTML = '<strong style="color:#eb5e00">The connection handler does not work!</strong>';
|
96 |
+
}
|
97 |
+
else if (text == 'error_not_all_fields_filled_out')
|
98 |
+
{
|
99 |
+
result_container.innerHTML = '<strong style="color:#eb5e00">Please fill out each of the fields above.</strong>';
|
100 |
+
}
|
101 |
+
else if (text == 'error_subdomain_wrong')
|
102 |
+
{
|
103 |
+
result_container.innerHTML = '<strong style="color:#eb5e00">The API subdomain does not seem to exist!</strong>';
|
104 |
+
}
|
105 |
+
else if (text == 'error_subdomain_wrong_syntax')
|
106 |
+
{
|
107 |
+
result_container.innerHTML = '<strong style="color:#eb5e00">The API subdomain does not seem to exist!</strong>';
|
108 |
+
}
|
109 |
+
else if (text == 'error_communication')
|
110 |
+
{
|
111 |
+
result_container.innerHTML = '<strong style="color:#eb5e00">Could not establish a communication with OneAll.</strong>';
|
112 |
+
}
|
113 |
+
else if (text == 'error_authentication_credentials_wrong')
|
114 |
+
{
|
115 |
+
result_container.innerHTML = '<strong style="color:#eb5e00">The API keys are invalid!</strong>';
|
116 |
+
}
|
117 |
+
else if (text == 'error_plan_has_no_single_signon')
|
118 |
+
{
|
119 |
+
result_container.innerHTML = '<strong style="color:#eb5e00">Single Sign-On is not available for this OneAll site. Please login to your OneAll account and upgrade the site to a higher plan in order to enable it.</strong>';
|
120 |
+
}
|
121 |
+
else if (text == 'success')
|
122 |
+
{
|
123 |
+
result_container.innerHTML = '<strong style="color:#3d6611">Success! The API settings are correct!</strong>';
|
124 |
+
}
|
125 |
+
else
|
126 |
+
{
|
127 |
+
result_container.innerHTML = '<strong style="color:#eb5e00">Unknown result received</strong>';
|
128 |
+
}
|
129 |
+
|
130 |
+
}
|
131 |
+
</script>
|
132 |
+
<div id="oneall_singlesignon_api_verify_result"></div>
|
133 |
+
HTML;
|
134 |
+
}
|
135 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/Autocreateaccounts.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// Auto Create Accounts DropDown
|
27 |
+
class OneAll_SingleSignOn_Model_Autocreateaccounts
|
28 |
+
{
|
29 |
+
public function toOptionArray ()
|
30 |
+
{
|
31 |
+
$helper = Mage::helper ('oneall_singlesignon');
|
32 |
+
|
33 |
+
return array(
|
34 |
+
array(
|
35 |
+
'value' => 1,
|
36 |
+
'label' => $helper->__ ('Yes, automatically create new accounts')
|
37 |
+
),
|
38 |
+
array(
|
39 |
+
'value' => 0,
|
40 |
+
'label' => $helper->__ ('No, do not create new accounts for SSO users')
|
41 |
+
)
|
42 |
+
);
|
43 |
+
}
|
44 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/Autocreatesendmail.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// Auto Link Using Unverified Emails DropDown
|
27 |
+
class OneAll_SingleSignOn_Model_Autocreatesendmail
|
28 |
+
{
|
29 |
+
public function toOptionArray ()
|
30 |
+
{
|
31 |
+
$helper = Mage::helper ('oneall_singlesignon');
|
32 |
+
|
33 |
+
return array(
|
34 |
+
array(
|
35 |
+
'value' => 1,
|
36 |
+
'label' => $helper->__ ('Yes, send an email to newly added customers')
|
37 |
+
),
|
38 |
+
array(
|
39 |
+
'value' => 0,
|
40 |
+
'label' => $helper->__ ('No, do not send an email to newly added customers')
|
41 |
+
)
|
42 |
+
);
|
43 |
+
}
|
44 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/Autolinkaccounts.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// Auto Link Accounts DropDown
|
27 |
+
class OneAll_SingleSignOn_Model_Autolinkaccounts
|
28 |
+
{
|
29 |
+
public function toOptionArray ()
|
30 |
+
{
|
31 |
+
$helper = Mage::helper ('oneall_singlesignon');
|
32 |
+
|
33 |
+
return array(
|
34 |
+
array(
|
35 |
+
'value' => 1,
|
36 |
+
'label' => $helper->__ ('Yes, automatically link SSO users to existing accounts')
|
37 |
+
),
|
38 |
+
array(
|
39 |
+
'value' => 0,
|
40 |
+
'label' => $helper->__ ('No, do not link SSO users to existing accounts')
|
41 |
+
)
|
42 |
+
);
|
43 |
+
}
|
44 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/Autolinkunverified.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// Auto Link Using Unverified Emails DropDown
|
27 |
+
class OneAll_SingleSignOn_Model_Autolinkunverified
|
28 |
+
{
|
29 |
+
public function toOptionArray ()
|
30 |
+
{
|
31 |
+
$helper = Mage::helper ('oneall_singlesignon');
|
32 |
+
|
33 |
+
return array(
|
34 |
+
array(
|
35 |
+
'value' => 1,
|
36 |
+
'label' => $helper->__ ('Yes, also use unverified email addresses to link accounts')
|
37 |
+
),
|
38 |
+
array(
|
39 |
+
'value' => 0,
|
40 |
+
'label' => $helper->__ ('No, do not use unverified email addresses to link accounts')
|
41 |
+
)
|
42 |
+
);
|
43 |
+
}
|
44 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/Observer.php
ADDED
@@ -0,0 +1,290 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// Single Sign-On Observer
|
27 |
+
class OneAll_SingleSignOn_Model_Observer
|
28 |
+
{
|
29 |
+
// Fired whenever a customer is saved.
|
30 |
+
public function customer_save_after ($observer)
|
31 |
+
{
|
32 |
+
// Load Customer.
|
33 |
+
$customer = $observer->getCustomer ();
|
34 |
+
$customer_id = $customer->getId ();
|
35 |
+
|
36 |
+
// Customer found.
|
37 |
+
if (!empty ($customer_id))
|
38 |
+
{
|
39 |
+
// Where are we now?
|
40 |
+
$page_tag = trim (strtolower (Mage::app ()->getFrontController ()->getAction ()->getFullActionName ('_')));
|
41 |
+
switch ($page_tag)
|
42 |
+
{
|
43 |
+
// Customer is resetting his password.
|
44 |
+
case 'customer_account_resetpasswordpost' :
|
45 |
+
|
46 |
+
// Read customer's tokens.
|
47 |
+
$tokens = Mage::helper ('oneall_singlesignon')->get_local_storage_tokens_for_customer ($customer);
|
48 |
+
|
49 |
+
// If we don't have a token, nothing needs to be done
|
50 |
+
if ($tokens->have_been_retrieved === true)
|
51 |
+
{
|
52 |
+
// Get password details.
|
53 |
+
$password_frm_new = Mage::app ()->getRequest ()->getParam ('password');
|
54 |
+
$password_frm_confirm = Mage::app ()->getRequest ()->getParam ('confirmation');
|
55 |
+
|
56 |
+
// Make sure the passwords match.
|
57 |
+
if ($password_frm_new == $password_frm_confirm)
|
58 |
+
{
|
59 |
+
// Add Log
|
60 |
+
Mage::helper ('oneall_singlesignon')->add_log ('[Observer: customer_save_after] Updating cloud password for customer ['.$customer->getId().']');
|
61 |
+
|
62 |
+
// Update the customer's cloud storage.
|
63 |
+
$password_status = Mage::helper ('oneall_singlesignon')->api_update_customer_cloud_password ($customer, $password_frm_new);
|
64 |
+
}
|
65 |
+
}
|
66 |
+
break;
|
67 |
+
}
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
71 |
+
// Fired whenever a new customer registers.
|
72 |
+
public function customer_register ($observer)
|
73 |
+
{
|
74 |
+
// Load Customer.
|
75 |
+
$customer = $observer->getCustomer ();
|
76 |
+
$customer_id = $customer->getId ();
|
77 |
+
|
78 |
+
// Customer found.
|
79 |
+
if (!empty ($customer_id))
|
80 |
+
{
|
81 |
+
// Get login details
|
82 |
+
$email = Mage::app ()->getRequest ()->getParam ('email');
|
83 |
+
$password = Mage::app ()->getRequest ()->getParam ('password');
|
84 |
+
|
85 |
+
// Add Log
|
86 |
+
Mage::helper ('oneall_singlesignon')->add_log ('[Observer: customer_register] Creating SSO session for customer ['.$customer->getId().']');
|
87 |
+
|
88 |
+
// Setup a new SSO session for this customer
|
89 |
+
Mage::helper ('oneall_singlesignon')->create_session_for_customer ($customer, $email, $password);
|
90 |
+
}
|
91 |
+
}
|
92 |
+
|
93 |
+
// Fired whenever a customer updates his account settings.
|
94 |
+
public function customer_before_update_account ($observer)
|
95 |
+
{
|
96 |
+
// Load Customer
|
97 |
+
$customer = Mage::getSingleton ('customer/session')->getCustomer ();
|
98 |
+
$customer_id = $customer->getId ();
|
99 |
+
|
100 |
+
// Customer found
|
101 |
+
if (!empty ($customer_id))
|
102 |
+
{
|
103 |
+
// Read User Tokens
|
104 |
+
$tokens = Mage::helper ('oneall_singlesignon')->get_local_storage_tokens_for_customer ($customer);
|
105 |
+
|
106 |
+
// If we don't have a token, nothing needs to be done.
|
107 |
+
if ($tokens->have_been_retrieved === true)
|
108 |
+
{
|
109 |
+
// Add Log
|
110 |
+
Mage::helper ('oneall_singlesignon')->add_log ('[Observer: customer_before_update_account] Checking is password for customer ['.$customer->getId().'] must be updated');
|
111 |
+
|
112 |
+
// Is the entered password valid?
|
113 |
+
$password_is_valid = false;
|
114 |
+
|
115 |
+
// Does the customer wants to change the password?
|
116 |
+
$password_do_change = Mage::app ()->getRequest ()->getParam ('change_password');
|
117 |
+
|
118 |
+
// Gather new password details.
|
119 |
+
$password_frm_current = Mage::app ()->getRequest ()->getParam ('current_password');
|
120 |
+
$password_frm_new = Mage::app ()->getRequest ()->getParam ('password');
|
121 |
+
$password_frm_confirm = Mage::app ()->getRequest ()->getParam ('confirmation');
|
122 |
+
|
123 |
+
// Does the password can and needs to be changed?
|
124 |
+
if (!empty ($password_do_change))
|
125 |
+
{
|
126 |
+
if ( !empty ($password_frm_new) && ($password_frm_new == $password_frm_confirm) && ($password_frm_new != $password_frm_current))
|
127 |
+
{
|
128 |
+
// Old Password Details
|
129 |
+
$password_curr = $customer->getPasswordHash ();
|
130 |
+
$password_curr_parts = explode (":", $password_curr);
|
131 |
+
$password_curr_salt = $password_curr_parts [1];
|
132 |
+
|
133 |
+
// Check if the password is valid.
|
134 |
+
if ($password_curr == Mage::helper ('core')->getHash ($password_frm_current, $password_curr_salt))
|
135 |
+
{
|
136 |
+
// Add Log
|
137 |
+
Mage::helper ('oneall_singlesignon')->add_log ('[Observer: customer_before_update_account] Valid local password entered for customer ['.$customer->getId().']');
|
138 |
+
|
139 |
+
// Password is valid
|
140 |
+
$password_is_valid = true;
|
141 |
+
}
|
142 |
+
// If it's not valid then check the cloud storage.
|
143 |
+
else
|
144 |
+
{
|
145 |
+
// Checks if a given customer has a cloud storage account and if the given password is valid for it.
|
146 |
+
$password_status = Mage::helper ('oneall_singlesignon')->api_check_customer_cloud_password ($customer, $password_frm_current);
|
147 |
+
|
148 |
+
// User has a cloud storage and the password matches.
|
149 |
+
if ($password_status->is_valid === true)
|
150 |
+
{
|
151 |
+
// Add Log
|
152 |
+
Mage::helper ('oneall_singlesignon')->add_log ('[Observer: customer_before_update_account] Valid cloud password entered for customer ['.$customer->getId().']');
|
153 |
+
|
154 |
+
// Password is valid
|
155 |
+
$password_is_valid = true;
|
156 |
+
}
|
157 |
+
}
|
158 |
+
|
159 |
+
// The entered password is valid.
|
160 |
+
if ($password_is_valid == true)
|
161 |
+
{
|
162 |
+
// Add Log
|
163 |
+
Mage::helper ('oneall_singlesignon')->add_log ('[Observer: customer_before_update_account] Updating passwords for customer ['.$customer->getId().']');
|
164 |
+
|
165 |
+
// Set the new password.
|
166 |
+
$customer->setPassword ($password_frm_new);
|
167 |
+
$customer->save ();
|
168 |
+
|
169 |
+
// Update the customer's cloud storage.
|
170 |
+
$password_status = Mage::helper ('oneall_singlesignon')->api_update_customer_cloud_password ($customer, $password_frm_new);
|
171 |
+
|
172 |
+
// Reset password form - we have already done everything that needs to be done.
|
173 |
+
foreach (array('change_password', 'current_password', 'password', 'confirmation') as $field)
|
174 |
+
{
|
175 |
+
Mage::app ()->getRequest ()->setPost ($field, null);
|
176 |
+
}
|
177 |
+
}
|
178 |
+
else
|
179 |
+
{
|
180 |
+
// Add Log
|
181 |
+
Mage::helper ('oneall_singlesignon')->add_log ('[Observer: customer_before_update_account] No valid passwords entered for customer ['.$customer->getId().']');
|
182 |
+
}
|
183 |
+
}
|
184 |
+
}
|
185 |
+
}
|
186 |
+
}
|
187 |
+
}
|
188 |
+
|
189 |
+
// Fired when a customer tries to login.
|
190 |
+
public function customer_before_login ($observer)
|
191 |
+
{
|
192 |
+
// Retrieve login data
|
193 |
+
$login = Mage::app ()->getRequest ()->getParam ('login');
|
194 |
+
if (is_array ($login))
|
195 |
+
{
|
196 |
+
// Get login details.
|
197 |
+
$email = (isset ($login ['username']) ? trim ($login ['username']) : '');
|
198 |
+
$password = (isset ($login ['password']) ? trim ($login ['password']) : '');
|
199 |
+
|
200 |
+
// Have the credentials been specified?
|
201 |
+
if (!empty ($email) && !empty ($password))
|
202 |
+
{
|
203 |
+
if (Zend_Validate::is ($email, 'EmailAddress'))
|
204 |
+
{
|
205 |
+
// Add Log
|
206 |
+
Mage::helper ('oneall_singlesignon')->add_log ('[Observer: customer_before_login] Trying cloud login with ['. $email .']');
|
207 |
+
|
208 |
+
// Try to login this user
|
209 |
+
$cloud_login = Mage::helper ('oneall_singlesignon')->try_customer_cloud_login ($email, $password);
|
210 |
+
|
211 |
+
// Not successfull
|
212 |
+
if ( ! $cloud_login->is_successfull)
|
213 |
+
{
|
214 |
+
// Add Log
|
215 |
+
Mage::helper ('oneall_singlesignon')->add_log ('[Observer: customer_before_login] Cloud login with ['. $email .'] failed, trying local login');
|
216 |
+
}
|
217 |
+
}
|
218 |
+
}
|
219 |
+
}
|
220 |
+
}
|
221 |
+
|
222 |
+
// Fired after a customer has logged in.
|
223 |
+
public function customer_after_login ($observer)
|
224 |
+
{
|
225 |
+
// Load Customer.
|
226 |
+
$customer = $observer->getCustomer ();
|
227 |
+
$customer_id = $customer->getId ();
|
228 |
+
|
229 |
+
// Customer found.
|
230 |
+
if (!empty ($customer_id))
|
231 |
+
{
|
232 |
+
// Add Log
|
233 |
+
Mage::helper ('oneall_singlesignon')->add_log ('[Observer: customer_after_login] Creating session for customer ['.$customer->getId().']');
|
234 |
+
|
235 |
+
// Setup a new SSO session for this customer.
|
236 |
+
Mage::helper ('oneall_singlesignon')->create_session_for_customer ($customer);
|
237 |
+
}
|
238 |
+
}
|
239 |
+
|
240 |
+
// Fired after a customer has logged out.
|
241 |
+
public function customer_after_logout ($observer)
|
242 |
+
{
|
243 |
+
// Load Customer.
|
244 |
+
$customer = $observer->getCustomer ();
|
245 |
+
$customer_id = $customer->getId ();
|
246 |
+
|
247 |
+
// Customer found.
|
248 |
+
if (!empty ($customer_id))
|
249 |
+
{
|
250 |
+
// Add Log
|
251 |
+
Mage::helper ('oneall_singlesignon')->add_log ('[Observer: customer_after_logout] Removing session for customer ['.$customer->getId().']');
|
252 |
+
|
253 |
+
// Remove the SSO session of this customer.
|
254 |
+
Mage::helper ('oneall_singlesignon')->remove_session_for_customer ($customer);
|
255 |
+
}
|
256 |
+
}
|
257 |
+
|
258 |
+
// Fired before the layout is loaded.
|
259 |
+
public function layout_load_before ($observer)
|
260 |
+
{
|
261 |
+
// Where are we now?
|
262 |
+
$page_tag = trim (strtolower (Mage::app ()->getFrontController ()->getAction ()->getFullActionName ('_')));
|
263 |
+
switch ($page_tag)
|
264 |
+
{
|
265 |
+
// Customer is on the login page.
|
266 |
+
case 'customer_account_login' :
|
267 |
+
|
268 |
+
// Do we have the email of the customer?
|
269 |
+
$sso_email = Mage::getSingleton ('core/session')->getSSOEmail ();
|
270 |
+
if (!empty ($sso_email))
|
271 |
+
{
|
272 |
+
Mage::getSingleton ('core/session')->addSuccess (__ ('Please login with your email address <strong>%s</strong> in order to access your account.', $sso_email));
|
273 |
+
}
|
274 |
+
|
275 |
+
break;
|
276 |
+
|
277 |
+
// Customer is on the registration page.
|
278 |
+
case 'customer_account_create' :
|
279 |
+
|
280 |
+
// Do we have the email of the customer?
|
281 |
+
$sso_email = Mage::getSingleton ('core/session')->getSSOEmail ();
|
282 |
+
if (!empty ($sso_email))
|
283 |
+
{
|
284 |
+
Mage::getSingleton ('core/session')->addSuccess (__ ('You already seem to have created an account using the email address <strong>%s</strong>. Please click <a href="%s">here</a> to login.', $sso_email, Mage::getUrl ('customer/account/login')));
|
285 |
+
}
|
286 |
+
|
287 |
+
break;
|
288 |
+
}
|
289 |
+
}
|
290 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/Resource/Session.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// Single Sign-On Session Table
|
27 |
+
class OneAll_SingleSignOn_Model_Resource_Session extends Mage_Core_Model_Resource_Db_Abstract
|
28 |
+
{
|
29 |
+
public function _construct ()
|
30 |
+
{
|
31 |
+
$this->_init ('oneall_singlesignon/session', 'customer_id');
|
32 |
+
$this->_isPkAutoIncrement = false;
|
33 |
+
}
|
34 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/Resource/Session/Collection.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// Single Sign-On Session Table
|
27 |
+
class OneAll_SingleSignOn_Model_Resource_Session_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
|
28 |
+
{
|
29 |
+
public function _construct ()
|
30 |
+
{
|
31 |
+
$this->_init ('oneall_singlesignon/session');
|
32 |
+
}
|
33 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/Resource/User.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// Single Sign-On User Table
|
27 |
+
class OneAll_SingleSignOn_Model_Resource_User extends Mage_Core_Model_Resource_Db_Abstract
|
28 |
+
{
|
29 |
+
public function _construct ()
|
30 |
+
{
|
31 |
+
$this->_init ('oneall_singlesignon/user', 'customer_id');
|
32 |
+
$this->_isPkAutoIncrement = false;
|
33 |
+
}
|
34 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/Resource/User/Collection.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// Single Sign-On User Table
|
27 |
+
class OneAll_SingleSignOn_Model_Resource_User_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
|
28 |
+
{
|
29 |
+
public function _construct ()
|
30 |
+
{
|
31 |
+
$this->_init ('oneall_singlesignon/user');
|
32 |
+
}
|
33 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/Session.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// Single Sign-On Session Model
|
27 |
+
class OneAll_SingleSignOn_Model_Session extends Mage_Core_Model_Abstract
|
28 |
+
{
|
29 |
+
protected function _construct ()
|
30 |
+
{
|
31 |
+
parent::_construct();
|
32 |
+
$this->_init ('oneall_singlesignon/session');
|
33 |
+
}
|
34 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/Sessionlifetime.php
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// SSO Session Lifetime
|
27 |
+
class OneAll_SingleSignOn_Model_Sessionlifetime
|
28 |
+
{
|
29 |
+
public function toOptionArray ()
|
30 |
+
{
|
31 |
+
$helper = Mage::helper ('oneall_singlesignon');
|
32 |
+
|
33 |
+
return array(
|
34 |
+
array(
|
35 |
+
'value' => '7200',
|
36 |
+
'label' => $helper->__ ('2 Hours')
|
37 |
+
),
|
38 |
+
array(
|
39 |
+
'value' => '14400',
|
40 |
+
'label' => $helper->__ ('4 Hours')
|
41 |
+
),
|
42 |
+
array(
|
43 |
+
'value' => '21600',
|
44 |
+
'label' => $helper->__ ('6 Hours')
|
45 |
+
),
|
46 |
+
array(
|
47 |
+
'value' => '43200',
|
48 |
+
'label' => $helper->__ ('12 Hours')
|
49 |
+
),
|
50 |
+
array(
|
51 |
+
'value' => '86400',
|
52 |
+
'label' => $helper->__ ('1 Day')
|
53 |
+
),
|
54 |
+
array(
|
55 |
+
'value' => '172800',
|
56 |
+
'label' => $helper->__ ('2 Days')
|
57 |
+
),
|
58 |
+
array(
|
59 |
+
'value' => '259200',
|
60 |
+
'label' => $helper->__ ('3 Days')
|
61 |
+
),
|
62 |
+
array(
|
63 |
+
'value' => '345600',
|
64 |
+
'label' => $helper->__ ('4 Days')
|
65 |
+
),
|
66 |
+
array(
|
67 |
+
'value' => '432000',
|
68 |
+
'label' => $helper->__ ('5 Days')
|
69 |
+
),
|
70 |
+
array(
|
71 |
+
'value' => '518400',
|
72 |
+
'label' => $helper->__ ('6 Days')
|
73 |
+
),
|
74 |
+
array(
|
75 |
+
'value' => '604800',
|
76 |
+
'label' => $helper->__ ('1 Week')
|
77 |
+
),
|
78 |
+
array(
|
79 |
+
'value' => '1209600',
|
80 |
+
'label' => $helper->__ ('2 Weeks')
|
81 |
+
),
|
82 |
+
array(
|
83 |
+
'value' => '1814400',
|
84 |
+
'label' => $helper->__ ('3 Weeks')
|
85 |
+
),
|
86 |
+
array(
|
87 |
+
'value' => '2419200',
|
88 |
+
'label' => $helper->__ ('1 Month')
|
89 |
+
)
|
90 |
+
);
|
91 |
+
}
|
92 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/Sessionsubrealm.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// SSO Session Sub Realm
|
27 |
+
class OneAll_SingleSignOn_Model_Sessionsubrealm extends Mage_Core_Model_Config_Data
|
28 |
+
{
|
29 |
+
// Save the value to the database.
|
30 |
+
public function save ()
|
31 |
+
{
|
32 |
+
// Read Params
|
33 |
+
$params = Mage::app ()->getRequest ()->getParams ();
|
34 |
+
|
35 |
+
// Do not use a sub-realm without a top-realm
|
36 |
+
if (empty ($params ['groups'] ['settings'] ['fields'] ['sessiontoprealm'] ['value']))
|
37 |
+
{
|
38 |
+
$this->setValue ('');
|
39 |
+
}
|
40 |
+
|
41 |
+
// Save.
|
42 |
+
return parent::save ();
|
43 |
+
}
|
44 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/Subdomain.php
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// API Connection Subdomain
|
27 |
+
class OneAll_SingleSignOn_Model_Subdomain extends Mage_Core_Model_Config_Data
|
28 |
+
{
|
29 |
+
// Save the value to the database.
|
30 |
+
public function save ()
|
31 |
+
{
|
32 |
+
// Read subdomain.
|
33 |
+
$subdomain = trim ($this->getValue ());
|
34 |
+
|
35 |
+
// Full domain entered.
|
36 |
+
if (preg_match ("/([a-z0-9\-]+)\.api\.oneall\.com/i", $subdomain, $matches))
|
37 |
+
{
|
38 |
+
$subdomain = $matches [1];
|
39 |
+
}
|
40 |
+
|
41 |
+
// Use new value.
|
42 |
+
$this->setValue ($subdomain);
|
43 |
+
|
44 |
+
// Save.
|
45 |
+
return parent::save ();
|
46 |
+
}
|
47 |
+
}
|
app/code/community/OneAll/SingleSignOn/Model/User.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// Single Sign-On User Model
|
27 |
+
class OneAll_SingleSignOn_Model_User extends Mage_Core_Model_Abstract
|
28 |
+
{
|
29 |
+
protected function _construct ()
|
30 |
+
{
|
31 |
+
parent::_construct();
|
32 |
+
$this->_init ('oneall_singlesignon/user');
|
33 |
+
}
|
34 |
+
}
|
app/code/community/OneAll/SingleSignOn/controllers/AjaxController.php
ADDED
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
class OneAll_SingleSignOn_AjaxController extends Mage_Core_Controller_Front_Action
|
26 |
+
{
|
27 |
+
// Autodetect API Handler
|
28 |
+
public function indexAction ()
|
29 |
+
{
|
30 |
+
// Check if CURL is available
|
31 |
+
if (Mage::helper ('oneall_singlesignon')->is_curl_available ())
|
32 |
+
{
|
33 |
+
// Check CURL HTTPS - Port 443
|
34 |
+
if (Mage::helper ('oneall_singlesignon')->is_api_connection_curl_ok (true) === true)
|
35 |
+
{
|
36 |
+
die ('success_autodetect_api_curl_https');
|
37 |
+
}
|
38 |
+
// Check CURL HTTP - Port 80
|
39 |
+
elseif (Mage::helper ('oneall_singlesignon')->is_api_connection_curl_ok (false) === true)
|
40 |
+
{
|
41 |
+
die ('success_autodetect_api_curl_http');
|
42 |
+
}
|
43 |
+
else
|
44 |
+
{
|
45 |
+
die ('error_autodetect_api_curl_ports_blocked');
|
46 |
+
}
|
47 |
+
}
|
48 |
+
// Check if FSOCKOPEN is available
|
49 |
+
elseif (Mage::helper ('oneall_singlesignon')->is_fsockopen_available ())
|
50 |
+
{
|
51 |
+
// Check FSOCKOPEN HTTPS - Port 443
|
52 |
+
if (Mage::helper ('oneall_singlesignon')->is_api_connection_fsockopen_ok (true) == true)
|
53 |
+
{
|
54 |
+
die ('success_autodetect_api_fsockopen_https');
|
55 |
+
}
|
56 |
+
// Check FSOCKOPEN HTTP - Port 80
|
57 |
+
elseif (Mage::helper ('oneall_singlesignon')->is_api_connection_fsockopen_ok (false) == true)
|
58 |
+
{
|
59 |
+
die ('success_autodetect_api_fsockopen_http');
|
60 |
+
}
|
61 |
+
else
|
62 |
+
{
|
63 |
+
die ('error_autodetect_api_fsockopen_ports_blocked');
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
// No working handler found
|
68 |
+
die ('error_autodetect_api_no_handler');
|
69 |
+
}
|
70 |
+
|
71 |
+
// Verify API Settings
|
72 |
+
public function verifyAction ()
|
73 |
+
{
|
74 |
+
// Build settings.
|
75 |
+
$ext_settings = array();
|
76 |
+
|
77 |
+
// API Credentials.
|
78 |
+
$ext_settings ['subdomain'] = trim (Mage::app ()->getRequest ()->getParam ('api_subdomain'));
|
79 |
+
$ext_settings ['key'] = trim (Mage::app ()->getRequest ()->getParam ('api_key'));
|
80 |
+
$ext_settings ['secret'] = trim (Mage::app ()->getRequest ()->getParam ('api_secret'));
|
81 |
+
|
82 |
+
// API Connection Handler.
|
83 |
+
$ext_settings ['connection_handler'] = (trim (Mage::app ()->getRequest ()->getParam ('api_connection_handler')) == 'fsockopen' ? 'fsockopen' : 'curl');
|
84 |
+
$ext_settings ['connection_port'] = (trim (Mage::app ()->getRequest ()->getParam ('api_connection_port')) == '80' ? 80 : 443);
|
85 |
+
$ext_settings ['connection_protocol'] = ($ext_settings ['connection_port'] == 80 ? 'http' : 'https');
|
86 |
+
|
87 |
+
|
88 |
+
// Fields missing.
|
89 |
+
if (empty ($ext_settings ['subdomain']) || empty ($ext_settings ['key']) || empty ($ext_settings ['secret']))
|
90 |
+
{
|
91 |
+
die ('error_not_all_fields_filled_out');
|
92 |
+
}
|
93 |
+
|
94 |
+
// Full domain entered.
|
95 |
+
if (preg_match ("/([a-z0-9\-]+)\.api\.oneall\.com/i", $ext_settings ['subdomain'], $matches))
|
96 |
+
{
|
97 |
+
$ext_settings ['subdomain'] = $matches [1];
|
98 |
+
}
|
99 |
+
|
100 |
+
// Check subdomain format
|
101 |
+
if (!preg_match ("/^[a-z0-9\-]+$/i", $ext_settings ['subdomain']))
|
102 |
+
{
|
103 |
+
die ('error_subdomain_wrong_syntax');
|
104 |
+
}
|
105 |
+
|
106 |
+
// Domain
|
107 |
+
$ext_settings ['base_url'] = ($ext_settings ['subdomain'] . '.api.oneall.com');
|
108 |
+
$ext_settings ['api_url'] = ($ext_settings ['connection_protocol'] . '://' . $ext_settings ['base_url']);
|
109 |
+
|
110 |
+
// API Endpoint
|
111 |
+
$api_resource_url = $ext_settings ['api_url'] . '/site.json';
|
112 |
+
|
113 |
+
// API Options
|
114 |
+
$api_options = array(
|
115 |
+
'api_key' => $ext_settings ['key'],
|
116 |
+
'api_secret' => $ext_settings ['secret']
|
117 |
+
);
|
118 |
+
|
119 |
+
// Ping.
|
120 |
+
$result = Mage::helper ('oneall_singlesignon')->do_api_request ($ext_settings ['connection_handler'], $api_resource_url, 'GET', $api_options);
|
121 |
+
|
122 |
+
// Check result.
|
123 |
+
if (is_object ($result) && property_exists ($result, 'http_code'))
|
124 |
+
{
|
125 |
+
switch ($result->http_code)
|
126 |
+
{
|
127 |
+
// Success
|
128 |
+
case 200 :
|
129 |
+
if (property_exists ($result, 'http_data'))
|
130 |
+
{
|
131 |
+
// Decode result
|
132 |
+
$decoded_result = @json_decode ($result->http_data);
|
133 |
+
|
134 |
+
// Check result
|
135 |
+
if (is_object ($decoded_result) && isset ($decoded_result->response->result->data->site))
|
136 |
+
{
|
137 |
+
// Site Details
|
138 |
+
$site = $decoded_result->response->result->data->site;
|
139 |
+
|
140 |
+
// Check if our plans has the cloud storage
|
141 |
+
if (empty ($site->subscription_plan->features->has_single_signon))
|
142 |
+
{
|
143 |
+
die ('error_plan_has_no_single_signon');
|
144 |
+
}
|
145 |
+
// Success
|
146 |
+
else
|
147 |
+
{
|
148 |
+
die ('success');
|
149 |
+
}
|
150 |
+
}
|
151 |
+
}
|
152 |
+
break;
|
153 |
+
|
154 |
+
// Authentication Error
|
155 |
+
case 401 :
|
156 |
+
die ('error_authentication_credentials_wrong');
|
157 |
+
break;
|
158 |
+
|
159 |
+
// Wrong Subdomain
|
160 |
+
case 404 :
|
161 |
+
die ('error_subdomain_wrong');
|
162 |
+
break;
|
163 |
+
}
|
164 |
+
}
|
165 |
+
|
166 |
+
die ('error_communication');
|
167 |
+
}
|
168 |
+
}
|
app/code/community/OneAll/SingleSignOn/etc/adminhtml.xml
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<acl>
|
4 |
+
<resources>
|
5 |
+
<admin>
|
6 |
+
<children>
|
7 |
+
<system>
|
8 |
+
<children>
|
9 |
+
<config>
|
10 |
+
<children>
|
11 |
+
<oneall_singlesignon translate="title" module="oneall_singlesignon">
|
12 |
+
<title>OneAll Single Sign-On</title>
|
13 |
+
</oneall_singlesignon>
|
14 |
+
</children>
|
15 |
+
</config>
|
16 |
+
</children>
|
17 |
+
</system>
|
18 |
+
</children>
|
19 |
+
</admin>
|
20 |
+
</resources>
|
21 |
+
</acl>
|
22 |
+
</config>
|
app/code/community/OneAll/SingleSignOn/etc/config.xml
ADDED
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<OneAll_SingleSignOn>
|
5 |
+
<version>1.0.0</version>
|
6 |
+
</OneAll_SingleSignOn>
|
7 |
+
</modules>
|
8 |
+
<frontend>
|
9 |
+
<routers>
|
10 |
+
<oneall_singlesignon>
|
11 |
+
<use>standard</use>
|
12 |
+
<args>
|
13 |
+
<module>OneAll_SingleSignOn</module>
|
14 |
+
<frontName>oneall_singlesignon_ajax</frontName>
|
15 |
+
</args>
|
16 |
+
</oneall_singlesignon>
|
17 |
+
</routers>
|
18 |
+
<layout>
|
19 |
+
<updates>
|
20 |
+
<oneall_singlesignon module="oneall_singlesignon">
|
21 |
+
<file>oneall-singlesignon.xml</file>
|
22 |
+
</oneall_singlesignon>
|
23 |
+
</updates>
|
24 |
+
</layout>
|
25 |
+
</frontend>
|
26 |
+
<global>
|
27 |
+
<events>
|
28 |
+
|
29 |
+
<controller_action_predispatch_customer_account_loginpost>
|
30 |
+
<observers>
|
31 |
+
<OneAll_SingleSignOn_Model_Observer>
|
32 |
+
<type>singleton</type>
|
33 |
+
<class>OneAll_SingleSignOn_Model_Observer</class>
|
34 |
+
<method>customer_before_login</method>
|
35 |
+
</OneAll_SingleSignOn_Model_Observer>
|
36 |
+
</observers>
|
37 |
+
</controller_action_predispatch_customer_account_loginpost>
|
38 |
+
<customer_login>
|
39 |
+
<observers>
|
40 |
+
<OneAll_SingleSignOn_Model_Observer>
|
41 |
+
<type>singleton</type>
|
42 |
+
<class>OneAll_SingleSignOn_Model_Observer</class>
|
43 |
+
<method>customer_after_login</method>
|
44 |
+
</OneAll_SingleSignOn_Model_Observer>
|
45 |
+
</observers>
|
46 |
+
</customer_login>
|
47 |
+
<controller_action_predispatch_customer_account_editpost>
|
48 |
+
<observers>
|
49 |
+
<OneAll_SingleSignOn_Model_Observer>
|
50 |
+
<type>singleton</type>
|
51 |
+
<class>OneAll_SingleSignOn_Model_Observer</class>
|
52 |
+
<method>customer_before_update_account</method>
|
53 |
+
</OneAll_SingleSignOn_Model_Observer>
|
54 |
+
</observers>
|
55 |
+
</controller_action_predispatch_customer_account_editpost>
|
56 |
+
<controller_action_layout_load_before>
|
57 |
+
<observers>
|
58 |
+
<OneAll_SingleSignOn_Model_Observer>
|
59 |
+
<type>singleton</type>
|
60 |
+
<class>OneAll_SingleSignOn_Model_Observer</class>
|
61 |
+
<method>layout_load_before</method>
|
62 |
+
</OneAll_SingleSignOn_Model_Observer>
|
63 |
+
</observers>
|
64 |
+
</controller_action_layout_load_before>
|
65 |
+
<customer_save_after>
|
66 |
+
<observers>
|
67 |
+
<OneAll_SingleSignOn_Model_Observer>
|
68 |
+
<type>singleton</type>
|
69 |
+
<class>OneAll_SingleSignOn_Model_Observer</class>
|
70 |
+
<method>customer_save_after</method>
|
71 |
+
</OneAll_SingleSignOn_Model_Observer>
|
72 |
+
</observers>
|
73 |
+
</customer_save_after>
|
74 |
+
<customer_register_success>
|
75 |
+
<observers>
|
76 |
+
<OneAll_SingleSignOn_Model_Observer>
|
77 |
+
<type>singleton</type>
|
78 |
+
<class>OneAll_SingleSignOn_Model_Observer</class>
|
79 |
+
<method>customer_register</method>
|
80 |
+
</OneAll_SingleSignOn_Model_Observer>
|
81 |
+
</observers>
|
82 |
+
</customer_register_success>
|
83 |
+
<customer_logout>
|
84 |
+
<observers>
|
85 |
+
<OneAll_SingleSignOn_Model_Observer>
|
86 |
+
<type>singleton</type>
|
87 |
+
<class>OneAll_SingleSignOn_Model_Observer</class>
|
88 |
+
<method>customer_after_logout</method>
|
89 |
+
</OneAll_SingleSignOn_Model_Observer>
|
90 |
+
</observers>
|
91 |
+
</customer_logout>
|
92 |
+
</events>
|
93 |
+
<blocks>
|
94 |
+
<oneall_singlesignon>
|
95 |
+
<class>OneAll_SingleSignOn_Block</class>
|
96 |
+
</oneall_singlesignon>
|
97 |
+
</blocks>
|
98 |
+
<models>
|
99 |
+
<oneall_singlesignon>
|
100 |
+
<class>OneAll_SingleSignOn_Model</class>
|
101 |
+
<resourceModel>oneall_singlesignon_resource</resourceModel>
|
102 |
+
</oneall_singlesignon>
|
103 |
+
<oneall_singlesignon_resource>
|
104 |
+
<class>OneAll_SingleSignOn_Model_Resource</class>
|
105 |
+
<entities>
|
106 |
+
<session>
|
107 |
+
<table>oneall_singlesignon_session</table>
|
108 |
+
</session>
|
109 |
+
<user>
|
110 |
+
<table>oneall_singlesignon_user</table>
|
111 |
+
</user>
|
112 |
+
</entities>
|
113 |
+
</oneall_singlesignon_resource>
|
114 |
+
</models>
|
115 |
+
<resources>
|
116 |
+
<oneall_singlesignon_setup>
|
117 |
+
<setup>
|
118 |
+
<module>OneAll_SingleSignOn</module>
|
119 |
+
</setup>
|
120 |
+
<connection>
|
121 |
+
<use>core_setup</use>
|
122 |
+
</connection>
|
123 |
+
</oneall_singlesignon_setup>
|
124 |
+
<oneall_singlesignon_write>
|
125 |
+
<connection>
|
126 |
+
<use>core_write</use>
|
127 |
+
</connection>
|
128 |
+
</oneall_singlesignon_write>
|
129 |
+
<oneall_singlesignon_read>
|
130 |
+
<connection>
|
131 |
+
<use>core_read</use>
|
132 |
+
</connection>
|
133 |
+
</oneall_singlesignon_read>
|
134 |
+
</resources>
|
135 |
+
<helpers>
|
136 |
+
<oneall_singlesignon>
|
137 |
+
<class>OneAll_SingleSignOn_Helper</class>
|
138 |
+
</oneall_singlesignon>
|
139 |
+
</helpers>
|
140 |
+
</global>
|
141 |
+
<default>
|
142 |
+
<oneall_singlesignon>
|
143 |
+
<connection>
|
144 |
+
<handler>curl</handler>
|
145 |
+
<port>443</port>
|
146 |
+
</connection>
|
147 |
+
<settings>
|
148 |
+
<sessionlifetime>86400</sessionlifetime>
|
149 |
+
<sessiontoprealm></sessiontoprealm>
|
150 |
+
<sessionsubrealm></sessionsubrealm>
|
151 |
+
</settings>
|
152 |
+
<accounts_create>
|
153 |
+
<automatic>1</automatic>
|
154 |
+
<sendmail>0</sendmail>
|
155 |
+
</accounts_create>
|
156 |
+
<accounts_link>
|
157 |
+
<automatic>1</automatic>
|
158 |
+
<unverified>0</unverified>
|
159 |
+
</accounts_link>
|
160 |
+
</oneall_singlesignon>
|
161 |
+
</default>
|
162 |
+
</config>
|
app/code/community/OneAll/SingleSignOn/etc/system.xml
ADDED
@@ -0,0 +1,228 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<config>
|
3 |
+
<tabs>
|
4 |
+
<oneall translate="label">
|
5 |
+
<label>OneAll</label>
|
6 |
+
<sort_order>200</sort_order>
|
7 |
+
</oneall>
|
8 |
+
</tabs>
|
9 |
+
<sections>
|
10 |
+
<oneall_singlesignon>
|
11 |
+
<label>OneAll Single Sign-On</label>
|
12 |
+
<tab>oneall</tab>
|
13 |
+
<frontend_type>text</frontend_type>
|
14 |
+
<sort_order>260</sort_order>
|
15 |
+
<show_in_default>1</show_in_default>
|
16 |
+
<show_in_website>1</show_in_website>
|
17 |
+
<show_in_store>1</show_in_store>
|
18 |
+
<groups>
|
19 |
+
<documentation translate="label">
|
20 |
+
<label>Requirements</label>
|
21 |
+
<comment><![CDATA[Please note a OneAll site with a <a href="http://www.oneall.com/pricing-and-plans/#business-plans" target="_blank">Silver Plan</a> is required in order to use this extension. You only need one plan to enable SSO on all of your Magento shops.]]></comment>
|
22 |
+
<sort_order>1</sort_order>
|
23 |
+
<show_in_default>1</show_in_default>
|
24 |
+
<show_in_website>1</show_in_website>
|
25 |
+
<show_in_store>1</show_in_store>
|
26 |
+
<expanded>1</expanded>
|
27 |
+
</documentation>
|
28 |
+
<connection translate="label">
|
29 |
+
<label>API Connection Handler</label>
|
30 |
+
<comment><![CDATA[<p><strong>For security reasons we recommend using PHP CURL and HTTPS on port 443.</strong></p>]]></comment>
|
31 |
+
<frontend_type>Radios</frontend_type>
|
32 |
+
<frontend_model>oneall_singlesignon/adminhtml_system_config_fieldset_general</frontend_model>
|
33 |
+
<sort_order>2</sort_order>
|
34 |
+
<show_in_default>1</show_in_default>
|
35 |
+
<show_in_website>1</show_in_website>
|
36 |
+
<show_in_store>1</show_in_store>
|
37 |
+
<expanded>1</expanded>
|
38 |
+
<fields>
|
39 |
+
<handler>
|
40 |
+
<label>Connection Handler</label>
|
41 |
+
<frontend_type>select</frontend_type>
|
42 |
+
<source_model>oneall_singlesignon/apiconnectionhandler
|
43 |
+
</source_model>
|
44 |
+
<sort_order>1</sort_order>
|
45 |
+
<show_in_default>1</show_in_default>
|
46 |
+
<show_in_website>1</show_in_website>
|
47 |
+
<show_in_store>1</show_in_store>
|
48 |
+
</handler>
|
49 |
+
<port>
|
50 |
+
<label>Connection Port</label>
|
51 |
+
<frontend_type>select</frontend_type>
|
52 |
+
<source_model>oneall_singlesignon/apiconnectionport</source_model>
|
53 |
+
<sort_order>2</sort_order>
|
54 |
+
<show_in_default>1</show_in_default>
|
55 |
+
<show_in_website>1</show_in_website>
|
56 |
+
<show_in_store>1</show_in_store>
|
57 |
+
</port>
|
58 |
+
<autodetect>
|
59 |
+
<frontend_type>Button</frontend_type>
|
60 |
+
<comment>
|
61 |
+
<model>oneall_singlesignon/apiautodetect</model>
|
62 |
+
</comment>
|
63 |
+
<source_model>oneall_singlesignon/apiautodetect</source_model>
|
64 |
+
<sort_order>3</sort_order>
|
65 |
+
<show_in_default>1</show_in_default>
|
66 |
+
<show_in_website>1</show_in_website>
|
67 |
+
<show_in_store>1</show_in_store>
|
68 |
+
</autodetect>
|
69 |
+
</fields>
|
70 |
+
</connection>
|
71 |
+
<general translate="label">
|
72 |
+
<label>API Settings</label>
|
73 |
+
<comment><![CDATA[<p><strong>You can create and view your API Credentials in your <a href="https://app.oneall.com/signin/" target="_blank">OneAll account</a>.</strong></p><p><strong>Please make sure to use the same settings in all the shops that you want to link together using SSO.</strong></p>]]></comment>
|
74 |
+
<frontend_type>text</frontend_type>
|
75 |
+
<frontend_model>oneall_singlesignon/adminhtml_system_config_fieldset_general</frontend_model>
|
76 |
+
<sort_order>3</sort_order>
|
77 |
+
<show_in_default>1</show_in_default>
|
78 |
+
<show_in_website>1</show_in_website>
|
79 |
+
<show_in_store>1</show_in_store>
|
80 |
+
<expanded>1</expanded>
|
81 |
+
<fields>
|
82 |
+
<subdomain>
|
83 |
+
<label>API Subdomain</label>
|
84 |
+
<frontend_type>text</frontend_type>
|
85 |
+
<backend_model>oneall_singlesignon/subdomain</backend_model>
|
86 |
+
<sort_order>1</sort_order>
|
87 |
+
<show_in_default>1</show_in_default>
|
88 |
+
<show_in_website>1</show_in_website>
|
89 |
+
<show_in_store>1</show_in_store>
|
90 |
+
</subdomain>
|
91 |
+
<key>
|
92 |
+
<label>API Public Key</label>
|
93 |
+
<frontend_type>text</frontend_type>
|
94 |
+
<sort_order>2</sort_order>
|
95 |
+
<show_in_default>1</show_in_default>
|
96 |
+
<show_in_website>1</show_in_website>
|
97 |
+
<show_in_store>1</show_in_store>
|
98 |
+
</key>
|
99 |
+
<secret>
|
100 |
+
<label>API Private Key</label>
|
101 |
+
<frontend_type>text</frontend_type>
|
102 |
+
<sort_order>3</sort_order>
|
103 |
+
<show_in_default>1</show_in_default>
|
104 |
+
<show_in_website>1</show_in_website>
|
105 |
+
<show_in_store>1</show_in_store>
|
106 |
+
</secret>
|
107 |
+
<verify>
|
108 |
+
<label></label>
|
109 |
+
<frontend_type>Button</frontend_type>
|
110 |
+
<comment>
|
111 |
+
<model>oneall_singlesignon/apiverify</model>
|
112 |
+
</comment>
|
113 |
+
<source_model>oneall_singlesignon/apiverify</source_model>
|
114 |
+
<sort_order>4</sort_order>
|
115 |
+
<show_in_default>1</show_in_default>
|
116 |
+
<show_in_website>1</show_in_website>
|
117 |
+
<show_in_store>1</show_in_store>
|
118 |
+
</verify>
|
119 |
+
</fields>
|
120 |
+
</general>
|
121 |
+
<accounts_create translate="label">
|
122 |
+
<label>Automatic Account Creation</label>
|
123 |
+
<comment><![CDATA[<p><strong>Automatically creates new customer accounts for SSO users that do not have an account in this shop yet and logs the users in with these accounts.</p></strong>]]></comment>
|
124 |
+
<frontend_type>text</frontend_type>
|
125 |
+
<frontend_model>oneall_singlesignon/adminhtml_system_config_fieldset_general</frontend_model>
|
126 |
+
<sort_order>5</sort_order>
|
127 |
+
<show_in_default>1</show_in_default>
|
128 |
+
<show_in_website>1</show_in_website>
|
129 |
+
<show_in_store>1</show_in_store>
|
130 |
+
<expanded>1</expanded>
|
131 |
+
<fields>
|
132 |
+
<automatic>
|
133 |
+
<label>Automatically create accounts?</label>
|
134 |
+
<frontend_type>select</frontend_type>
|
135 |
+
<source_model>oneall_singlesignon/autocreateaccounts</source_model>
|
136 |
+
<sort_order>1</sort_order>
|
137 |
+
<show_in_default>1</show_in_default>
|
138 |
+
<show_in_website>1</show_in_website>
|
139 |
+
<show_in_store>1</show_in_store>
|
140 |
+
</automatic>
|
141 |
+
<sendmail>
|
142 |
+
<label>Send email to new customers?</label>
|
143 |
+
<frontend_type>select</frontend_type>
|
144 |
+
<source_model>oneall_singlesignon/autocreatesendmail</source_model>
|
145 |
+
<sort_order>2</sort_order>
|
146 |
+
<show_in_default>1</show_in_default>
|
147 |
+
<show_in_website>1</show_in_website>
|
148 |
+
<show_in_store>1</show_in_store>
|
149 |
+
</sendmail>
|
150 |
+
</fields>
|
151 |
+
</accounts_create>
|
152 |
+
<accounts_link translate="label">
|
153 |
+
<label>Automatic Account Link</label>
|
154 |
+
<comment><![CDATA[<p><strong>Tries to automatically link SSO users to already existing customer accounts. To link accounts the email address of the SSO session is matched against the email addresses of the existing customers.</strong></p><p><strong>If the extension finds an existing account but cannot link the SSO user to it (eg. if the option is disabled), a notice reminding the user of his existing account will be displayed on the login/registration page instead.</strong></p>]]></comment>
|
155 |
+
<frontend_type>text</frontend_type>
|
156 |
+
<frontend_model>oneall_singlesignon/adminhtml_system_config_fieldset_general</frontend_model>
|
157 |
+
<sort_order>5</sort_order>
|
158 |
+
<show_in_default>1</show_in_default>
|
159 |
+
<show_in_website>1</show_in_website>
|
160 |
+
<show_in_store>1</show_in_store>
|
161 |
+
<expanded>1</expanded>
|
162 |
+
<fields>
|
163 |
+
<automatic>
|
164 |
+
<label>Automatically link accounts?</label>
|
165 |
+
<frontend_type>select</frontend_type>
|
166 |
+
<source_model>oneall_singlesignon/autolinkaccounts</source_model>
|
167 |
+
<sort_order>1</sort_order>
|
168 |
+
<show_in_default>1</show_in_default>
|
169 |
+
<show_in_website>1</show_in_website>
|
170 |
+
<show_in_store>1</show_in_store>
|
171 |
+
</automatic>
|
172 |
+
<unverified>
|
173 |
+
<label>Link using unverified emails?</label>
|
174 |
+
<comment><![CDATA[<strong>Attention!</strong> For security reasons, we advise against using unverified email addresses to link accounts.]]></comment>
|
175 |
+
<frontend_type>select</frontend_type>
|
176 |
+
<source_model>oneall_singlesignon/autolinkunverified</source_model>
|
177 |
+
<sort_order>2</sort_order>
|
178 |
+
<show_in_default>1</show_in_default>
|
179 |
+
<show_in_website>1</show_in_website>
|
180 |
+
<show_in_store>1</show_in_store>
|
181 |
+
</unverified>
|
182 |
+
</fields>
|
183 |
+
</accounts_link>
|
184 |
+
<settings translate="label">
|
185 |
+
<label>SSO Session Settings</label>
|
186 |
+
<frontend_type>text</frontend_type>
|
187 |
+
<frontend_model>oneall_singlesignon/adminhtml_system_config_fieldset_general</frontend_model>
|
188 |
+
<sort_order>6</sort_order>
|
189 |
+
<show_in_default>1</show_in_default>
|
190 |
+
<show_in_website>1</show_in_website>
|
191 |
+
<show_in_store>1</show_in_store>
|
192 |
+
<expanded>1</expanded>
|
193 |
+
<fields>
|
194 |
+
<sessionlifetime>
|
195 |
+
<label>SSO Session Lifetime</label>
|
196 |
+
<comment>Sessions are automatically queued for deletion once their lifetime has expired.</comment>
|
197 |
+
<frontend_type>select</frontend_type>
|
198 |
+
<source_model>oneall_singlesignon/sessionlifetime</source_model>
|
199 |
+
<sort_order>1</sort_order>
|
200 |
+
<show_in_default>1</show_in_default>
|
201 |
+
<show_in_website>1</show_in_website>
|
202 |
+
<show_in_store>1</show_in_store>
|
203 |
+
</sessionlifetime>
|
204 |
+
<sessiontoprealm>
|
205 |
+
<label>SSO Session Top Realm</label>
|
206 |
+
<comment>Optional - The primary realm of the SSO sessions generated for customers of this Magento shop.</comment>
|
207 |
+
<frontend_type>text</frontend_type>
|
208 |
+
<sort_order>2</sort_order>
|
209 |
+
<show_in_default>1</show_in_default>
|
210 |
+
<show_in_website>1</show_in_website>
|
211 |
+
<show_in_store>1</show_in_store>
|
212 |
+
</sessiontoprealm>
|
213 |
+
<sessionsubrealm>
|
214 |
+
<backend_model>oneall_singlesignon/sessionsubrealm</backend_model>
|
215 |
+
<label>SSO Session Sub Realm</label>
|
216 |
+
<comment>Optional - The secondary realm of the SSO sessions generated for customers of this Magento shop.</comment>
|
217 |
+
<frontend_type>text</frontend_type>
|
218 |
+
<sort_order>3</sort_order>
|
219 |
+
<show_in_default>1</show_in_default>
|
220 |
+
<show_in_website>1</show_in_website>
|
221 |
+
<show_in_store>1</show_in_store>
|
222 |
+
</sessionsubrealm>
|
223 |
+
</fields>
|
224 |
+
</settings>
|
225 |
+
</groups>
|
226 |
+
</oneall_singlesignon>
|
227 |
+
</sections>
|
228 |
+
</config>
|
app/code/community/OneAll/SingleSignOn/sql/oneall_singlesignon_setup/mysql4-install-1.0.0.php
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// Start Installer.
|
27 |
+
$installer = $this;
|
28 |
+
$installer->startSetup ();
|
29 |
+
|
30 |
+
// Table to store the customer's sso_session_token.
|
31 |
+
$installer->run ("
|
32 |
+
|
33 |
+
CREATE TABLE IF NOT EXISTS `" . $this->getTable ('oneall_singlesignon/session') . "` (
|
34 |
+
`customer_id` int(11) UNSIGNED NOT NULL,
|
35 |
+
`sso_session_token` char(36) NOT NULL,
|
36 |
+
`added_at` datetime default NULL,
|
37 |
+
`modified_at` datetime default NULL,
|
38 |
+
PRIMARY KEY (`customer_id`)
|
39 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='OneAll Single Sign-On Session';
|
40 |
+
|
41 |
+
");
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
// Table to store the customer's user_token/identity_token.
|
46 |
+
$installer->run ("
|
47 |
+
|
48 |
+
CREATE TABLE IF NOT EXISTS `" . $this->getTable ('oneall_singlesignon/user') . "` (
|
49 |
+
`customer_id` int(11) UNSIGNED NOT NULL,
|
50 |
+
`user_token` char(36) NOT NULL,
|
51 |
+
`identity_token` char(36) NOT NULL,
|
52 |
+
`added_at` datetime default NULL,
|
53 |
+
`modified_at` datetime default NULL,
|
54 |
+
PRIMARY KEY (`customer_id`)
|
55 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='OneAll Single Sign-On Users';
|
56 |
+
|
57 |
+
");
|
58 |
+
|
59 |
+
// End Installer.
|
60 |
+
$installer->endSetup ();
|
app/design/frontend/base/default/layout/oneall-singlesignon.xml
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout version="0.1.0">
|
3 |
+
<customer_logged_out>
|
4 |
+
<reference name="head">
|
5 |
+
<block type="core/template" name="oneall.singlesignon.loggedout" template="oneall/singlesignon/loggedout.phtml" />
|
6 |
+
</reference>
|
7 |
+
</customer_logged_out>
|
8 |
+
<customer_logged_in>
|
9 |
+
<reference name="head">
|
10 |
+
<block type="core/template" name="oneall.singlesignon.loggedin" template="oneall/singlesignon/loggedin.phtml" />
|
11 |
+
</reference>
|
12 |
+
</customer_logged_in>
|
13 |
+
</layout>
|
app/design/frontend/base/default/template/oneall/singlesignon/loggedin.phtml
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// Encapsulate
|
27 |
+
if (!function_exists ('oneall_singlesignon_run_loggedin'))
|
28 |
+
{
|
29 |
+
function oneall_singlesignon_run_loggedin ()
|
30 |
+
{
|
31 |
+
// Read Settings
|
32 |
+
$settings = Mage::helper ('oneall_singlesignon')->get_settings ();
|
33 |
+
|
34 |
+
// If it's empty the extension has not been setup yet
|
35 |
+
if (!empty ($settings ['subdomain']))
|
36 |
+
{
|
37 |
+
// Read Customer
|
38 |
+
$customer = Mage::getSingleton ('customer/session')->getCustomer ();
|
39 |
+
|
40 |
+
// Check if we have a sso_session_token for this customer
|
41 |
+
$session = Mage::getModel ('oneall_singlesignon/session')->load ($customer->getId (), 'customer_id');
|
42 |
+
$sso_session_token = $session->sso_session_token;
|
43 |
+
|
44 |
+
// Token Found
|
45 |
+
if (!empty ($sso_session_token))
|
46 |
+
{
|
47 |
+
// Build SSO JavaScript
|
48 |
+
$data = array();
|
49 |
+
$data [] = "<!-- OneAll.com / Single Sign-On for Magento -->";
|
50 |
+
$data [] = "<script type=\"text/javascript\">";
|
51 |
+
$data [] = "//<![CDATA[";
|
52 |
+
$data [] = " var have_oa_lib = (have_oa_lib || false);";
|
53 |
+
$data [] = " (function(){if (!have_oa_lib){";
|
54 |
+
$data [] = " var lib = document.createElement('script');";
|
55 |
+
$data [] = " lib.type = 'text/javascript'; lib.async = true;";
|
56 |
+
$data [] = " lib.src = '//" . $settings ['base_url'] . "/socialize/library.js';";
|
57 |
+
$data [] = " var node = document.getElementsByTagName('script')[0];";
|
58 |
+
$data [] = " node.parentNode.insertBefore(lib, node); have_oa_lib = true;";
|
59 |
+
$data [] = " }})();";
|
60 |
+
$data [] = " var _oneall = (_oneall || []);";
|
61 |
+
$data [] = " _oneall.push(['single_sign_on', 'do_register_sso_session', '" . $sso_session_token . "']);";
|
62 |
+
$data [] = "//]]>";
|
63 |
+
$data [] = "</script>";
|
64 |
+
$data [] = "";
|
65 |
+
|
66 |
+
// Add SSO JavaScript
|
67 |
+
echo implode ("\n", $data);
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
}
|
72 |
+
|
73 |
+
// Run
|
74 |
+
oneall_singlesignon_run_loggedin ();
|
app/design/frontend/base/default/template/oneall/singlesignon/loggedout.phtml
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package OneAll Single Sign-On
|
4 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
5 |
+
* @license GNU/GPL 2 or later
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or
|
8 |
+
* modify it under the terms of the GNU General Public License
|
9 |
+
* as published by the Free Software Foundation; either version 2
|
10 |
+
* of the License, or (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program; if not, write to the Free Software
|
19 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
+
*
|
21 |
+
* The "GNU General Public License" (GPL) is available at
|
22 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
|
26 |
+
// Encapsulate
|
27 |
+
if (!function_exists ('oneall_singlesignon_run_loggedout'))
|
28 |
+
{
|
29 |
+
function oneall_singlesignon_run_loggedout ()
|
30 |
+
{
|
31 |
+
// Read Settings
|
32 |
+
$settings = Mage::helper ('oneall_singlesignon')->get_settings ();
|
33 |
+
|
34 |
+
// If it's empty the extension has not been setup yet
|
35 |
+
if (!empty ($settings ['subdomain']))
|
36 |
+
{
|
37 |
+
// Check if we need to login by SSO
|
38 |
+
$status = Mage::helper ('oneall_singlesignon')->check_for_sso_login ();
|
39 |
+
|
40 |
+
// Nothing has been done
|
41 |
+
switch (strtolower ($status->action))
|
42 |
+
{
|
43 |
+
// //////////////////////////////////////////////////////////////////////////
|
44 |
+
// No user found and we cannot add users
|
45 |
+
// //////////////////////////////////////////////////////////////////////////
|
46 |
+
case 'new_user_no_login_autocreate_off' :
|
47 |
+
|
48 |
+
// Add Log
|
49 |
+
Mage::helper ('oneall_singlesignon')->add_log ('[SSO: run_loggedout] New user detected but account creation is disabled');
|
50 |
+
|
51 |
+
// This value prevents SSO from re-trying to login the user.
|
52 |
+
Mage::getSingleton ('core/session')->setSSOGracePeriod (time () + 3600);
|
53 |
+
|
54 |
+
break;
|
55 |
+
|
56 |
+
// //////////////////////////////////////////////////////////////////////////
|
57 |
+
// User found and logged in
|
58 |
+
// //////////////////////////////////////////////////////////////////////////
|
59 |
+
|
60 |
+
// Logged in using the user_token
|
61 |
+
case 'existing_user_login_user_token' :
|
62 |
+
|
63 |
+
// Add Log
|
64 |
+
Mage::helper ('oneall_singlesignon')->add_log ('[SSO: run_loggedout] Existing user recognized by user_token ['.$status->user_token.']');
|
65 |
+
|
66 |
+
// Logged in using a verified email address
|
67 |
+
case 'existing_user_login_email_verified' :
|
68 |
+
|
69 |
+
// Logged in using an un-verified email address
|
70 |
+
case 'existing_user_login_email_unverified' :
|
71 |
+
|
72 |
+
// Remove these
|
73 |
+
Mage::getSingleton ('core/session')->unsSSOEmail ();
|
74 |
+
Mage::getSingleton ('core/session')->unsSSOGracePeriod ();
|
75 |
+
|
76 |
+
break;
|
77 |
+
|
78 |
+
// //////////////////////////////////////////////////////////////////////////
|
79 |
+
// User found, but we cannot log him in
|
80 |
+
// //////////////////////////////////////////////////////////////////////////
|
81 |
+
|
82 |
+
// Customer found, but autolink disabled
|
83 |
+
case 'existing_user_no_login_autolink_off' :
|
84 |
+
|
85 |
+
// Customer found, but autolink disabled for unverified emails
|
86 |
+
case 'existing_user_no_login_autolink_off_unverified_emails' :
|
87 |
+
|
88 |
+
// This value prevents SSO from re-trying to login the user.
|
89 |
+
Mage::getSingleton ('core/session')->setSSOGracePeriod (time () + 3600);
|
90 |
+
|
91 |
+
// This value is a hint for the user, used in OneAll_SingleSignOn_Model_Observer
|
92 |
+
Mage::getSingleton ('core/session')->setSSOEmail ($status->customer->getEmail ());
|
93 |
+
|
94 |
+
// Login Page URL
|
95 |
+
$login_page_url = Mage::getUrl ('customer/account/login');
|
96 |
+
|
97 |
+
// Redirect
|
98 |
+
Mage::app ()->getFrontController ()->getResponse ()->setRedirect ($login_page_url);
|
99 |
+
|
100 |
+
break;
|
101 |
+
|
102 |
+
// //////////////////////////////////////////////////////////////////////////
|
103 |
+
// Default
|
104 |
+
// //////////////////////////////////////////////////////////////////////////
|
105 |
+
default :
|
106 |
+
|
107 |
+
// Read data
|
108 |
+
$sso_grace_period = intval (Mage::getSingleton ('core/session')->getSSOGracePeriod ());
|
109 |
+
|
110 |
+
// If this value is in the future, we should not try to login the user with SSO
|
111 |
+
if ($sso_grace_period < time ())
|
112 |
+
{
|
113 |
+
// Build SSO JavaScript
|
114 |
+
$data = array();
|
115 |
+
$data [] = "<!-- OneAll.com / Single Sign-On for Magento -->";
|
116 |
+
$data [] = "<script type=\"text/javascript\">";
|
117 |
+
$data [] = "//<![CDATA[";
|
118 |
+
$data [] = " var have_oa_lib = (have_oa_lib || false);";
|
119 |
+
$data [] = " (function(){if (!have_oa_lib){";
|
120 |
+
$data [] = " var lib = document.createElement('script');";
|
121 |
+
$data [] = " lib.type = 'text/javascript'; lib.async = true;";
|
122 |
+
$data [] = " lib.src = '//" . $settings ['base_url'] . "/socialize/library.js';";
|
123 |
+
$data [] = " var node = document.getElementsByTagName('script')[0];";
|
124 |
+
$data [] = " node.parentNode.insertBefore(lib, node); have_oa_lib = true;";
|
125 |
+
$data [] = " }})();";
|
126 |
+
$data [] = " var _oneall = (_oneall || []);";
|
127 |
+
$data [] = " _oneall.push(['single_sign_on', 'set_callback_uri', window.location.href]);";
|
128 |
+
$data [] = " _oneall.push(['single_sign_on', 'do_check_for_sso_session']);";
|
129 |
+
$data [] = "//]]>";
|
130 |
+
$data [] = "</script>";
|
131 |
+
$data [] = "";
|
132 |
+
|
133 |
+
// Add SSO JavaScript
|
134 |
+
echo implode ("\n", $data);
|
135 |
+
}
|
136 |
+
|
137 |
+
break;
|
138 |
+
}
|
139 |
+
}
|
140 |
+
}
|
141 |
+
}
|
142 |
+
|
143 |
+
// Run
|
144 |
+
oneall_singlesignon_run_loggedout ();
|
app/etc/modules/OneAll_SingleSignOn.xml
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* @package OneAll Single Sign-On
|
5 |
+
* @copyright Copyright 2011-2017 http://www.oneall.com/
|
6 |
+
* @license GNU/GPL 2 or later
|
7 |
+
*
|
8 |
+
* This program is free software; you can redistribute it and/or
|
9 |
+
* modify it under the terms of the GNU General Public License
|
10 |
+
* as published by the Free Software Foundation; either version 2
|
11 |
+
* of the License, or (at your option) any later version.
|
12 |
+
*
|
13 |
+
* This program is distributed in the hope that it will be useful,
|
14 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
+
* GNU General Public License for more details.
|
17 |
+
*
|
18 |
+
* You should have received a copy of the GNU General Public License
|
19 |
+
* along with this program; if not, write to the Free Software
|
20 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
+
*
|
22 |
+
* The "GNU General Public License" (GPL) is available at
|
23 |
+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
24 |
+
*
|
25 |
+
*/
|
26 |
+
-->
|
27 |
+
<config>
|
28 |
+
<modules>
|
29 |
+
<OneAll_SingleSignOn>
|
30 |
+
<active>true</active>
|
31 |
+
<codePool>community</codePool>
|
32 |
+
<version>1.0.0</version>
|
33 |
+
</OneAll_SingleSignOn>
|
34 |
+
</modules>
|
35 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>OneAll_SingleSignOn</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license>GNU/GPL 2 or later</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Single Sign-On automatically signs users in as they browse between multiple and independent Magento shops in your network.</summary>
|
10 |
+
<description>Single Sign On for Magento is a professional extension that automatically signs users in as they browse between multiple and independent Magento shops in your network. 
|
11 |
+

|
12 |
+
Take away the need for your users to re-enter their authentication credentials when they switch from one of your shops to another. 
|
13 |
+

|
14 |
+
100% compliant with all European and U.S. data protection laws.</description>
|
15 |
+
<notes>First Release</notes>
|
16 |
+
<authors><author><name>OneAll</name><user>OneAll</user><email>support@oneall.com</email></author></authors>
|
17 |
+
<date>2017-02-28</date>
|
18 |
+
<time>08:47:07</time>
|
19 |
+
<contents><target name="magecommunity"><dir name="OneAll"><dir name="SingleSignOn"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Fieldset"><file name="General.php" hash="c0ab442fad34120c4f447e957498f520"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="c932884755691f417cc42f78880fec36"/></dir><dir name="Model"><file name="Apiautodetect.php" hash="77309fb314cf82fa4c6524244494e9be"/><file name="Apiconnectionhandler.php" hash="b696454def7320d66938e887bea468a1"/><file name="Apiconnectionport.php" hash="fa1fe1f691b69180dfedc624bd16af75"/><file name="Apiverify.php" hash="62000fb9d727cdbfd1bc6c3037dc94c8"/><file name="Autocreateaccounts.php" hash="0aad711237ef95d85fcd5d17d60e3b91"/><file name="Autocreatesendmail.php" hash="eefa63f837e7c707689746ec0119fcbb"/><file name="Autolinkaccounts.php" hash="762758fb233062704ae4844639d2e02c"/><file name="Autolinkunverified.php" hash="3e1c290dc39905cd79136a1244e4604c"/><file name="Observer.php" hash="a82ae4be803983fbb90538866cf5fe61"/><dir name="Resource"><dir name="Session"><file name="Collection.php" hash="1ddb59ee1f6677b380fad4224cafbf85"/></dir><file name="Session.php" hash="8bca89bf0b0cd5f71134c9bb66e40cda"/><dir name="User"><file name="Collection.php" hash="1898d23e804507c371abf458fbdd0954"/></dir><file name="User.php" hash="25915ca37a5bc4682af2a0ddef1deb9f"/></dir><file name="Session.php" hash="336fb93596fa553f7163f2b4c04be48d"/><file name="Sessionlifetime.php" hash="ec23a29cf067b92a952bf40a492fc1ca"/><file name="Sessionsubrealm.php" hash="948d60beaad0ce5332ea3ee477a8ce34"/><file name="Subdomain.php" hash="b4850aa3c34c745d67846f9b0e80863e"/><file name="User.php" hash="19381f561be295b4f5edc9e8d1efce53"/></dir><dir name="controllers"><file name="AjaxController.php" hash="ba491693992ed85cafb3a40ace26c44b"/></dir><dir name="etc"><file name="adminhtml.xml" hash="900b56f9a5d8f38df05f283c6f5d7ff8"/><file name="config.xml" hash="be86c658c30c2871f36f8cc0f4d9216d"/><file name="system.xml" hash="c53735a7be92ad515fec4c2bec272d85"/></dir><dir name="sql"><dir name="oneall_singlesignon_setup"><file name="mysql4-install-1.0.0.php" hash="3d3bc48e2efd8db3c4c4e3d749d5c26f"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="oneall-singlesignon.xml" hash="92eb1a2e374a73402990043c7bdb10b3"/></dir><dir name="template"><dir name="oneall"><dir name="singlesignon"><file name="loggedin.phtml" hash="b36c1ea49ea31faf84d340a76d6eb002"/><file name="loggedout.phtml" hash="ab557c6047def6175e0d7c9a8cabcb55"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="OneAll_SingleSignOn.xml" hash="910eea2b985109eb361dfb448a92fb48"/></dir></target></contents>
|
20 |
+
<compatible/>
|
21 |
+
<dependencies><required><php><min>5.1.0</min><max>7.0.0</max></php></required></dependencies>
|
22 |
+
</package>
|