Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8794905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:18:53+00:00 2026-06-13T23:18:53+00:00

I’m using HWIOAuthBundle to let an user login with Oauth, I’ve created a custom

  • 0

I’m using HWIOAuthBundle to let an user login with Oauth, I’ve created a custom user provider which creates an user in case it doesn’t exist:

public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
    $attr = $response->getResponse();
    switch($response->getResourceOwner()->getName()) {
        case 'google':
            if(!$user = $this->userRepository->findOneByGoogleId($attr['id'])) {
                if(($user = $this->userRepository->findOneByEmail($attr['email'])) && $attr['verified_email']) {
                    $user->setGoogleId($attr['id']);
                    if(!$user->getFirstname()) {
                        $user->setFirstname($attr['given_name']);
                    }
                    if(!$user->getLastname()) {
                        $user->setLastname($attr['family_name']);
                    }
                    $user->setGoogleName($attr['name']);
                }else{
                    $user = new User();
                    $user->setUsername($this->userRepository->createUsernameByEmail($attr['email']));
                    $user->setEmail($attr['email']);
                    $user->setFirstname($attr['given_name']);
                    $user->setLastname($attr['family_name']);
                    $user->setPassword('');
                    $user->setIsActive(true);
                    $user->setGoogleId($attr['id']);
                    $user->setGoogleName($attr['name']);
                    $user->addGroup($this->groupRepository->findOneByRole('ROLE_USER'));
                    $this->entityManager->persist($user);
                }
            }
            break;
        case 'facebook':
            if(!$user = $this->userRepository->findOneByFacebookId($attr['id'])) {
                if(($user = $this->userRepository->findOneByEmail($attr['email'])) && $attr['verified']) {
                    $user->setFacebookId($attr['id']);
                    if(!$user->getFirstname()) {
                        $user->setFirstname($attr['first_name']);
                    }
                    if(!$user->getLastname()) {
                        $user->setLastname($attr['last_name']);
                    }
                    $user->setFacebookUsername($attr['username']);
                }else{
                    $user = new User();
                    $user->setUsername($this->userRepository->createUsernameByEmail($attr['email']));
                    $user->setEmail($attr['email']);
                    $user->setFirstname($attr['first_name']);
                    $user->setLastname($attr['last_name']);
                    $user->setPassword('');
                    $user->setIsActive(true);
                    $user->setFacebookId($attr['id']);
                    $user->setFacebookUsername($attr['username']);
                    $user->addGroup($this->groupRepository->findOneByRole('ROLE_USER'));
                    $this->entityManager->persist($user);
                }
            }
            break;
    }

    $this->entityManager->flush();


    if (null === $user) {
        throw new AccountNotLinkedException(sprintf("User '%s' not found.", $attr['email']));
    }

    return $user;
}

The problem is that twitter for example doesn’t give the email or i want some additional fields to be included before a new user is created. Is there a way to redirect an user to a “complete registration” form before creating it?

I’ve tried to add a request listener, that on each request, if the user is logged, checks if the email is there and if it doesn’t it redirects to the complete_registration page, but it will redirect also if the user goes to the homepage, to logout or anything else, I want to redirect him only if he tries to access some user restricted pages.

Or better, don’t create it until he gives all the required informations.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:18:54+00:00Added an answer on June 13, 2026 at 11:18 pm

    I’ve found the solution by myself, I’ve manually created a new exception:

    <?php
    
    namespace Acme\UserBundle\Exception;
    
    use Symfony\Component\Security\Core\Exception\AuthenticationException;
    use HWI\Bundle\OAuthBundle\Security\Core\Exception\OAuthAwareExceptionInterface;
    
    /**
     * IncompleteUserException is thrown when the user isn't fully registered (e.g.: missing some informations).
     *
     * @author Alessandro Tagliapietra http://www.alexnetwork.it/
     */
    class IncompleteUserException extends AuthenticationException implements OAuthAwareExceptionInterface
    {
        private $user;
        private $accessToken;
        private $resourceOwnerName;
    
        /**
         * {@inheritdoc}
         */
        public function setAccessToken($accessToken)
        {
            $this->accessToken = $accessToken;
        }
    
        /**
         * {@inheritdoc}
         */
        public function getAccessToken()
        {
            return $this->accessToken;
        }
    
        /**
         * {@inheritdoc}
         */
        public function getResourceOwnerName()
        {
            return $this->resourceOwnerName;
        }
    
        /**
         * {@inheritdoc}
         */
        public function setResourceOwnerName($resourceOwnerName)
        {
            $this->resourceOwnerName = $resourceOwnerName;
        }
    
        public function setUser($user)
        {
            $this->user = $user;
        }
    
        public function getUser($user)
        {
            return $this->user;
        }
    
        public function serialize()
        {
            return serialize(array(
                $this->user,
                $this->accessToken,
                $this->resourceOwnerName,
                parent::serialize(),
            ));
        }
    
        public function unserialize($str)
        {
            list(
                $this->user,
                $this->accessToken,
                $this->resourceOwnerName,
                $parentData
            ) = unserialize($str);
            parent::unserialize($parentData);
        }
    }
    

    In this way, in the custom Oauth user provider when i check if an user exist or I create a new user i check if the required fields are missing:

    if (!$user->getEmail()) {
        $e = new IncompleteUserException("Your account doesn't has a mail set");
        $e->setUser($user);
        throw $e;
    }
    

    In that case the user will be redirected to the login form, with that exception in session, so in the login page I do:

    if($error instanceof IncompleteUserException) {
        $session->set(SecurityContext::AUTHENTICATION_ERROR, $error);
        return $this->redirect($this->generateUrl('register_complete'));
    }
    

    And it will be redirected to a form with the $user in the exception so it can ask only for the missing information and then login the user.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.