Skip to content

Commit

Permalink
Fix Ajax response
Browse files Browse the repository at this point in the history
  • Loading branch information
realsmartnose committed Sep 23, 2023
1 parent e3676dc commit e398ffd
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 85 deletions.
36 changes: 31 additions & 5 deletions Classes/Authentication/GpsNoseBasedAuthenticationService.php
@@ -1,12 +1,38 @@
<?php

namespace SmartNoses\Gpsnose\Authentication;

use TYPO3\CMS\Core\Authentication\AuthenticationService;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;

class GpsNoseBasedAuthenticationService extends AuthenticationService
class GpsNoseBasedAuthenticationService extends FrontendUserAuthentication
{
public function authUser(array $user): int

public $info = null;
public $login = null;

public function init()
{
}
public function getLastErrorArray()
{
}

/**
* Undocumented function
*
* @param ServerRequestInterface $request
* @return void
*/
public function getLoginFormData(ServerRequestInterface $request = null)
{
return ($user['username'] == $_POST['user'] && $user['password'] == $_POST['pass']) ? 200 : 100;
$userInfo = [
'status' => $_POST['logintype'],
'uname' => $_POST['user'],
'uident' => $_POST['pass'],
'uident_text' => $_POST['pass'],
];
$this->login = $userInfo;
return $userInfo;
}
}
}
56 changes: 21 additions & 35 deletions Classes/Controller/ApiController.php
Expand Up @@ -35,15 +35,6 @@
*/
class ApiController extends BaseController
{
/**
* @var \TYPO3\CMS\Extbase\Mvc\View\JsonView
*/
protected $view;

/**
* @var string
*/
protected $defaultViewObjectName = \TYPO3\CMS\Extbase\Mvc\View\JsonView::class;

/**
* mashupRepository
Expand Down Expand Up @@ -95,13 +86,13 @@ public function pageMembersAction()

$communityTag = $_POST['profileTag'];

$members = [];
if (!GnUtil::IsNullOrEmpty($communityTag)) {
$memberService = new GnMemberService(GnUtility::getLanguage());
$this->view->assign('members', $memberService->GetMembersPage($communityTag, $lastKnownTicks, $pageSize));
$this->view->setVariablesToRender(array(
'members'
));
$members = $memberService->GetMembersPage($communityTag, $lastKnownTicks, $pageSize);
}

return $this->jsonResponse(json_encode($members));
}

/**
Expand All @@ -123,13 +114,13 @@ public function pageNewsAction()

$communityTag = $_POST['community'];

$news = [];
if (!GnUtil::IsNullOrEmpty($communityTag)) {
$newsService = new GnNewsService(GnUtility::getLanguage());
$this->view->assign('news', $newsService->GetNewsPage($communityTag, $lastKnownTicks, $pageSize));
$this->view->setVariablesToRender(array(
'news'
));
$news = $newsService->GetNewsPage($communityTag, $lastKnownTicks, $pageSize);
}

return $this->jsonResponse(json_encode($news));
}

/**
Expand All @@ -153,13 +144,13 @@ public function pageCommentsAction()

$itemType = $_POST['itemType'];

$comments = [];
if (!GnUtil::IsNullOrEmpty($communityTag)) {
$commentService = new GnCommentService(GnUtility::getLanguage());
$this->view->assign('comments', $commentService->GetCommentsPage($itemType, $communityTag, $lastKnownTicks, $pageSize));
$this->view->setVariablesToRender(array(
'comments'
));
$comments = $commentService->GetCommentsPage($itemType, $communityTag, $lastKnownTicks, $pageSize);
}

return $this->jsonResponse(json_encode($comments));
}

/**
Expand All @@ -176,13 +167,13 @@ public function commentSaveAction()
$creationTicks = $_POST['creationTicks'];
$isUpdate = filter_var($_POST['isUpdate'], FILTER_VALIDATE_BOOLEAN);

$result = null;
if (!GnUtil::IsNullOrEmpty($uniqueKey)) {
$commentService = new GnCommentService(GnUtility::getLanguage());
$this->view->assign('result', $commentService->SaveComment($creationTicks, $text, $itemType, $uniqueKey, $isUpdate));
$this->view->setVariablesToRender(array(
'result'
));
$result = $commentService->SaveComment($creationTicks, $text, $itemType, $uniqueKey, $isUpdate);
}

return $this->jsonResponse(json_encode($result));
}

/**
Expand All @@ -200,12 +191,10 @@ public function loginVerifieAction()

$verified = GnUtility::login($mashup, $loginId);
}
$this->view->assign('verified', (object)[

return $this->jsonResponse(json_encode([
'IsOk' => $verified
]);
$this->view->setVariablesToRender(array(
'verified'
));
]));
}

/**
Expand All @@ -227,12 +216,9 @@ public function validateSecurityTokenAction()
$validated = $gnLoginApi->IsSecurityTokenValid($token) === TRUE ? TRUE : FALSE;
}

$this->view->assign('validated', (object)[
return $this->jsonResponse(json_encode([
'IsOk' => $validated
]);
$this->view->setVariablesToRender(array(
'validated'
));
]));
}

/**
Expand Down
12 changes: 12 additions & 0 deletions Classes/Domain/Model/FrontendUser.php
Expand Up @@ -81,6 +81,18 @@ class FrontendUser extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
*/
protected $gpsnoseEmail = NULL;

public function __construct()
{
$this->usergroup = new ObjectStorage();
}

/**
* Called again with initialize object, as fetching an entity from the DB does not use the constructor
*/
public function initializeObject(): void
{
$this->usergroup = $this->usergroup ?? new ObjectStorage();
}

/**
* Get the value of username
Expand Down
48 changes: 25 additions & 23 deletions Classes/Hooks/CmsLayoutHook.php
Expand Up @@ -30,29 +30,31 @@ public function addPluginIcon($params, $parentObject)
}

$iconName = NULL;
switch ($params[2]['list_type']) {
case 'gpsnose_members':
$iconName = 'gpsnose-plugin-members';
break;
case 'gpsnose_news':
$iconName = 'gpsnose-plugin-news';
break;
case 'gpsnose_commentscommunity':
$iconName = 'gpsnose-plugin-comments-community';
break;
case 'gpsnose_loginqrcode':
$iconName = 'gpsnose-plugin-loginqrcode';
break;
case 'gpsnose_nearbynoses':
case 'gpsnose_nearbyimpressions':
case 'gpsnose_nearbypois':
case 'gpsnose_nearbytracks':
case 'gpsnose_nearbyevents':
$iconName = 'gpsnose-plugin-nearby';
break;
case 'gpsnose_qrscanindex':
$iconName = 'gpsnose-plugin-qrscan';
break;
if (isset($params[2])) {
switch ($params[2]['list_type']) {
case 'gpsnose_members':
$iconName = 'gpsnose-plugin-members';
break;
case 'gpsnose_news':
$iconName = 'gpsnose-plugin-news';
break;
case 'gpsnose_commentscommunity':
$iconName = 'gpsnose-plugin-comments-community';
break;
case 'gpsnose_loginqrcode':
$iconName = 'gpsnose-plugin-loginqrcode';
break;
case 'gpsnose_nearbynoses':
case 'gpsnose_nearbyimpressions':
case 'gpsnose_nearbypois':
case 'gpsnose_nearbytracks':
case 'gpsnose_nearbyevents':
$iconName = 'gpsnose-plugin-nearby';
break;
case 'gpsnose_qrscanindex':
$iconName = 'gpsnose-plugin-qrscan';
break;
}
}

if ($iconName !== NULL) {
Expand Down
1 change: 0 additions & 1 deletion Classes/Service/GnCommentService.php
Expand Up @@ -64,7 +64,6 @@ public function SaveComment(string $commentTicks, string $text, int $itemType =
}
} catch (\Exception $e) {
GnLogger::Error($e->getMessage());
return new GnError(1, $e->getMessage());
}
return NULL;
}
Expand Down
2 changes: 0 additions & 2 deletions Classes/Service/GnCommunityService.php
Expand Up @@ -41,7 +41,6 @@ public function GetCommunity(string $communityTag)
}
} catch (\Exception $e) {
GnLogger::Error($e->getMessage());
return new GnError(1, $e->getMessage());
}
return NULL;
}
Expand Down Expand Up @@ -70,7 +69,6 @@ public function GetQrCodeJoinImage(string $communityTag)
}
} catch (\Exception $e) {
GnLogger::Error($e->getMessage());
return new GnError(1, $e->getMessage());
}
return NULL;
}
Expand Down
1 change: 0 additions & 1 deletion Classes/Service/GnComponentsService.php
Expand Up @@ -26,7 +26,6 @@ public function GetQrCode(string $tag)
return $gnLoginApi->GetComponentsApi()->GetQrCode($tag);
} catch (\Exception $e) {
GnLogger::Error($e->getMessage());
return new GnError(1, $e->getMessage());
}
return NULL;
}
Expand Down
26 changes: 16 additions & 10 deletions Classes/Utility/GnUtility.php
Expand Up @@ -18,8 +18,11 @@
use SmartNoses\Gpsnose\Domain\Repository\MashupRepository;
use GpsNose\SDK\Framework\GnCryptor;
use GpsNose\SDK\Framework\Logging\GnLogger;
use Psr\Http\Message\ResponseInterface;
use SmartNoses\Gpsnose\Authentication\GpsNoseBasedAuthenticationService;
use TYPO3\CMS\Core\Authentication\LoginType;
use TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;

class GnUtility
Expand Down Expand Up @@ -82,7 +85,7 @@ public static function login(Mashup $mashup, string $loginId)
{
$GLOBALS['TYPO3_CONF_VARS']['FE']['checkFeUserPid'] = false;

$verified = FALSE;
$verified = false;
if ($mashup && !GnUtil::IsNullOrEmpty($loginId)) {
$api = new GnApi();
$gnLogin = $api->GetLoginApiForEndUser($mashup->getAppKey(), $loginId, NULL)->GetVerified();
Expand Down Expand Up @@ -121,9 +124,11 @@ public static function login(Mashup $mashup, string $loginId)
if (! GnUtil::IsNullOrEmpty($gnLogin->Email) && $gnSettings['login.']['syncEmail']) {
$frontendUser->setEmail($gnLogin->Email ?: '');
}
if (GnUtil::IsNullOrEmpty($frontendUser->getPassword())) {
$frontendUser->setPassword(GnUtil::NewGuid());
}

$password = GnUtil::NewGuid();
$hashInstance = GeneralUtility::makeInstance(PasswordHashFactory::class)->getDefaultHashInstance('FE');
$hashedPassword = $hashInstance->getHashedPassword($password);
$frontendUser->setPassword($hashedPassword);

/** @var \SmartNoses\Gpsnose\Domain\Repository\FrontendUserGroupRepository $userGroupRepository */
$userGroupRepository = GeneralUtility::makeInstance(FrontendUserGroupRepository::class);
Expand Down Expand Up @@ -154,7 +159,7 @@ public static function login(Mashup $mashup, string $loginId)
}
GeneralUtility::makeInstance(PersistenceManager::class)->persistAll();

$verified = self::loginUser($frontendUser->getUsername(), $frontendUser->getPassword());
$verified = self::loginUser($frontendUser->getUsername(), $password);

$gnAuthData = new GnAuthenticationData();
$gnAuthData->LoginId = $loginId;
Expand Down Expand Up @@ -187,12 +192,13 @@ public static function login(Mashup $mashup, string $loginId)
*/
private static function loginUser($username, $password)
{
$_POST['logintype'] = 'login';
$_POST['logintype'] = LoginType::LOGIN;
$_POST['user'] = $username;
$_POST['pass'] = $password;
/** @var FrontendUserAuthentication */
$authService = GeneralUtility::makeInstance(FrontendUserAuthentication::class);
$authService->start(($GLOBALS['TYPO3_REQUEST'] ?? null));
/** @var GpsNoseBasedAuthenticationService */
$authService = GeneralUtility::makeInstance(GpsNoseBasedAuthenticationService::class);
$request = $GLOBALS['TYPO3_REQUEST'] ?: null;
$authService->start($request);

$hasUser = false;
if (isset($authService->user)) {
Expand Down
1 change: 0 additions & 1 deletion Classes/ViewHelpers/Community/JoinqrcodeViewHelper.php
Expand Up @@ -49,7 +49,6 @@ public function render()
}
} catch (\Exception $e) {
GnLogger::Error($e->getMessage());
return NULL;
}
return NULL;
}
Expand Down
1 change: 0 additions & 1 deletion Classes/ViewHelpers/Ticks/DatetimeViewHelper.php
Expand Up @@ -39,7 +39,6 @@ public function render()
return date($format, $date->getTimestamp());
} catch (\Exception $e) {
GnLogger::Error($e->getMessage());
return NULL;
}
return NULL;
}
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions Documentation/ChangeLog/Index.rst
Expand Up @@ -6,6 +6,10 @@
Change log
==========

Version 3.0.1
-------------
- FIX: Ajax response

Version 3.0.0
-------------
- UPD: Add TYPO3 V12 support
Expand Down
2 changes: 1 addition & 1 deletion Documentation/Settings.cfg
Expand Up @@ -21,7 +21,7 @@

project = GpsNose Documentation
version = 3.0
release = 3.0.0
release = 3.0.1
t3author = smart.nose
copyright = since 2019 by SmartNoses (https://www.gpsnose.com)

Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Expand Up @@ -21,7 +21,7 @@
'uploadfolder' => '0',
'createDirs' => '',
'clearCacheOnLoad' => 0,
'version' => '3.0.0',
'version' => '3.0.1',
'constraints' => [
'depends' => [
'typo3' => '11.5.0-12.9.99',
Expand Down

0 comments on commit e398ffd

Please sign in to comment.