Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Chernyi committed Mar 1, 2018
1 parent 7219bb2 commit 75d9f61
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Auth/Repository/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface RepositoryInterface
*
* @return null|RepositoryInterface
*/
public function getByLogin(string $login): ?self;
public function getByLogin(string $login): ?Root;

/**
* Get login fields, eg: ['email', 'username'].
Expand Down
10 changes: 4 additions & 6 deletions src/Auth/Repository/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function login(string $login, string $password): ?Root
return null;
}

if (!password_verify($password, $this->hashPassword($password))) {
if (!password_verify($password, $user->get($this->getPasswordField()))) {
return null;
}

Expand All @@ -56,15 +56,13 @@ public function login(string $login, string $password): ?Root
/**
* {@inheritdoc}
*/
public function getByLogin(string $login): ?RepositoryInterface
public function getByLogin(string $login): ?Root
{
$entity = $this->entity($this->config('auth.entity', 'user'));
foreach ($this->getLoginFields() as $field) {
try {
if ($entity->has([$field => $login])) {
$this->data = $entity->load($login, $field)->getData();

return $this;
return $entity->load($login, $field);
}
} catch (\Throwable $t) {
//If field does not exist, exception will be thrown,
Expand All @@ -73,6 +71,6 @@ public function getByLogin(string $login): ?RepositoryInterface
}
}

return $null;
return null;
}
}
2 changes: 1 addition & 1 deletion src/Auth/Storage/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function setUser(Root $user)
throw new \Exception('wtf/auth cookie storage requires dflydev/fig-cookies package installed');
}

return \Dflydev\FigCookies\Cookie::create('user_id', $user->getId())
return \Dflydev\FigCookies\SetCookie::create('user_id', $user->getId())
->rememberForever()
->withDomain(getenv('APP_HOST'))
->withHttpOnly(true);
Expand Down
8 changes: 5 additions & 3 deletions src/Auth/Storage/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function setUser(Root $user)
'aud' => $this->config('jwt.aud', getenv('APP_HOST')),
'exp' => $this->config('jwt.exp', time() + 604800),
'data' => $data,
], getenv('APP_SECRET'), $this->config('jwt.algorithm'.['HS256'])[0]);
], getenv('APP_SECRET'), $this->config('jwt.algorithm', ['HS256'])[0]);
}

/**
Expand All @@ -43,12 +43,14 @@ public function getUser(): ?Root

// wtf/rest implementation
if ($this->container->has('user')) {
return $this->user;
return $this->entity($this->config('auth.entity'))->setData($this->user);
}

// tuupola/slim-jwt-auth implementation
if ($token = $this->request->getAttribute($this->config('jwt.attribute', 'token'))) {
return is_object($token) && property_exists($token, 'data') ? $token->data : $token;
$data = (array) (is_object($token) && property_exists($token, 'data') ? $token->data : ($token['data'] ?? $token));

return $this->entity($this->config('auth.entity'))->setData($data);
}

return null;
Expand Down

0 comments on commit 75d9f61

Please sign in to comment.