src/User/CoreBundle/Controller/SecurityController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\User\CoreBundle\Controller;
  3. use App\Siance\FrameworkExtraBundle\Controller\SianceController;
  4. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  7. use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
  8. use Symfony\Component\HttpFoundation\RedirectResponse;
  9. use Symfony\Component\HttpFoundation\Session\Session;
  10. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  11. use Doctrine\ORM\Query\ResultSetMapping;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. class SecurityController extends SianceController
  14. {
  15.     /**
  16.      * ログイン
  17.      *
  18.      * @Template()
  19.      * @Route("/login", name="user_login")
  20.      * @param Request $request
  21.      * @return \Symfony\Component\HttpFoundation\Response
  22.      */
  23.     public function loginAction(Request $request)
  24.     {
  25.         $user $this->getUser();
  26.         $authenticationUtils $this->get('security.authentication_utils');
  27.         // ログインエラーがあれば、ここで取得
  28.         $error $authenticationUtils->getLastAuthenticationError();
  29.         // ユーザーによって前回入力されたログインID
  30.         $lastUsername $authenticationUtils->getLastUsername();
  31.         // ログイン不能エラーメッセージ
  32.         $msg[0] = $this->getParameter('CMN_V_0001');
  33.         if ($error) {
  34.             if ($error->getMessage() == 'LineIdNotFound') {
  35.                 // LINEログインの失敗→まだLINE登録されてないからID/PWでログインしてね的なメッセージ
  36.                 $msg[0] = 'LINEアカウントが連携されておりません。';
  37.             } elseif ($error->getMessage() == 'LineIdRegisterError') {
  38.                 // LINE連携の失敗→ユーザー情報確認に戻す
  39.                 if (!empty($user)) {
  40.                     // 失敗メッセージ(仮)
  41.                     $this->setAlert('danger''CMN_V_0001');
  42.                     return new RedirectResponse($this->generateUrl('user_info'));
  43.                 }
  44.             }
  45.         }
  46.         if (!empty($user)) {
  47.            return $this->redirectToRoute("user_home");
  48.         }
  49.         // JavaScript無効メッセージ
  50.         $msg[1] = $this->getParameter('CMN_I_0033');
  51.         return $this->render('@UserCore/security/login.html.twig', array(
  52.             'last_username' => $lastUsername,
  53.             'error' => $error,
  54.             'msg' => $msg
  55.         ));
  56.     }
  57.     /**
  58.      * LINEログイン
  59.      * @Route("line/login", name="line_login")
  60.      * @return RedirectResponse
  61.      */
  62.     public function lineLoginAction()
  63.     {
  64.         return $this->get('oauth2.registry')
  65.             ->getClient('line_client')
  66.             ->redirect(array('scope' => 'openid'), array());
  67.     }
  68. }