Skip to content

Instantly share code, notes, and snippets.

@shadowhand
Created May 4, 2014 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shadowhand/63fc386a6aa86068b793 to your computer and use it in GitHub Desktop.
Save shadowhand/63fc386a6aa86068b793 to your computer and use it in GitHub Desktop.
user login use case
<?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