Skip to content

Commit fcb7c38

Browse files
committed
add error control messages
1 parent b15cd77 commit fcb7c38

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

extensions/Latch/LatchAccount.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
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
*/
3637
function 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
*/
114116
function 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+

extensions/Latch/LatchController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ class LatchController
2121
*/
2222
public static function doPair( $otp )
2323
{
24+
$toRet=-1;//return value=-1, error during unpairing process
2425
$api = new Latch( LatchConfig::appId, LatchConfig::secret ); //creation of a Latch API object
2526
$response = $api->pair( $otp ); //send the OTP writen by the user in the textbox
2627
$data = $response->getData( );
27-
echo( $data->accountId );
28+
//echo( $data->accountId );
2829
if( !is_null( $data ) && property_exists( $data, "accountId" ) ) //if the Latch API object contains the accountId
2930
{
3031
$accountId = $data->accountId;
3132
dbHelper::storeAccountId( $accountId );
3233
$toRet=1; //return value=1, pairing process successful
3334
}
34-
$toRet=-1; //return value=-1, error during pairing process
3535
return $toRet;
3636
}
3737
/**
@@ -40,6 +40,7 @@ public static function doPair( $otp )
4040
*/
4141
public static function doUnpair( )
4242
{
43+
$toRet=-1;//return value=-1, error during unpairing process
4344
global $wgUser; //mediawiki global var to get the userID that is currently logged into mediawiki
4445
//if( dbHelper::isPaired( $wgUser->getId() ) )
4546
//{
@@ -52,10 +53,10 @@ public static function doUnpair( )
5253
$toRet=1; //return value=1, unpairing process successful
5354
}
5455
//}
55-
$toRet=-1;//return value=-1, error during unpairing process
5656
return $toRet;
5757
}
5858

59+
5960
/**
6061
* Checks the status of a digital latch, or the status of an operation given as a parameter
6162
*/

linux_install/install.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ chown -R root /usr/share/mediawiki/LocalSettings.php
2525
chgrp -R root /usr/share/mediawiki/LocalSettings.php
2626
chmod -R 775 /usr/share/mediawiki/LocalSettings.php
2727

28-
#ADD INCLUDES TO LocalSettings.php
28+
#ADD CHANGES TO LocalSettings.php
2929
echo "require_once "\'"/usr/share/mediawiki/extensions/Latch/LatchController.php"\'";" >> /usr/share/mediawiki/LocalSettings.php
3030
echo "require_once "\'"/usr/share/mediawiki/extensions/Latch/LatchAccount.php"\'";" >> /usr/share/mediawiki/LocalSettings.php
3131
echo "require_once "\'"/usr/share/mediawiki/extensions/Latch/dbHelper.php"\'";" >> /usr/share/mediawiki/LocalSettings.php
@@ -53,8 +53,7 @@ read DBwikiName
5353
echo "You will be asked for the root password to enter MySQL"
5454
mysql -u root -h $DBserverName -p << EOF
5555
use $DBwikiName;
56-
CREATE TABLE latch ( mw_user_id INT NOT NULL, account_id VARCHAR(256) );
57-
CREATE INDEX mw_user_id ON latch(mw_user_id);
56+
CREATE TABLE latch ( mw_user_id INT NOT NULL, account_id VARCHAR(256), PRIMARY KEY(mw_user_id) );
5857
SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 'latch';
5958
DESCRIBE latch;
6059
EOF

0 commit comments

Comments
 (0)