Provide a stable method for checking whether a user has enabled OATH

This makes it possible to check from another extension whether the
user has strong login security, without depending on internals
which can change at any time.

(The TwoFactorEnabled hook was intended for something like this
but it operates on $wgUser which makes it useless for logins.)

Change-Id: Ie15c45c9b29de0a0f926c2467808ca144f05e866
This commit is contained in:
Gergő Tisza 2016-11-15 23:13:59 +00:00
parent cd72757e4d
commit 160daf2c05

View file

@ -6,6 +6,16 @@
* @ingroup Extensions
*/
class OATHAuthUtils {
/**
* Check whether OATH two-factor authentication is enabled for a given user.
* This is a stable method that does not change and can be used in other extensions.
* @param User $user
* @return bool
*/
public static function isEnabledFor( User $user ) {
$oathUser = OATHAuthHooks::getOATHUserRepository()->findByUser( $user );
return $oathUser && $oathUser->getKey();
}
/**
* Encrypt an aray of variables to put into the user's session. We use this