/**
  * @EXT\Route(
  *     "/login",
  *     name="claro_o365_login"
  * )
  *
  * @return RedirectResponse
  */
 public function loginAction()
 {
     $this->authHelper->GetAuthenticationHeaderFor3LeggedFlow($_GET['code']);
     $jsonResponse = $this->graphHelper->getMeEntry();
     $userResponse = new O365ResponseUser($jsonResponse);
     $userManager = $this->get('claroline.manager.user_manager');
     $email = $userResponse->getEmail();
     $user = $userManager->getUserByEmail($email);
     if ($user === null) {
         $missingProperties = $userResponse->validate();
         if (count($missingProperties) > 0) {
             return $this->render('FormaLibreOfficeConnectBundle:Authentication:missingProperties.html.twig', ['missingProperties' => $missingProperties]);
         }
         $user = new User();
         $user->setFirstName($userResponse->getNickname());
         $user->setLastName($userResponse->getRealName());
         $user->setUsername($userResponse->getUsername());
         $user->setPlainPassword($userResponse->getEmail());
         $user->setMail($userResponse->getEmail());
         $user->setIsMailValidated(true);
         $userManager->createUser($user, false);
     }
     $userRepo = $this->get('doctrine.orm.entity_manager')->getRepository('ClarolineCoreBundle:User');
     $securityContext = $this->get('security.context');
     $userLoaded = $userRepo->loadUserByUsername($user->getUsername());
     $providerKey = 'main';
     $token = new UsernamePasswordToken($userLoaded, $userLoaded->getPassword(), $providerKey, $userLoaded->getRoles());
     $securityContext->setToken($token);
     $userManager->logUser($user);
     return $this->get('claroline.authentication_handler')->onAuthenticationSuccess($this->get('request'), $token);
 }
示例#2
0
 /**
  * Activates a User and set the init date to now.
  */
 public function activateUser(User $user)
 {
     $user->setIsEnabled(true);
     $user->setIsMailValidated(true);
     $user->setResetPasswordHash(null);
     $user->setInitDate(new \DateTime());
     $this->objectManager->persist($user);
     $this->objectManager->flush();
 }