-
-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: moved login API to controller
- Loading branch information
Showing
9 changed files
with
136 additions
and
41 deletions.
There are no files selected for viewing
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 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 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
15 changes: 15 additions & 0 deletions
15
phpmyfaq/src/phpMyFAQ/Api/Controller/AttachmentController.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* The Attachment Controller for the REST API | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* @package phpMyFAQ | ||
* @author Thorsten Rinne <[email protected]> | ||
* @copyright 2023 phpMyFAQ Team | ||
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 | ||
* @link https://www.phpmyfaq.de | ||
* @since 2023-07-30 | ||
*/ | ||
|
||
namespace phpMyFAQ\Api\Controller; | ||
|
||
use phpMyFAQ\Attachment\AttachmentException; | ||
|
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
/** | ||
* The Login Controller for the REST API | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* @package phpMyFAQ | ||
* @author Thorsten Rinne <[email protected]> | ||
* @copyright 2023 phpMyFAQ Team | ||
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 | ||
* @link https://www.phpmyfaq.de | ||
* @since 2023-07-30 | ||
*/ | ||
|
||
namespace phpMyFAQ\Api\Controller; | ||
|
||
use phpMyFAQ\Configuration; | ||
use phpMyFAQ\Core\Exception; | ||
use phpMyFAQ\Filter; | ||
use phpMyFAQ\Translation; | ||
use phpMyFAQ\User\CurrentUser; | ||
use phpMyFAQ\User\UserAuthentication; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class LoginController | ||
{ | ||
/** | ||
* @throws \JsonException | ||
*/ | ||
public function login(Request $request): JsonResponse | ||
{ | ||
$response = new JsonResponse(); | ||
$faqConfig = Configuration::getConfigurationInstance(); | ||
|
||
$postBody = json_decode($request->getContent(), false, 512, JSON_THROW_ON_ERROR); | ||
|
||
$faqUsername = Filter::filterVar($postBody->username, FILTER_SANITIZE_SPECIAL_CHARS); | ||
$faqPassword = Filter::filterVar($postBody->password, FILTER_SANITIZE_SPECIAL_CHARS); | ||
|
||
$user = new CurrentUser($faqConfig); | ||
$userAuth = new UserAuthentication($faqConfig, $user); | ||
try { | ||
$user = $userAuth->authenticate($faqUsername, $faqPassword); | ||
$response->setStatusCode(Response::HTTP_OK); | ||
$result = [ | ||
'loggedin' => true | ||
]; | ||
} catch (Exception $e) { | ||
$faqConfig->getLogger()->error('Failed login: ' . $e->getMessage()); | ||
$response->setStatusCode(Response::HTTP_BAD_REQUEST); | ||
$result = [ | ||
'loggedin' => false, | ||
'error' => Translation::get('ad_auth_fail') | ||
]; | ||
} | ||
$response->setData($result); | ||
|
||
return $response; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* The News Controller for the REST API | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* @package phpMyFAQ | ||
* @author Thorsten Rinne <[email protected]> | ||
* @copyright 2023 phpMyFAQ Team | ||
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 | ||
* @link https://www.phpmyfaq.de | ||
* @since 2023-07-30 | ||
*/ | ||
|
||
namespace phpMyFAQ\Api\Controller; | ||
|
||
use phpMyFAQ\Configuration; | ||
|
15 changes: 15 additions & 0 deletions
15
phpmyfaq/src/phpMyFAQ/Api/Controller/OpenQuestionController.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* The Open Questions Controller for the REST API | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* @package phpMyFAQ | ||
* @author Thorsten Rinne <[email protected]> | ||
* @copyright 2023 phpMyFAQ Team | ||
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 | ||
* @link https://www.phpmyfaq.de | ||
* @since 2023-07-29 | ||
*/ | ||
|
||
namespace phpMyFAQ\Api\Controller; | ||
|
||
use phpMyFAQ\Configuration; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* The Tags Controller for the REST API | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* @package phpMyFAQ | ||
* @author Thorsten Rinne <[email protected]> | ||
* @copyright 2023 phpMyFAQ Team | ||
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 | ||
* @link https://www.phpmyfaq.de | ||
* @since 2023-07-29 | ||
*/ | ||
|
||
namespace phpMyFAQ\Api\Controller; | ||
|
||
use phpMyFAQ\Configuration; | ||
|