app/library/Auth.php: use Httpcp\Auth\Result
This commit is contained in:
parent
d4902331cf
commit
1e9203f35f
1 changed files with 28 additions and 16 deletions
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
namespace Httpcb;
|
||||
|
||||
use Httpcb\OAuth\UserData\UserDataInterface;
|
||||
use Phalcon\Mvc\User\Component;
|
||||
use App\Model\Data\User;
|
||||
use App\Model\Data\User,
|
||||
Httpcb\OAuth\UserData\UserDataInterface,
|
||||
Httpcb\Auth\Result,
|
||||
Phalcon\Mvc\User\Component;
|
||||
|
||||
class Auth extends Component
|
||||
{
|
||||
|
|
@ -18,7 +19,7 @@ class Auth extends Component
|
|||
*
|
||||
* @param string $email_username
|
||||
* @param string $password
|
||||
* @return bool
|
||||
* @return Result
|
||||
*/
|
||||
public function login($email_username, $password)
|
||||
{
|
||||
|
|
@ -26,6 +27,11 @@ class Auth extends Component
|
|||
$user = User::findFirstByUsernameOrEmail($email_username);
|
||||
|
||||
if ($user) {
|
||||
|
||||
if ($user->status == User::STATUS_SUSPENDED) {
|
||||
return new Result(Result::FAILURE_ACCOUNT_SUSPENDED);
|
||||
}
|
||||
|
||||
// Verify password
|
||||
$hash = $user->getPassword();
|
||||
if (strlen($hash) > 1 && $this->security->checkHash($password, $hash)) {
|
||||
|
|
@ -34,33 +40,39 @@ class Auth extends Component
|
|||
|
||||
$this->eventsManager->fire('auth:onLogin', $this, 'password');
|
||||
|
||||
return true;
|
||||
return new Result(Result::SUCCESS);
|
||||
}
|
||||
return new Result(Result::FAILURE_INVALID_CREDENTIALS);
|
||||
}
|
||||
return false;
|
||||
return new Result(Result::FAILURE_IDENTITY_NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Login using OAuth
|
||||
*
|
||||
* @param UserDataInterface $data
|
||||
* @return bool
|
||||
* @return Result
|
||||
*/
|
||||
public function loginOauth(UserDataInterface $data)
|
||||
{
|
||||
$user = User::findFirstByOAuthID($data);
|
||||
|
||||
// Did not find any user.
|
||||
if (!$user) {
|
||||
return false;
|
||||
if ($user) {
|
||||
|
||||
if ($user->getStatus() == User::STATUS_SUSPENDED) {
|
||||
return new Result(Result::FAILURE_ACCOUNT_SUSPENDED);
|
||||
}
|
||||
|
||||
$this->setIdentity($user->getId());
|
||||
|
||||
$this->eventsManager->fire('auth:onLogin', $this,
|
||||
"OAuth {$data->getProvider()}");
|
||||
|
||||
|
||||
return new Result(Result::SUCCESS);
|
||||
}
|
||||
|
||||
$this->setIdentity($user->getId());
|
||||
|
||||
$this->eventsManager->fire('auth:onLogin', $this,
|
||||
"OAuth {$data->getProvider()}");
|
||||
|
||||
return true;
|
||||
return new Result(Result::FAILURE_IDENTITY_NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Reference in a new issue