Skip to content

Conversation

@faynt0
Copy link

@faynt0 faynt0 commented Aug 11, 2016

Summary of Changes

  • Refactored 2FA from FOF to Joomla Core
  • Removed dependecies to FOF
  • Refactored 2FA templates to JLayouts Reverted back for B/C, removed the FOF part that resolves the template paths and used JPluginHelper instead.

Testing Instructions

  • Step 1 Activate the Twofactor Auth plugins ( Google Auth, Yubikey) in the backend
  • Step 2 Frontend: Go to the "Edit user profile" page and activate 2FA (Google Auth) and set up the authenticator
  • Step 2.1 Select Yubikey from the dropdown menu and it's template should be loaded ( Yubikey FOF dependecy was only related to the template)
  • Step 3 Logout and log in using your Google authenticator ( Frontend & Backend)
  • Step 4 After applying the patch Step 1-3 should work as before.

To test that custom templates still work create a "form.php" in "templates/protostar//html/plg_twofactorauth_totp" (Google Auth) with an echo() or similar and
go to Frontend -> Edit User profile , select Google Autheticator and your form's content should be shown.

// Stop output buffering and get the form contents
$html = @ob_get_clean();
$layout = new JLayoutFile('plugins.twofactorauth.yubikey.form');
$data = ['new_totp' => $new_totp];
Copy link
Contributor

@izharaazmi izharaazmi Aug 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is >= PHP 5.4 only?

moved files up a level because there are no namespaces yet
cleaned up xml files
simplified array extraction
@faynt0
Copy link
Author

faynt0 commented Aug 11, 2016

@izharaazmi thanks for pointing out, I changed the syntax.

@izharaazmi
Copy link
Contributor

IMO, the plugin default layouts should be placed inside the plugin itself. Same for the language files though. But since this plugin is part of core, I am not sure if this applies here.

I also believe uninstall of the plugin should remove all its elements. Certainly, except the library classes it depends on.

@roland-d
Copy link
Contributor

@izharaazmi The language files can stay where they are I believe because all other core plugins have their language files in the admin language folder.

As for removing the library classes, that is a more difficult question because you cannot delete them when you uninstall 1 plugin because the other needs it nor can you uninstall it when you delete the 2nd plugin because theoretically you could install another authentication plugin that requires it. So I would say we can leave it as-is.

@izharaazmi
Copy link
Contributor

@roland-d I said except...

Certainly, except the library classes it depends on.

I meant to say – when uninstalling the plugin remove the default layouts too alongwith any plugin only files . And keep the library classes and any layout overrides which is obvious anyway. You too are saying the same.

IMO, the plugin default layouts should be placed inside the plugin itself.

IMO, /layouts is not the best place for plugin's default layout files and uninstalling the plugin will not (and should not) remove it from there.

@roland-d
Copy link
Contributor

@izharaazmi Using the /layouts folder, we already have a layout there for the user profile plugin, so I believe it is the correct place.

As for the uninstallation, if I uninstall the profile plugin the layout is going to stay as well. The question should rather be should all Joomla core be rewritten to be fully uninstallable, perhaps but that is out-of-scope for this pull request.

@izharaazmi
Copy link
Contributor

Yeah, agreed on that. We'll talk over it some other day 👍

*
* @since 1.0
*/
class Base32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class and file name are incorrect.

@mbabker
Copy link
Contributor

mbabker commented Aug 11, 2016

@izharaazmi Using the /layouts folder, we already have a layout there for the user profile plugin, so I believe it is the correct place.

Just because that has been done already does not make it correct or even set precedent. The voting plugin and page navigation plugins both use tmpl/ directories for layouts. The stats plugin uses JLayout with a bunch of code inlined into it. So the existing practice for the majority is to keep the code contained in the extension, NOT use the global directory.

@roland-d
Copy link
Contributor

I am sure if we put it in the tmpl/ folder the comment would have been why we don't put it in the layouts folder :/

@mbabker
Copy link
Contributor

mbabker commented Aug 11, 2016

Well right now the plugin makes use of a tmpl/ folder so for B/C reasons whatever the logic for layout overrides is has to stay in place otherwise this cannot be accepted before 4.0 because it will cause HTML changes on sites implementing an override.

@wilsonge
Copy link
Contributor

This is a large b/c break - we have a JPlugin helper method (https://github.com/joomla/joomla-cms/blob/staging/libraries/cms/plugin/helper.php#L38) that will keep b/c with the FOF layouts and whichever way we go with that extension specific layouts should 100% go in the extension directory and NOT the global layout directory. As Michael says see how roberto did the stats plugin

@Bakual
Copy link
Contributor

Bakual commented Aug 11, 2016

Imho, as long as 3rd parties can't install stuff into the layouts folder without custom installation scripts, our core extensions shouldn't do it as well.
The layouts folder should only contain JLayouts which are reusable across various extensions. Obviously that isn't the case today but it should be.
The proper place for an extension specific layout is the tmpl folder.

Or we make a move and let 3rd parties install their JLayouts into eg /layouts/com_foo/bar.php (similar to the media folder).

@izharaazmi
Copy link
Contributor

@Bakual 👍
However, I'd like to do it the other way around. Centralise extension specific files / layouts / media / language (already) within the extension directory as much as possible.

@brianteeman
Copy link
Contributor

Cant say I am a fan of having a file called Totp.php and another called totp.php

@faynt0
Copy link
Author

faynt0 commented Aug 12, 2016

First of all thanks everyone for your input, in the recent changes I got the autoloading to work like some of you mentioned.

Due to your B/C concerns I reverted the changes to the templating but removed and replaced the FOF part that handles the custom template path

@brianteeman
Copy link
Contributor

I have tested this item ✅ successfully on 4bed2e5

applied PR and confirmed that both yubikey and google authenticator worked for site and admin login


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11553.

@faynt0
Copy link
Author

faynt0 commented Aug 12, 2016

Added small test instruction for custom templates.


// Include the form.php from a template override. If none is found use the default.
$path = FOFPlatform::getInstance()->getTemplateOverridePath('plg_twofactorauth_totp', true);
$path = JPATH_THEMES . "/" . JFactory::getApplication()->getTemplate() . "/html/plg_twofactorauth_totp";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use JPluginHelper::getLayoutPath(). It'll also eliminate the need for the if/else include, you just include the return from that method. Same for the other plugin.

{
include_once __DIR__ . '/tmpl/form.php';
}
include_once JPluginHelper::getLayoutPath('twofactorauth', 'yubikey', "form");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think layouts should not be include_once'd. Please verify this and amend if needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@izharaazmi Why would we need include here? The form is not going to change during runtime is it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. In this specific case, it may not apply but it is a general practice to 'require' a layout file. An 'include' may also be preferred sometimes.
  2. If we call this plugin twice in a request cycle, 2nd will output nothing. Again for this case this may not be an issue, but *_once are costly anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has always been a require_once as you can see in the old code and hasn't given a problem so far.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... hasn't given a problem so far.

is not a good reason to keep doing something. To me *_once should be used only when any attempt to include the file for a second time may cause an issue such as for class definitions or function declarations etc.

Any other code should be able to load as many time as needed. See the various Joomla modules for example:

mod_footer would normally never be called twice but modules/mod_footer/mod_footer.php:37 still calls it using require. For me it is the correct approach. No need to pose an unnecessary job to check against included_files to the interpreter.

@andrepereiradasilva
Copy link
Contributor

andrepereiradasilva commented Dec 4, 2016

if the intention is to remove fof in joomla 4.0 this should be rebased to 4.0 branch

@Bakual
Copy link
Contributor

Bakual commented Dec 4, 2016

Why? this could already be done in J3 fine.

@mbabker
Copy link
Contributor

mbabker commented May 21, 2017

Is this still being worked on?

@ghost
Copy link

ghost commented May 27, 2017

If this PR get no Response, it will be closed at 22th June 2017.

@roland-d
Copy link
Contributor

I guess the students have given up on this. @icampus any idea?

@faynt0
Copy link
Author

faynt0 commented May 30, 2017

I kind of fail to see what is left to be done here, is it about the include vs. include_once debate?

@roland-d
Copy link
Contributor

roland-d commented Jun 3, 2017

@faynt0 At least the PR needs to be updated so it is in-sync with the staging branch.

@ghost
Copy link

ghost commented Jun 21, 2017

@roland-d can you please have a Look at Status of this PR?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/11553.

@roland-d
Copy link
Contributor

@franz-wohlkoenig As far as I can see this needs testing as @faynt0 already updated it with the staging branch.

@ghost
Copy link

ghost commented Jun 22, 2017

thanks @roland-d

@ghost
Copy link

ghost commented Jun 23, 2017

@brianteeman can you please test again?

@roland-d
Copy link
Contributor

roland-d commented Aug 8, 2017

@faynt0 could you please bring this up-to-date with the J4 codebase? Pretty please :) Ping @wilsonge as well if you have questions.

@wilsonge
Copy link
Contributor

wilsonge commented Aug 8, 2017

We need to update the Encrypt code with the latest version. change the branch to be against J4 and I promise I will get this merged!

@wilsonge
Copy link
Contributor

OK i've ported this in #17687

@wilsonge wilsonge closed this Aug 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants