Define fallback for request IP when persisting user

Bug: T237554
Change-Id: I18f57a523a6515f593963a9c149374bd6f6c73b4
This commit is contained in:
Dejan Savuljesku 2019-11-12 09:47:12 +01:00 committed by Reedy
parent 0a7729a578
commit 54fc8a0cbf
2 changed files with 9 additions and 2 deletions

View file

@ -22,6 +22,7 @@ namespace MediaWiki\Extension\OATHAuth\Key;
use Base32\Base32;
use jakobo\HOTP\HOTP;
use MediaWiki\Extension\OATHAuth\OATHUser;
use MediaWiki\Extension\OATHAuth\OATHUserRepository;
use Psr\Log\LoggerInterface;
use MediaWiki\Logger\LoggerFactory;
use DomainException;
@ -195,6 +196,8 @@ class TOTPKey implements IAuthKey {
$auth = MediaWikiServices::getInstance()->getService( 'OATHAuth' );
$module = $auth->getModuleByKey( 'totp' );
/** @var OATHUserRepository $userRepo */
$userRepo = MediaWikiServices::getInstance()->getService( 'OATHUserRepository' );
$user->addKey( $this );
$user->setModule( $module );

View file

@ -29,6 +29,7 @@ use BagOStuff;
use ConfigException;
use User;
use stdClass;
use RequestContext;
class OATHUserRepository {
/** @var ILoadBalancer */
@ -119,11 +120,14 @@ class OATHUserRepository {
/**
* @param OATHUser $user
* @param string $clientInfo
* @param string|null $clientInfo
* @throws ConfigException
* @throws MWException
*/
public function persist( OATHUser $user, $clientInfo ) {
public function persist( OATHUser $user, $clientInfo = null ) {
if ( !$clientInfo ) {
$clientInfo = RequestContext::getMain()->getRequest()->getIP();
}
$prevUser = $this->findByUser( $user->getUser() );
$data = $user->getModule()->getDataFromUser( $user );