public function login(string $username, string $password, Session $session)
    {
        if ($session->has('authentication', 'user_id'))
        {
            throw new AuthenticationError(
                "Already logged in",
                AuthenticationError::DUPLICATE_SESSION
            );
        }

        $cl = $this->getUserClass();
        $this->user = new $cl;
        try
        {
            $this->user->obtainFromLogin($username, $password);
        }
        catch (AuthenticationError $e)
        {
            throw $e;
        }
        catch (\Exception $e)
        {
            throw new AuthenticationError("Login failed", $e->getCode(), $e); 
        }

        $session->set('authentication', 'user_id', $this->user->getUserID());
        return $this->user;
    }
public function login(string $username, string $password, Session $session)
    {
        if ($session->has('authentication', 'user_id'))
        {
            throw new AuthenticationError(
                "Already logged in",
                AuthenticationError::DUPLICATE_SESSION
            );
        }

        $cl = $this->getUserClass();
        $this->user = new $cl;
        try
        {
            $this->user->obtainFromLogin($username, $password);
        }
        catch (AuthenticationError $e)
        {
            throw $e;
        }
        catch (\Exception $e)
        {
            throw new AuthenticationError("Login failed", $e->getCode(), $e); 
        }

        $session->set('authentication', 'user_id', $this->user->getUserID());
        return $this->user;
    }
public function login ( string $ username , string $ password , Session $ session ) { if ( $ session -> has ( 'authentication' , 'user_id' ) ) { throw new AuthenticationError ( "Already logged in" , AuthenticationError :: DUPLICATE_SESSION ) ; } $ cl = $ this -> getUserClass ( ) ; $ this -> user = new $ cl ; try { $ this -> user -> obtainFromLogin ( $ username , $ password ) ; } catch ( AuthenticationError $ e ) { throw $ e ; } catch ( \ Exception $ e ) { throw new AuthenticationError ( "Login failed" , $ e -> getCode ( ) , $ e ) ; } $ session -> set ( 'authentication' , 'user_id' , $ this -> user -> getUserID ( ) ) ; return $ this -> user ; }
Check if the provided details contain a valid login.
@param string $username The user to log in
@param string $password The password to verify
@param Wedeto\HTTP\Session $session The session to log into
@throws Wedeto\Auth\AuthenticationError When logging in fails
@return Wedeto\Auth\UserInterface The logged in user
Check if the provided details contain a valid login .