Skip to content

Commit 0189d34

Browse files
committed
Add ability to login user without password check
Make session management steps for OAuth driven workflows possible by separating the act of verifying username & password from setting an authenticated UserData object in the current session. Change-Id: Ie49b9cc0ccf2c9fdcc559fc065b0f5ab4207cd38
1 parent aadeb21 commit 0189d34

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

src/Auth/AuthManager.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,7 @@ public function authenticate( $uname, $password ) {
109109
$user = $this->manager->getUserData( $uname );
110110
$check = Password::comparePasswordToHash( $password, $user->getPassword() );
111111
if ( $check && !$user->isBlocked() ) {
112-
// clear session
113-
foreach ( $_SESSION as $key => $value ) {
114-
unset( $_SESSION[$key] );
115-
}
116-
117-
// generate new session id
118-
session_regenerate_id( true );
119-
120-
// store user info in session
121-
$this->setUser( $user );
122-
112+
$this->login( $user );
123113
return true;
124114

125115
} else {
@@ -128,6 +118,25 @@ public function authenticate( $uname, $password ) {
128118
}
129119

130120

121+
/**
122+
* Add authentication.
123+
*
124+
* @param UserData $user
125+
*/
126+
public function login( UserData $user ) {
127+
// clear session
128+
foreach ( $_SESSION as $key => $value ) {
129+
unset( $_SESSION[$key] );
130+
}
131+
132+
// generate new session id
133+
session_regenerate_id( true );
134+
135+
// store user info in session
136+
$this->setUser( $user );
137+
}
138+
139+
131140
/**
132141
* Remove authentication.
133142
*/

src/Auth/UserManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace Wikimedia\Slimapp\Auth;
2525

26-
use \PDOException;
26+
use PDOException;
2727

2828
/**
2929
* Data access object for users.

0 commit comments

Comments
 (0)