2016-07-11 2 views
0

ログイン時に有効なValidationCodeを入力すると、アカウントを再アクティブ化できるユーザーがロックされています。ユーザーが以前にロックされているので、私はAuthenticationFailureListenerを使用してログイン失敗を検出し、有効な検証コードがあるかどうかを判断します。ログのトレースに応じてすべてのアクションが正しいデータを持つように見えますが、問題はすべてです。同じですが、何もデータベースに保存されていないため、変更は発生しません。ログイン時にFOSUserBundleロック解除ユーザー:変更が維持されない

これは私のコードです:

public function onAuthenticationFailure(Request $request, AuthenticationException $exception) 
{ 
    $userReactivated = false; 

    // Checks if error is due to user locked and 
    if ($exception instanceof LockedException) 
    { 
     $username = $request->request->get("_username"); 
     $v_code = $request->request->get("_validation_code"); 

     error_log("{$username} {$v_code}"); 

     $user = $this->em->getRepository("AppUserBundle:Usuario")->findOneBy(array('username' => $username)); 
     if ($user != null) 
     { 
      $validationCode = $this->em->getRepository("AppUserBundle:ValidationCode")->findOneBy(array('code' => $v_code)); 

      if ($validationCode != null) 
      { 
       error_log("Code " . $validationCode->getId()); 
       if ($validationCode->isActive()) 
       { 
        $user->setValidationCode($validationCode); 
        $userReactivated = true; 

        $user->setLocked(false); 
        $this->em->persist($user); 
        $this->em->flush(); 
       } 
      } 
     } 
    } 

    if (!$userReactivated) 
     return parent::onAuthenticationFailure($request, $exception); 
    else 
    { 
     return true; // TODO: login user and redirect to home page 
    } 
} 

答えて

-1
if (!$userReactivated) { 
    $exception->setUser($user); 
    return parent::onAuthenticationFailure($request, $exception); 
} else { 
    return true; // TODO: login user and redirect to home page 
} 
+0

より多くの情報を編集してください。コード専用と「試してください」の回答は、検索可能なコンテンツが含まれていないため、推奨されません。なぜ誰かが「これを試してみる」べき理由を説明しません。 – abarisone

関連する問題