2828use Symfony \Component \HttpFoundation \Response ;
2929use Symfony \Component \Security \Core \Exception \AccessDeniedException ;
3030use Symfony \Component \Translation \Translator ;
31+ use Symfony \Component \Translation \TranslatorInterface ;
3132
3233/**
3334 * Controller managing the user profile.
@@ -39,12 +40,16 @@ class ProfileController extends AbstractController
3940 private $ eventDispatcher ;
4041 private $ formFactory ;
4142 private $ userManager ;
43+ private $ emailUpdateConfirmation ;
44+ private $ translator ;
4245
43- public function __construct (EventDispatcherInterface $ eventDispatcher , FactoryInterface $ formFactory , UserManagerInterface $ userManager )
46+ public function __construct (EventDispatcherInterface $ eventDispatcher , FactoryInterface $ formFactory , UserManagerInterface $ userManager, EmailUpdateConfirmation $ emailUpdateConfirmation , TranslatorInterface $ translator )
4447 {
4548 $ this ->eventDispatcher = $ eventDispatcher ;
4649 $ this ->formFactory = $ formFactory ;
4750 $ this ->userManager = $ userManager ;
51+ $ this ->emailUpdateConfirmation = $ emailUpdateConfirmation ;
52+ $ this ->translator = $ translator ;
4853 }
4954
5055 /**
@@ -121,42 +126,33 @@ public function editAction(Request $request)
121126 */
122127 public function confirmEmailUpdateAction (Request $ request , $ token )
123128 {
124- $ userManager = $ this ->container ->get ('fos_user.user_manager ' );
125-
126129 /** @var User $user */
127- $ user = $ userManager ->findUserByConfirmationToken ($ token );
130+ $ user = $ this -> userManager ->findUserByConfirmationToken ($ token );
128131
129132 // If user was not found throw 404 exception
130133 if (!$ user ) {
131- /** @var Translator $translator */
132- $ translator = $ this ->get ('translator ' );
133- throw $ this ->createNotFoundException ($ translator ->trans ('email_update.error.message ' , array (), 'FOSUserBundle ' ));
134+ throw $ this ->createNotFoundException ($ this ->translator ->trans ('email_update.error.message ' , array (), 'FOSUserBundle ' ));
134135 }
135136
136137 // Show invalid token message if the user id found via token does not match the current users id (e.g. anon. or other user)
137138 if (!($ this ->getUser () instanceof UserInterface) || ($ user ->getId () !== $ this ->getUser ()->getId ())) {
138- /** @var Translator $translator */
139- $ translator = $ this ->get ('translator ' );
140- throw new AccessDeniedException ($ translator ->trans ('email_update.error.message ' , array (), 'FOSUserBundle ' ));
139+ throw new AccessDeniedException ($ this ->translator ->trans ('email_update.error.message ' , array (), 'FOSUserBundle ' ));
141140 }
142141
143- /** @var EmailUpdateConfirmation $emailUpdateConfirmation */
144- $ emailUpdateConfirmation = $ this ->get ('fos_user.email_update_confirmation ' );
145-
146- $ emailUpdateConfirmation ->setUser ($ user );
142+ $ this ->emailUpdateConfirmation ->setUser ($ user );
147143
148- $ newEmail = $ emailUpdateConfirmation ->fetchEncryptedEmailFromConfirmationLink ($ request ->get ('target ' ));
144+ $ newEmail = $ this -> emailUpdateConfirmation ->fetchEncryptedEmailFromConfirmationLink ($ request ->get ('target ' ));
149145
150146 // Update user email
151147 if ($ newEmail ) {
152- $ user ->setConfirmationToken ($ emailUpdateConfirmation ->getEmailConfirmedToken ());
148+ $ user ->setConfirmationToken ($ this -> emailUpdateConfirmation ->getEmailConfirmedToken ());
153149 $ user ->setEmail ($ newEmail );
154150 }
155151
156- $ userManager ->updateUser ($ user );
152+ $ this -> userManager ->updateUser ($ user );
157153
158154 $ event = new UserEvent ($ user , $ request );
159- $ this ->get ( ' event_dispatcher ' ) ->dispatch (FOSUserEvents::EMAIL_UPDATE_SUCCESS , $ event );
155+ $ this ->eventDispatcher ->dispatch (FOSUserEvents::EMAIL_UPDATE_SUCCESS , $ event );
160156
161157 return $ this ->redirect ($ this ->generateUrl ('fos_user_profile_show ' ));
162158 }
0 commit comments