Created
May 19, 2014 14:50
-
-
Save shadowhand/4f19d9aa0ec4b621ee0d 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 | |
/** | |
* Ushahidi Platform User Login Use Case | |
* | |
* @author Ushahidi Team <team@ushahidi.com> | |
* @package Ushahidi\Platform | |
* @copyright 2014 Ushahidi | |
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) | |
*/ | |
namespace Ushahidi\Usecase\User; | |
use Ushahidi\Entity\User; | |
use Ushahidi\Tool\Validator; | |
use Ushahidi\Tool\PasswordAuthenticator; | |
use Ushahidi\Exception\AuthenticatorException; | |
use Ushahidi\Exception\ValidatorException; | |
use Ushahidi\Usecase\User\LoginUserRepository; | |
class Login | |
{ | |
private $repo; | |
private $valid; | |
private $auth; | |
public function __construct(LoginUserRepository $repo, Validator $valid, PasswordAuthenticator $auth) | |
{ | |
$this->repo = $repo; | |
$this->valid = $valid; | |
$this->auth = $auth; | |
} | |
public function interact(Array $input) | |
{ | |
if (!$this->valid->check($input)) | |
throw new ValidatorException('Failed to validate user login', $this->valid->errors()); | |
$hash = $this->repo->getPasswordHashByUsername($input['username']); | |
// TODO: handle the other bits of A1, like rehashing and brute force checks | |
if (!$this->auth->checkPassword($input['password'], $hash)) | |
throw new AuthenticatorException(sprintf('Invalid password for user "%s"', $input['username'])); | |
return $this->repo->getByUsername($input['username']); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment