Last active
July 3, 2019 09:20
-
-
Save iamandrewluca/f618c611abb2515fb5f30e4ad9e14e19 to your computer and use it in GitHub Desktop.
Typo3 / Extbase backend / frontend user manual login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin( | |
'MyVendor.' . $_EXTKEY, | |
'my_plugin', | |
array( | |
// My is MyController. myLogin is the action | |
'My' => 'myLogin', | |
), | |
array() | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is how form field names should be. extension and plugin name included. | |
tx_myext_my_plugin[username] | |
tx_myext_my_plugin[password] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyController extends ActionController | |
{ | |
// ... | |
/** | |
* @var \TYPO3\CMS\Extbase\Mvc\View\JsonView | |
*/ | |
protected $view; | |
/** | |
* @var string | |
*/ | |
protected $defaultViewObjectName = JsonView::class; | |
/** | |
* $saltedPasswordService | |
* | |
* @var \TYPO3\CMS\Saltedpasswords\SaltedPasswordService | |
* @inject | |
*/ | |
protected $saltedPasswordService = null; | |
/** | |
* $responseMessage | |
* @var array | |
*/ | |
private $responseMessage = []; | |
function initializeAction() | |
{ | |
parent::initializeAction(); | |
$this->responseMessage['status'] = 'ERROR'; | |
$this->responseMessage['messages'] = []; | |
} | |
/** | |
* my login action | |
* @return string | |
*/ | |
public function myLoginAction() | |
{ | |
if ($this->isUserValid()) { | |
$this->responseMessage['status'] = 'SUCCESS'; | |
} | |
$this->view->assign('value', $this->responseMessage); | |
return $this->view->render(); | |
} | |
/** | |
* @return bool | |
* @internal param array $responseMessage | |
*/ | |
private function isUserValid() | |
{ | |
try { | |
$username = $this->request->getArgument('username'); | |
$password = $this->request->getArgument('password'); | |
} catch (NoSuchArgumentException $ex) { | |
$this->responseMessage['messages'][] = $ex->getMessage(); | |
return false; | |
} | |
$loginData=array( | |
'uname' => $username, | |
'uident_text'=> $password, | |
'status' =>'login' | |
); | |
// $userAuth = $this->objectManager->get(FrontendUserAuthentication::class); | |
$userAuth = $this->objectManager->get(BackendUserAuthentication::class); | |
$userAuth->checkPid = false; | |
$info = $userAuth->getAuthInfoArray(); | |
$user = $userAuth->fetchUserRecord($info['db_user'], $loginData['uname']); | |
if (!$user) { | |
$this->responseMessage['messages'][] = 'Invalid user'; | |
return $user; | |
} | |
$isValidLoginData = $this->saltedPasswordService->compareUident($user, $loginData); | |
if (!$isValidLoginData) { | |
$this->responseMessage['messages'][] = 'Invalid password'; | |
return $isValidLoginData; | |
} | |
return $isValidLoginData; | |
} | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
'preVars' => array( | |
0 => array( | |
'GETvar' => 'type', | |
'valueMap' => array( | |
// mysite.com/requestpath | |
'requestpath' => 1452982642, | |
), | |
'noMatch' => 'bypass', | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// https://typo3.org/documentation/snippets/sd/227/ | |
$loginData = array( | |
'uname' => 'johndoe', //usernmae | |
'uident_text'=> 'mypassword', //password | |
'status' =>'login' | |
); | |
//do not use a particular pid | |
$GLOBALS['TSFE']->fe_user->checkPid = false; | |
$info = $GLOBALS['TSFE']->fe_user->getAuthInfoArray(); | |
$user = $GLOBALS['TSFE']->fe_user->fetchUserRecord($info['db_user'] ,$loginData['uname']); | |
$ok = $GLOBALS['TSFE']->fe_user->compareUident($user, $loginData); | |
if ($ok) { | |
//login successfull | |
$GLOBALS['TSFE']->fe_user->createUserSession($user); | |
} else { | |
//login failed | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://usetypo3.com/json-view.html | |
api_tag = PAGE | |
api_tag { | |
config { | |
disableAllHeaderCode = 1 | |
debug = 0 | |
no_cache = 1 | |
} | |
typeNum = 1452982642 | |
10 < tt_content.list.20.myext_my_plugin | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment