<?php
namespace App\User\CoreBundle\Controller;
use App\Siance\FrameworkExtraBundle\Controller\SianceController;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Doctrine\ORM\Query\ResultSetMapping;
use Symfony\Component\Routing\Annotation\Route;
class SecurityController extends SianceController
{
/**
* ログイン
*
* @Template()
* @Route("/login", name="user_login")
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function loginAction(Request $request)
{
$user = $this->getUser();
$authenticationUtils = $this->get('security.authentication_utils');
// ログインエラーがあれば、ここで取得
$error = $authenticationUtils->getLastAuthenticationError();
// ユーザーによって前回入力されたログインID
$lastUsername = $authenticationUtils->getLastUsername();
// ログイン不能エラーメッセージ
$msg[0] = $this->getParameter('CMN_V_0001');
if ($error) {
if ($error->getMessage() == 'LineIdNotFound') {
// LINEログインの失敗→まだLINE登録されてないからID/PWでログインしてね的なメッセージ
$msg[0] = 'LINEアカウントが連携されておりません。';
} elseif ($error->getMessage() == 'LineIdRegisterError') {
// LINE連携の失敗→ユーザー情報確認に戻す
if (!empty($user)) {
// 失敗メッセージ(仮)
$this->setAlert('danger', 'CMN_V_0001');
return new RedirectResponse($this->generateUrl('user_info'));
}
}
}
if (!empty($user)) {
return $this->redirectToRoute("user_home");
}
// JavaScript無効メッセージ
$msg[1] = $this->getParameter('CMN_I_0033');
return $this->render('@UserCore/security/login.html.twig', array(
'last_username' => $lastUsername,
'error' => $error,
'msg' => $msg
));
}
/**
* LINEログイン
* @Route("line/login", name="line_login")
* @return RedirectResponse
*/
public function lineLoginAction()
{
return $this->get('oauth2.registry')
->getClient('line_client')
->redirect(array('scope' => 'openid'), array());
}
}