0
我有一個Lexik捆綁的UserProvider,並檢查用戶是否通過會話存在,但是當我做出某些請求時會出現問題,會話失去了人們知道的值,因爲發生這種情況。Symfony在服務中丟失會話
服務
app.user_provider:
class: ApiBundle\Security\Userprovider
arguments: ["@session","@switchconnection","@doctrine.orm.entity_manager" , "@doctrine.dbal.default_connection" , "@doctrine"]
我的供應商
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use ApiBundle\Entity\Utilizador;
use Symfony\Component\HttpFoundation\Session\Session;
public function __construct(Session $session,$switchconnection ,\Doctrine\ORM\EntityManager $em , \Doctrine\DBAL\Connection $dbalConnection , \Doctrine\Bundle\DoctrineBundle\Registry $doctrine) {
$this->session = $session;
$this->switchconnection = $switchconnection;
$this->em = $em;
$this->connection = $dbalConnection;
$this->doctrine = $doctrine;
}
public function loadUserByUsername($username)
{
if($this->session->get("currentuser") == $username){
$this->switchconnection->switchDatabase($this->session->get("dbconnection"), $this->connection , $this->doctrine);
$conn = $this->em->getConnection();
$stmt = $conn->prepare(".....");
$stmt->bindParam(1, $username);
$stmt->execute();
$results = $stmt->fetchAll();
$count = count($results);
if($count != 0)
{
$user= new Utilizador();
$user->setUsername($results[0]['username']);
$user->setEmail($results[0]['email']);
return $user;
}
}
throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
}
我還檢查了在var /會話/ dev的文件夾中有2 Phpsession幾乎相同的會話寄存器。
更新1
重要信息這只是發生在WebKit瀏覽器
我已經加入抱歉,我沒有進入的問題 – user26776
ok了進口。我有更新答案請現在就試試。 –
謝謝,但它不起作用 – user26776