Created
May 4, 2014 01:06
-
-
Save shadowhand/63fc386a6aa86068b793 to your computer and use it in GitHub Desktop.
user login use case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Ushahidi\Usecase\User; | |
use Ushahidi\Entity\User; | |
use Ushahidi\Entity\UserRepository; | |
use Ushahidi\Tool\Validator; | |
use Ushahidi\Tool\PasswordAuthenticator; | |
use Ushahidi\Exception\Login as LoginException; | |
class Login | |
{ | |
private $repo; | |
private $valid; | |
private $auth; | |
public function __construct(UserRepository $repo, Validator $valid, PasswordAuthenticator $auth) | |
{ | |
$this->repo = $repo; | |
$this->valid = $valid; | |
$this->auth = $auth; | |
} | |
public function interact(User $user) | |
{ | |
$this->valid->check($user); | |
// Password is plaintext at this point, we will check after locating the user | |
$password = $user->password; | |
// Attempt to load the member user | |
$member = $this->repo->getByUsername($user->username); | |
// TODO: handle the other bits of A1, like rehashing and brute force checks | |
$this->auth->checkPassword($password, $member->password); | |
return $member->id; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment