88* Compatibility: MediaWiki 1.23.8
99*/
1010
11+
1112$ dir = __DIR__ . '/ ' ; //set the internationalization files directory for the extension
1213$ wgMessagesDirs ['latch ' ] = __DIR__ . '/i18n ' ;
1314
@@ -35,6 +36,7 @@ function onLogout( &$user )
3536 */
3637function onUserLoadAfterLoadFromSession ( $ user )
3738{
39+
3840 global $ wgRequest ; //used to set a session variable, when the user logs into MW, check once if there is a latch and save it in the variable
3941
4042 if ( $ user ->getId () > 0 ) // user logged in MediaWiki
@@ -79,7 +81,7 @@ function onPreferencesForm( $user, &$preferences )
7981 );
8082
8183 }
82-
84+
8385 else //if the user is not paired render the view with pair options in the form
8486 {
8587 $ preferences ['formUnpairedTextbox ' ] = array (
@@ -104,26 +106,47 @@ function onPreferencesForm( $user, &$preferences )
104106 'help-message ' => 'prefs-2FA-help ' ,
105107 );
106108 }
107-
109+
108110 return true ; // Required return value of a hook function.
109111}
110112
111113/**
112114 * Allows extension to modify what preferences will be saved
113115 */
114116function onPreferencesFormPreSave ( $ formData , $ form , $ user , &$ result )
115- {
117+ {
118+ $ errorMsg = '' ;
116119 //the user has not paired Mediawiki account with Latch
117120 if ( !dbHelper::isPaired () )
118121 {
119122 $ oneTimePassword = $ formData ["formUnpairedTextbox " ]; //get the OTP writen by the user in the textbox form
120- LatchController::doPair ($ oneTimePassword );
123+ $ responsePair = LatchController::doPair ($ oneTimePassword );
124+
125+ if ( $ responsePair == -1 )
126+ {
127+ $ errorMsg = "Error con el token de pareado, por favor vuelve a enviar el token. " ;
128+ if ( $ errorMsg <> '' )
129+ {
130+ return $ errorMsg ;
131+ }
132+ }
133+
121134 }
122135 //the user has paired Mediawiki account with Latch
123136 else if ( dbHelper::isPaired () && isset ( $ _POST ["wpformPairedButton " ] ) )
124- {
125- LatchController::doUnpair ();
137+ {
138+ $ responseUnpair = LatchController::doUnpair ();
139+ if ( $ responseUnpair == -1 )
140+ {
141+ $ errorMsg = "Error durante proceso de despareado, por favor vuelve a intentarlo. " ;
142+ if ( $ errorMsg <> '' )
143+ {
144+ return $ errorMsg ;
145+ }
146+ }
147+
126148 }
127149
128150 return true ; // Required return value of a hook function.
129151}
152+
0 commit comments