summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/EmailLogin/classes
diff options
context:
space:
mode:
authorYaco <franco@reevo.org>2020-06-04 11:01:00 -0300
committerYaco <franco@reevo.org>2020-06-04 11:01:00 -0300
commitfc7369835258467bf97eb64f184b93691f9a9fd5 (patch)
treedaabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/extensions/EmailLogin/classes
first commit
Diffstat (limited to 'www/wiki/extensions/EmailLogin/classes')
-rw-r--r--www/wiki/extensions/EmailLogin/classes/EmailPasswordAuthenticationProvider.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/www/wiki/extensions/EmailLogin/classes/EmailPasswordAuthenticationProvider.php b/www/wiki/extensions/EmailLogin/classes/EmailPasswordAuthenticationProvider.php
new file mode 100644
index 00000000..2c4d133d
--- /dev/null
+++ b/www/wiki/extensions/EmailLogin/classes/EmailPasswordAuthenticationProvider.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace EmailLogin;
+
+use MediaWiki\Auth\AuthenticationRequest;
+use MediaWiki\Auth\AuthenticationResponse;
+use MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider;
+use MediaWiki\Auth\PasswordAuthenticationRequest;
+
+class EmailPasswordAuthenticationProvider extends LocalPasswordPrimaryAuthenticationProvider
+{
+ public function beginPrimaryAuthentication(array $reqs)
+ {
+ $req = AuthenticationRequest::getRequestByClass($reqs, PasswordAuthenticationRequest::class);
+
+ $dbr = wfGetDB(DB_REPLICA);
+ $row = $dbr->selectRow(
+ 'user',
+ ['user_email', 'user_name'],
+ ['user_email' => $req->username],
+ __METHOD__
+ );
+ if (!$row) {
+ return AuthenticationResponse::newAbstain();
+ }
+ $req->username = $row->user_name;
+
+ return parent::beginPrimaryAuthentication([$req]);
+ }
+}