Skip to content
Snippets Groups Projects
Select Git revision
  • 5610842e5669ed17983d219f6c779316f209ba92
  • master default protected
2 results

COPYING-AGPL

Blame
  • user.php 14.65 KiB
    <?php
    /**
     * ownCloud
     *
     * @author Frank Karlitschek
     * @copyright 2012 Frank Karlitschek frank@owncloud.org
     *
     * This library is free software; you can redistribute it and/or
     * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
     * License as published by the Free Software Foundation; either
     * version 3 of the License, or any later version.
     *
     * This library is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
     *
     * You should have received a copy of the GNU Affero General Public
     * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     *
     */
    
    /**
     * This class provides wrapper methods for user management. Multiple backends are
     * supported. User management operations are delegated to the configured backend for
     * execution.
     *
     * Hooks provided:
     *   pre_createUser(&run, uid, password)
     *   post_createUser(uid, password)
     *   pre_deleteUser(&run, uid)
     *   post_deleteUser(uid)
     *   pre_setPassword(&run, uid, password, recoveryPassword)
     *   post_setPassword(uid, password, recoveryPassword)
     *   pre_login(&run, uid, password)
     *   post_login(uid)
     *   logout()
     */
    class OC_User {
    	public static $userSession = null;
    
    	private static function getUserSession() {
    		if (!self::$userSession) {
    			$manager = new \OC\User\Manager();
    			self::$userSession = new \OC\User\Session($manager, \OC::$session);
    			self::$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
    				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
    			});
    			self::$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
    				/** @var $user \OC\User\User */
    				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
    			});
    			self::$userSession->listen('\OC\User', 'preDelete', function ($user) {
    				/** @var $user \OC\User\User */
    				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
    			});
    			self::$userSession->listen('\OC\User', 'postDelete', function ($user) {
    				/** @var $user \OC\User\User */
    				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
    			});
    			self::$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
    				/** @var $user \OC\User\User */
    				OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
    			});
    			self::$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
    				/** @var $user \OC\User\User */
    				OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
    			});
    			self::$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
    				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));