Skip to content

Commit 734a1f4

Browse files
committed
Save preferences but fixed
1 parent 0e4b32e commit 734a1f4

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

extensions/Latch/LatchAccount.php

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,30 @@ function onUserLoadAfterLoadFromSession( $user )
6969
function onPreferencesForm( $user, &$preferences )
7070
{
7171

72-
if( dbHelper::isPaired( ) ) //$user->getId() ) )//if the user is paired render the view with unpair options in the form
72+
if( dbHelper::isPaired( ) ) //if the user is paired render the view with unpair options in the form
7373
{
74-
74+
/*
75+
$preferences['formUnpairedTextbox'] = array(
76+
'type' => 'text',
77+
'section' => '2FA/Latch',
78+
'label-message' => 'prefs-2FA-label',
79+
'maxlength' => '6', //OTP is maximum 6 characters.
80+
'id'=>'pairingToken',
81+
);
82+
*/
7583
$preferences['formPairedButton'] = array(
7684
'type' => 'submit',
77-
'section' => '2FA/Latch',//'2nd factor authentication/Latch your account',
85+
'section' => '2FA/Latch',//'2nd factor authentication
7886
'id'=>'unpairButton',
7987
'default' => wfMessage("prefs-2FA-button-unpair"),
8088
);
8189

8290
}
8391

92+
93+
8494
else //if the user is not paired render the view with pair options in the form
8595
{
86-
8796
$preferences['formUnpairedTextbox'] = array(
8897
'type' => 'text',
8998
'section' => '2FA/Latch',
@@ -93,6 +102,13 @@ function onPreferencesForm( $user, &$preferences )
93102
'id'=>'pairingToken',
94103
);
95104

105+
$preferences['formUnpairedButton'] = array(
106+
'type' => 'submit',
107+
'section' => '2FA/Latch',
108+
'id'=>'pairButton',
109+
'default' => wfMessage("prefs-2FA-button-pair"),
110+
);
111+
96112
$preferences['formUnpairedMessage'] = array (
97113
'type' => 'info',
98114
'section' => '2FA/Latch',
@@ -105,15 +121,17 @@ function onPreferencesForm( $user, &$preferences )
105121

106122
function onPreferencesFormPreSave( $formData, $form, $user, &$result )
107123
{
108-
109-
if( !dbHelper::isPaired( ) )//$user->getId('pairingToken') ) ) //the user has not paired Mediawiki account with Latch
110-
{
124+
//the user has not paired Mediawiki account with Latch
125+
if( !dbHelper::isPaired() ) //&& isset( $_POST["formUniredButton"] ) )
126+
{
111127
$oneTimePassword = $formData["formUnpairedTextbox"]; //get the OTP writen by the user in the textbox form
112128
LatchController::doPair($oneTimePassword);
113129
}
114-
else //the user has paired Mediawiki account with Latch
115-
{
130+
//the user has paired Mediawiki account with Latch
131+
else if( dbHelper::isPaired() && isset( $_POST["wpformPairedButton"] ) )
132+
{
116133
LatchController::doUnpair();
117134
}
135+
118136
return true; // Required return value of a hook function.
119137
}

0 commit comments

Comments
 (0)