Správny výpis výnimky v UserManager

sidzejs
Člen | 9
+
0
-

Dobrý deň,
pracujem pri prihlasovaní s UserManagerom, ktorý bol v sandboxe. Pri správnych prihlasovacích údajoch je všetko OK, ale ak sa zadá zlé meno alebo heslo tak hádže problém „Class ‚App\Model\NS\AuthenticationException‘ not found ". Potreboval by som pritom aby mi to vyhodilo nejak rozumne výpis "zlé meno alebo heslo“. Keď som tam skúšal dať $this->flashMessage(‚zlé meno alebo heslo‘); tak to samozrejme nefunguje, pretože sa nejedná o presenter. Vie mi s tým niekto poradiť? Za vaše odpovede vopred ďakujem :)

<?php

namespace App\Model;

use Nette;
use Nette\Security\Passwords;


/**
 * Users management.
 */
class UserManager implements Nette\Security\IAuthenticator{

    private $database;
    private $table = "users";
    public static $user_salt = "AEcx199opQ";


    public function __construct(Nette\Database\Context $database)
    {
        $this->database = $database;
    }

    /**
     * Performs an authentication
     * @param  array
     * @return Nette\Security\Identity
     * @throws Nette\Security\AuthenticationException
     */
    public function authenticate(array $credentials) {
        list($username, $password) = $credentials;

        $row = $this->database->table('users')->where('email = ?', $username)->fetch();

        if (!$row) {
           throw new NS\AuthenticationException("User '$username' not found.", self::IDENTITY_NOT_FOUND);
        }

        if ($row->password !== sha1($password . self::$user_salt)) {
            throw new NS\AuthenticationException("Invalid password.", self::INVALID_CREDENTIAL);
        }

        return new Nette\Security\Identity($row->id, $row->role, $row->toArray());
    }

}
CZechBoY
Člen | 3608
+
+1
-

Michas aliasovany a full namespacy.
S timto kodem co mas je potreba dat nahoru use Nette\Security as NS;

sidzejs
Člen | 9
+
0
-

CZechBoY napsal(a):

Michas aliasovany a full namespacy.
S timto kodem co mas je potreba dat nahoru use Nette\Security as NS;

Funguje to, ďakujem !