TYPO3 - 以编程方式创建用户

时间:2013-06-08 18:45:59

标签: php typo3

是否可以在typo3扩展程序中以编程方式(不带SQL )创建或删除用户?

2 个答案:

答案 0 :(得分:2)

对于CRUD前端用户(fe_users),已经存在可用于您自己的Extbase扩展的存储库和模型。下面...

TYPO3 / sysext / extbase /类别/域

您可以找到模型和存储库类。

答案 1 :(得分:1)

一些代码示例:

function createUser() {
    // TypoScript Template mit userid anlegen
    // Neue Seite anlegen
    $tmpId = 'NEWuser478d8d';
    $data['be_users'][$tmpId] = array(
        'username' => $this->email,
        'password' => $this->password,
        'admin' => 0,
        'pid' => 0,
        'usergroup' => $this->usergroup,
        'lang' => 'de',
        'email' => $this->email,
        'db_mountpoints' => '',
        'realName' => $this->realName,
        'file_mountpoints' => '',
        'fileoper_perms' => (int)$this->conf['fileoper_perms'],
        'options' => '2', // mount from group: filemount, aber nicht dbmount
        'db_mountpoints' => $this->dbMountPage,
        'file_mountpoints' => $this->conf['file_mountpoints'],
        'workspace_perms' => 0,
        'workspace_id' => 0,
        'workspace_preview' => 0
    );
    $this->debug($data, 'beuser');
    $this->tce->start($data,array());
    $this->tce->process_datamap();
    $this->userid =  $this->tce->substNEWwithIDs[$tmpId];
    // t3lib_div::debug('Neue Userid:'.$this->userid);
    return true;
}

你需要一个活跃的be-user,所以创建一个:

/**
 *  Creates a Be-User
 *
 *  @return     void
 */
function setBeUser() {
    global $BE_USER;
    unset($BE_USER);
    $BE_USER        = t3lib_div::makeInstance('t3lib_beUserAuth');
    $BE_USER->OS    = TYPO3_OS;
    $BE_USER->setBeUserByUid($this->conf['setBeUserByUid']);
    $BE_USER->fetchGroupData();
    $BE_USER->backendSetUC();

    $GLOBALS['BE_USER'] = $BE_USER;

    $GLOBALS['LANG'] = t3lib_div::makeInstance('language');
    $GLOBALS['LANG']->init($BE_USER->uc['lang']);

    return $BE_USER;
}

init tce:

$this->tce = t3lib_div::makeInstance('t3lib_TCEmain');
$this->tce->BE_USER = $this->setBeUser();
$this->tce->stripslashes_values = 0;
$this->createUser();