nice meet you.
i'm developping symfony 3.1.3 , i'm using security system offered framework, no fosuser neither guard.
i have in controller typical function login:
public function loginaction(request $request) {     // works     $authenticationutils = $this->get('security.authentication_utils');      // login error if there 1     $error = $authenticationutils->getlastauthenticationerror();      // last username entered user     $lastusername = $authenticationutils->getlastusername();      return $this->render(         'security/loginform_old.html.twig',         array(             // last username entered user             'last_username' => $lastusername,             'error'         => $error,         )     ); } and want check if user has activated account. in entity user have isactive attribute set false default , link registration email setted true.
i have been searching issue without results , i'm sure common, wants check if user's email one.
thanks.
lets assume have registrationcontroller.php class store code manage user's registration.
create function sends email user after registration:
public function sendconfirmationemailmessage(user $user) {      $confirmationtoken = $user->getconfirmationtoken();     $username = $user->getusername();      $subject = 'account activation';     $email = $user->getemail();      $renderedtemplate = $this->templating->render('appbundle:emails:registration.html.twig', array(         'username' => $username,         'confirmationtoken' => $confirmationtoken     ));      $message = \swift_message::newinstance()             ->setsubject($subject)             ->setfrom(mailer_from)             ->setreplyto(mailer_from)             ->setto($email)             ->setbody($renderedtemplate, "text/html");      $this->mailer->send($message);  } create route associated function takes generated token argument, search user token , activate if user exist:
/** * @route("user/activate/{token}") */ public function confirmaction(request $request, $token) {     $em = $this->getdoctrine()->getmanager();     $repository = $em->getrepository('appbundle:user');      $user = $repository->finduserbyconfirmationtoken($token);      if (!$user)     {         throw $this->createnotfoundexception('we couldn\'t find account confirmation token');     }      $user->setconfirmationtoken(null);     $user->setenabled(true);      $em->persist($user);     $em->flush();      return $this->redirecttoroute('user_registration_confirmed'); } then when have function registers user call sendconfirmationemailmessage shown below:
public function registeraction(request $request) {     /* logic goes here: form validation, creating new user */     /* $user created user */     sendconfirmationemailmessage($user); } anyway if isactive() function return false symfony security system prevent login. user entity should implement userinterface.
Comments
Post a Comment