1414use Chamilo \CoreBundle \Repository \Node \UserRepository ;
1515use Chamilo \CoreBundle \Settings \SettingsManager ;
1616use Chamilo \CoreBundle \Traits \ControllerTrait ;
17+ use DateTimeImmutable ;
1718use Endroid \QrCode \Builder \Builder ;
1819use Endroid \QrCode \Encoding \Encoding ;
1920use Endroid \QrCode \ErrorCorrectionLevel \ErrorCorrectionLevelHigh ;
@@ -77,7 +78,7 @@ public function edit(
7778 $ password = $ form ['password ' ]->getData ();
7879 if ($ password ) {
7980 $ user ->setPlainPassword ($ password );
80- $ user ->setPasswordUpdatedAt (new \ DateTimeImmutable ());
81+ $ user ->setPasswordUpdatedAt (new DateTimeImmutable ());
8182 }
8283 }
8384
@@ -113,21 +114,21 @@ public function changePassword(
113114
114115 if (!$ user || !$ user instanceof UserInterface) {
115116 $ userId = $ request ->query ->get ('userId ' );
116- //error_log("User not logged in. Received userId from query: " . $userId);
117+ // error_log("User not logged in. Received userId from query: " . $userId);
117118
118119 if (!$ userId || !ctype_digit ($ userId )) {
119- //error_log("Access denied: Missing or invalid userId.");
120+ // error_log("Access denied: Missing or invalid userId.");
120121 throw $ this ->createAccessDeniedException ('This user does not have access to this section. ' );
121122 }
122123
123- $ user = $ userRepository ->find ((int )$ userId );
124+ $ user = $ userRepository ->find ((int ) $ userId );
124125
125126 if (!$ user || !$ user instanceof UserInterface) {
126- //error_log("Access denied: User not found with ID $userId");
127+ // error_log("Access denied: User not found with ID $userId");
127128 throw $ this ->createAccessDeniedException ('User not found or invalid. ' );
128129 }
129130
130- //error_log("Loaded user by ID: " . $user->getId());
131+ // error_log("Loaded user by ID: " . $user->getId());
131132 }
132133
133134 $ isRotation = $ request ->query ->getBoolean ('rotate ' , false );
@@ -163,7 +164,7 @@ public function changePassword(
163164
164165 $ totp = TOTP ::create ($ secret );
165166 $ portalName = $ settingsManager ->getSetting ('platform.institution ' );
166- $ totp ->setLabel ($ portalName . ' - ' . $ user ->getEmail ());
167+ $ totp ->setLabel ($ portalName. ' - ' . $ user ->getEmail ());
167168
168169 $ qrCodeResult = Builder::create ()
169170 ->writer (new PngWriter ())
@@ -172,7 +173,8 @@ public function changePassword(
172173 ->errorCorrectionLevel (new ErrorCorrectionLevelHigh ())
173174 ->size (300 )
174175 ->margin (10 )
175- ->build ();
176+ ->build ()
177+ ;
176178
177179 $ qrCodeBase64 = base64_encode ($ qrCodeResult ->getString ());
178180 $ showQRCode = true ;
@@ -224,7 +226,7 @@ public function changePassword(
224226 ));
225227 } else {
226228 $ user ->setPlainPassword ($ newPassword );
227- $ user ->setPasswordUpdatedAt (new \ DateTimeImmutable ());
229+ $ user ->setPasswordUpdatedAt (new DateTimeImmutable ());
228230 $ userRepository ->updateUser ($ user );
229231 $ this ->addFlash ('success ' , 'Password updated successfully. ' );
230232
@@ -244,10 +246,10 @@ public function changePassword(
244246 }
245247 }
246248 } else {
247- error_log (" Form is NOT valid. " );
249+ error_log (' Form is NOT valid. ' );
248250 }
249251 } else {
250- error_log (" Form NOT submitted yet. " );
252+ error_log (' Form NOT submitted yet. ' );
251253 }
252254
253255 return $ this ->render ('@ChamiloCore/Account/change_password.html.twig ' , [
@@ -267,7 +269,7 @@ private function encryptTOTPSecret(string $secret, string $encryptionKey): strin
267269 $ iv = openssl_random_pseudo_bytes (openssl_cipher_iv_length ($ cipherMethod ));
268270 $ encryptedSecret = openssl_encrypt ($ secret , $ cipherMethod , $ encryptionKey , 0 , $ iv );
269271
270- return base64_encode ($ iv . ':: ' . $ encryptedSecret );
272+ return base64_encode ($ iv. ':: ' . $ encryptedSecret );
271273 }
272274
273275 /**
0 commit comments