This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
/
pydio.php
171 lines (149 loc) · 5.54 KB
/
pydio.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/**
* @version $Id: example.php 11720 2009-03-27 21:27:42Z ian $
* @package Joomla
* @subpackage JFramework
* @copyright Copyright (C) 2010 Charles du Jeu
* @license LGPL
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );
define('AJXP_EXEC', true);
jimport('joomla.event.plugin');
jimport( 'joomla.registry.registry' );
/**
* Pydio User Plugin
*
* @package Joomla
* @subpackage JFramework
* @since 3.0
*/
class plgUserPydio extends JPlugin
{
/**
* Constructor
*
* For php4 compatability we must not use the __constructor as a constructor for plugins
* because func_get_args ( void ) returns a copy of all passed arguments NOT references.
* This causes problems with cross-referencing necessary for the observer design pattern.
*
* @param object $subject The object to observe
* @param array $config An array that holds the plugin configuration
* @since 1.6
*/
public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
$this->_plugin = JPluginHelper::getPlugin( 'user', 'pydio' );
$this->_params = new JRegistry();
$this->_params->loadString($this->_plugin->params);
$this->secret = $this->_params->get("ajxp_secret_key") OR '';
$installPath = $this->_params->get("ajxp_install_path") OR '';
$this->glueCode = $installPath."/plugins/auth.remote/glueCode.php";
$this->glueCodeFound = file_exists($this->glueCode);
$this->autoCreate = $this->_params->get("ajxp_auto_create");
}
/**
* Example store user method
*
* Method is called after user data is stored in the database
*
* @param array holds the new user data
* @param boolean true if a new user is stored
* @param boolean true if user was succesfully stored in the database
* @param string message
*/
public function onUserAfterSave($joomlaUser, $isnew, $success, $msg)
{
global $mainframe;
// convert the user parameters passed to the event
// to a format the external application
if(!$this->glueCodeFound) return false;
if(!$success) return true;
global $AJXP_GLUE_GLOBALS;
$AJXP_GLUE_GLOBALS = array();
$AJXP_GLUE_GLOBALS["secret"] = $this->secret;
$AJXP_GLUE_GLOBALS["user"] = array();
$AJXP_GLUE_GLOBALS["user"]['name'] = $joomlaUser['username'];
$AJXP_GLUE_GLOBALS["user"]['password'] = $joomlaUser['password'];
if($joomlaUser['usertype'] == "Super Administrator" || $joomlaUser['usertype'] == "Administrator" || $joomlaUser["isRoot"]
|| is_array($joomlaUser["groups"]) && in_array("8", $joomlaUser["groups"])){
$AJXP_GLUE_GLOBALS["user"]['right'] = 'admin';
} else {
$AJXP_GLUE_GLOBALS["user"]['right'] = '';
}
$AJXP_GLUE_GLOBALS["plugInAction"] = ($isnew?"addUser":"updateUser");
include($this->glueCode);
return $AJXP_GLUE_GLOBALS["result"];
}
/**
* Example store user method
*
* Method is called after user data is deleted from the database
*
* @param array holds the user data
* @param boolean true if user was succesfully stored in the database
* @param string message
*/
public function onUserAfterDelete($joomlaUser, $succes, $msg)
{
global $mainframe;
// only the $user['id'] exists and carries valid information
// Call a function in the external app to delete the user
// ThirdPartyApp::deleteUser($user['id']);
if(!$this->glueCodeFound) return false;
if(!$succes) return true;
global $AJXP_GLUE_GLOBALS;
$AJXP_GLUE_GLOBALS = array();
$AJXP_GLUE_GLOBALS["secret"] = $this->secret;
$AJXP_GLUE_GLOBALS["userName"] = $joomlaUser['username'];
$AJXP_GLUE_GLOBALS["plugInAction"] = "delUser";
include($this->glueCode);
return true;
}
/**
* This method should handle any login logic and report back to the subject
*
* @access public
* @param array holds the user data
* @param array extra options
* @return boolean True on success
* @since 1.6
*/
public function onUserLogin($user, $options)
{
// Initialize variables
$success = false;
if(!$this->glueCodeFound) return false;
global $AJXP_GLUE_GLOBALS;
$AJXP_GLUE_GLOBALS = array();
//$plugInAction, $login, $result, $secret, $autoCreate;
$AJXP_GLUE_GLOBALS["secret"] = $this->secret;
$AJXP_GLUE_GLOBALS["autoCreate"] = $this->autoCreate;
$AJXP_GLUE_GLOBALS["plugInAction"] = "login";
$AJXP_GLUE_GLOBALS["login"] = array("name"=>$user["username"], "password"=>$user["password"]);
include($this->glueCode);
new SessionSwitcher("previous", false, true);
return true;
}
/**
* This method should handle any logout logic and report back to the subject
*
* @access public
* @param array holds the user data
* @return boolean True on success
* @since 1.6
*/
public function onUserLogout($user)
{
// Initialize variables
$success = false;
if(!$this->glueCodeFound) return false;
global $AJXP_GLUE_GLOBALS;
$AJXP_GLUE_GLOBALS = array();
$AJXP_GLUE_GLOBALS["secret"] = $this->secret;
$AJXP_GLUE_GLOBALS["plugInAction"] = "logout";
include($this->glueCode);
return $AJXP_GLUE_GLOBALS["result"];
}
}