Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!defined('PATH_typo3conf'))
- die('Could not access this script directly!');
- class MyLoginClass {
- public function main() {
- $extKey = 'myextkey';
- $this->debug = t3lib_extMgm::isLoaded('devlog');
- // force debug off
- $this->debug = FALSE;
- $feUserObject = tslib_eidtools::initFeUser();
- $feUserObject->writeDevLog = TRUE;
- $logintype = t3lib_div::_GP('logintype');
- $backend = tx_rsaauth_backendfactory::getBackend();
- if ($logintype == 'login') {
- if ($this->debug) {
- t3lib_div::devLog('SESSION after login: ' . json_encode($_SESSION), $extKey, 0);
- }
- if ($feUserObject->user) {
- $feUserObject->fetchGroupData();
- $uid = $feUserObject->user['uid'];
- $groupsCount = count($feUserObject->groupData['uid']);
- $groups = $feUserObject->groupData['title'];
- return json_encode(array(
- 'success' => TRUE,
- 'username' => $feUserObject->user['username']
- ));
- } else {
- return json_encode(array(
- 'success' => FALSE,
- 'errors' => array(
- 'reason' => 'Login error.'
- )
- ));
- }
- } elseif ($logintype == 'logout') {
- $feUserObject->logoff();
- } else {
- if ($feUserObject->user) {
- return json_encode(array(
- 'success' => true,
- 'data' => array(
- array(
- 'xtype' => 'displayfield',
- 'value' => $feUserObject->user['username'],
- 'fieldLabel' => 'Username'
- ),
- array(
- 'xtype' => 'displayfield',
- 'value' => $feUserObject->user['email'],
- 'fieldLabel' => 'E-mail'
- ),
- array(
- 'xtype' => 'displayfield',
- 'value' => date('j.n.Y G:i:s T', $feUserObject->user['lastlogin']),
- 'fieldLabel' => 'Last login'
- ),
- array(
- 'xtype' => 'hidden',
- 'name' => 'logintype',
- 'value' => 'logout'
- )
- )
- ));
- } else {
- if (trim($GLOBALS['TYPO3_CONF_VARS']['FE']['loginSecurityLevel']) === 'rsa') {
- if ($backend->isAvailable()) {
- // Generate a new key pair
- $keyPair = $backend->createNewKeyPair();
- // Save private key
- $storage = tx_rsaauth_storagefactory::getStorage();
- /* @var $storage tx_rsaauth_abstract_storage */
- $storage->put($keyPair->getPrivateKey());
- if ($this->debug) {
- t3lib_div::devLog('SESSION before login: ' . json_encode($_SESSION), $extKey, 0);
- }
- $rsa_n = htmlspecialchars($keyPair->getPublicKeyModulus());
- $rsa_e = sprintf('%x', $keyPair->getExponent());
- return json_encode(array(
- 'success' => true,
- 'data' => array(
- array(
- 'xtype' => 'textfield',
- 'name' => 'user',
- 'fieldLabel' => 'Username',
- 'allowBlank' => FALSE,
- blankText => 'Username is empty.'
- ),
- array(
- 'xtype' => 'textfield',
- 'name' => 'pass',
- 'fieldLabel' => 'Password',
- 'allowBlank' => FALSE,
- 'inputType' => 'password',
- blankText => 'Password is empty.'
- ),
- array(
- 'xtype' => 'hidden',
- 'name' => 'logintype',
- 'value' => 'login'
- ),
- array(
- 'xtype' => 'hidden',
- 'name' => 'n',
- 'value' => $rsa_n
- ),
- array(
- 'xtype' => 'hidden',
- 'name' => 'e',
- 'value' => $rsa_e
- )
- )
- ));
- }
- }
- }
- }
- }
- }
- $output = t3lib_div::makeInstance('MyLoginClass');
- echo $output->main();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement