-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 00 - rework google auth process
Body : goals are to prevent erreor on first auth and to clean the whole process
- Loading branch information
1 parent
b4188ec
commit d427743
Showing
10 changed files
with
186 additions
and
127 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,60 @@ | ||
<?php | ||
|
||
/** | ||
* @author ThomasLdev | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller; | ||
|
||
use App\Entity\User; | ||
use App\Entity\UserSettings; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
class BaseController extends AbstractController | ||
{ | ||
protected const LOGIN_ROUTE = 'app_login'; | ||
protected const INDEX_ROUTE = 'app_index'; | ||
protected const SETTINGS_ROUTE = 'app_settings'; | ||
|
||
public function __construct( | ||
private readonly TranslatorInterface $translator, | ||
) { | ||
} | ||
|
||
public function flashOnRedirect(string $type, string $message, string $route): RedirectResponse | ||
{ | ||
$this->addFlash($type, $this->translator->trans($message)); | ||
|
||
return $this->redirectToRoute($route); | ||
} | ||
|
||
public function getAppUser(): User | ||
{ | ||
$user = $this->getUser(); | ||
|
||
if (false === $user instanceof User) { | ||
$this->flashOnRedirect('error', 'errors.controller.user.not_logged',self::LOGIN_ROUTE); | ||
} | ||
|
||
return $user; | ||
} | ||
|
||
public function getAppUserSettings(User $user): UserSettings | ||
{ | ||
$settings = $user->getSettings(); | ||
|
||
if (null === $settings) { | ||
$this->flashOnRedirect( | ||
'error', | ||
'errors.controller.user.no_settings', | ||
self::SETTINGS_ROUTE | ||
); | ||
} | ||
|
||
return $settings; | ||
} | ||
} |
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
Oops, something went wrong.