Topic-icon Two Factor Authentication Generates Javascript-Error

Active Subscriptions:

None
Hello there!

I've installed the SC Login Module V 4.2.4. Regular logins work without any problems, however users who have two factor authentication enabled get the following JavaScript error:

TypeError: jfbcJQuery(...)[0].clone is not a function
http://localhost/media/sourcecoast/js/mod_sclogin.js
Line 38

This concerns the following code block:
// Copy the username/password fields
                    var usernameField = jfbcJQuery(formId + ' :input[name=username]')[0].clone();
                    usernameField.type = 'hidden';
                    usernameField.val = username;
                    jfbcJQuery(otpForm).find("form").append(usernameField.outerHTML);

                    var passwordField = jfbcJQuery(formId + ' :input[name=password]')[0].clone();
                    passwordField.type = 'hidden';
                    passwordField.val = password;
                    jfbcJQuery(otpForm).find("form").append(passwordField.outerHTML);

I've tested it using Joomla 3.4 using the default Protostar template.

Many thanks for your help.

Kind regards,
Romeo
The topic has been locked.
Active Subscriptions:

None
I've fiddled a bit around with mod_sclogin.js, when I remove the brackets from the clone operations:
var usernameField = jfbcJQuery(formId + ' :input[name=username]')[0].clone(); to
var usernameField = jfbcJQuery(formId + ' :input[name=username]').clone();

and
var passwordField = jfbcJQuery(formId + ' :input[name=password]')[0].clone(); to
var passwordField = jfbcJQuery(formId + ' :input[name=password]').clone();

then the JavaScript error disappears, I see that the username and password gets copied:
alert(usernameField.toSource())
alert(passwordField .toSource())

However, after entering the OTP (YubiKey) I get the following Joomla error: "Password cannot be empty".

Thank you for your appreciated support.
The topic has been locked.
Active Subscriptions:

None
Just discovered that there's a new V 4.3 but unfortunately the problem persists in this version as well.
The topic has been locked.
Active Subscriptions:

None
9 years 6 months ago - 9 years 6 months ago #52061 by sconsulting
Bug fixed! :D

I've noticed that usernameField.outerHTML and passwordField.outerHTML did not get appended to the form. I've changed the code as follows and it works like a charm now (see new variables usernameFieldHTML and passworFieldHTML):
// Copy the username/password fields
var usernameField = jfbcJQuery(formId + ' :input[name=username]').clone();
usernameField.val = username;
usernameFieldHTML = '<input type=\"hidden\" name=\"username\" value=\"' + usernameField.val + '\"\>';
jfbcJQuery(otpForm).find("form").append(usernameFieldHTML);

var passwordField = jfbcJQuery(formId + ' :input[name=password]').clone();
passwordField.val = password;
passwordFieldHTML = '<input type=\"hidden\" name=\"password\" value=\"' + passwordField.val + '\"\>';
jfbcJQuery(otpForm).find("form").append(passwordFieldHTML);

Have a nice weekend!
Last edit: 9 years 6 months ago by sconsulting.
The topic has been locked.
Support Specialist
Thanks for the report and for the code that works for you. I'm unsure why you're having issues, but we'll investigate further. This is not a problem we've encountered or heard of before and there are lots of users who use the SCLogin module with OTP enabled.

Can you tell me if you're including jQuery on your page or if you're relying on the inclusion of jQuery from the SCLogin module? My only guess is that you're using a different version of jQuery which isn't supporting the clone operation we're doing above.

Either way, very glad to hear you got things going on your site now with the band-aid. Hopefully, we can get it working for you so you don't have to make fixes to each new release.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
9 years 6 months ago - 9 years 6 months ago #52068 by sconsulting
Hi Alex,

Thanks for your reply! I've tested it on two different Joomla 3.4 installations and experienced the same issue. Both templates I've tried load the Twitter Bootstrap JavaScript Framework using JHtml::_('bootstrap.framework') and according to the following documentation, this will automatically enable the jQuery framework in noConflict mode (version 1.11.1) :
docs.joomla.org/J3.x:Javascript_Frameworks

Maybe this could have lead to the issue I found?

Kind regards,
Romeo
Last edit: 9 years 6 months ago by sconsulting.
The topic has been locked.
Support Specialist
Romeo,
That shouldn't be the issue. We do extensive testing with the jQuery version that is distributed with Joomla. In Joomla 3.3 and 3.4, almost the exact same release of jQuery was included (v1.11.1 vs 1.11.2). I can't imagine that .1 vs .2 made a difference as that should be a very minor release, but we'll investigate further.

We also haven't heard of any reports from users about this, which is doubly strange as people are usually very vocal when they can't login. We'll let you know what we find.

Thanks,
Alex
The topic has been locked.
Support Specialist
Oh yeah.. the listing of library versions included, in case you were curious..
docs.joomla.org/What_version_of_Joomla!_should_you_use%3F
The topic has been locked.
Active Subscriptions:

None
9 years 6 months ago - 9 years 6 months ago #52090 by sconsulting
Thank you Alex.

Just for your info, I've tested it on the following instances:

-> Joomla 3.4.0 using the default Protostar template
-> Joomla 3.4.1 using the free YooTheme Master2 template, available here: yootheme.com/themes/downloads

Both instances are hosted on IIS 8.5 using PHP 5.4.24.

Another small detail, the SC Login module doesn't use any form validation, which means a user could attempt to login with a blank username / password. Using a template override I've added the HTML5 required attribute to the input fields:

/templates/templatename/html/mod_sclogin/joomlaLogin_vertical.php:

<input name="username" tabindex="0" id="sclogin-username" class="input-block-level" alt="username" type="text" placeholder="<?php echo JText::_('MOD_SCLOGIN_USERNAME'); ?>" required>

and

<input name="<?php echo $passwordName; ?>" tabindex="0" id="sclogin-passwd" class="input-block-level" alt="password" type="password" placeholder="<?php echo JText::_('MOD_SCLOGIN_PASSWORD') ?>" required>

This works great in most modern browsers, however IOS Safari doesn't prevent a form submission when a required input form element is left blank. I've then tried the jQuery validation plugin which worked, however on mobile devices the two factor authentication stopped working when using the jQuery validation plugin. Just for your info.

Have a good Sunday!
Last edit: 9 years 6 months ago by sconsulting.
The topic has been locked.