public function requestLoginToken()
    {
        // Get dependencies
        $session = $this->container->sessionHandler;
        $email = $this->container->emailHandler;
        $security = $this->container->accessHandler;
        $userMapper = ($this->container->dataMapper)('UserMapper');
        $body = $this->request->getParsedBody();

        // Fetch all users
        $userList = $userMapper->find();

        // Clean provided email
        $providedEmail = strtolower(trim($body['email']));

        $foundValidUser = false;
        foreach ($userList as $user) {
            if ($user->email === $providedEmail) {
                $foundValidUser = $user;
                break;
            }
        }

        // Did we find a match?
        if (!$foundValidUser) {
            // No, log and silently redirect to home
            $this->container->logger->alert('Failed login attempt: ' . $body['email']);

            return $this->redirect('home');
        }

        // Belt and braces/suspenders double check
        if ($foundValidUser->email === $providedEmail) {
            // Get and set token, and user ID
            $token = $security->generateLoginToken();
            $session->setData([
                $this->loginTokenKey => $token,
                $this->loginTokenExpiresKey => time() + 120,
                'user_id' => $foundValidUser->id,
                'email' => $foundValidUser->email
            ]);

            // Get request details to create login link and email to user
            $scheme = $this->request->getUri()->getScheme();
            $host = $this->request->getUri()->getHost();
            $link = $scheme . '://' . $host;
            $link .= $this->container->router->pathFor('adminProcessLoginToken', ['token' => $token]);

            // Send message
            $email->setTo($providedEmail, '')
                ->setSubject('PitonCMS Login')
                ->setMessage("Click to login\n\n {$link}")
                ->send();
        }

        // Direct to home page
        return $this->redirect('home');
    }
public function requestLoginToken()
    {
        // Get dependencies
        $session = $this->container->sessionHandler;
        $email = $this->container->emailHandler;
        $security = $this->container->accessHandler;
        $userMapper = ($this->container->dataMapper)('UserMapper');
        $body = $this->request->getParsedBody();

        // Fetch all users
        $userList = $userMapper->find();

        // Clean provided email
        $providedEmail = strtolower(trim($body['email']));

        $foundValidUser = false;
        foreach ($userList as $user) {
            if ($user->email === $providedEmail) {
                $foundValidUser = $user;
                break;
            }
        }

        // Did we find a match?
        if (!$foundValidUser) {
            // No, log and silently redirect to home
            $this->container->logger->alert('Failed login attempt: ' . $body['email']);

            return $this->redirect('home');
        }

        // Belt and braces/suspenders double check
        if ($foundValidUser->email === $providedEmail) {
            // Get and set token, and user ID
            $token = $security->generateLoginToken();
            $session->setData([
                $this->loginTokenKey => $token,
                $this->loginTokenExpiresKey => time() + 120,
                'user_id' => $foundValidUser->id,
                'email' => $foundValidUser->email
            ]);

            // Get request details to create login link and email to user
            $scheme = $this->request->getUri()->getScheme();
            $host = $this->request->getUri()->getHost();
            $link = $scheme . '://' . $host;
            $link .= $this->container->router->pathFor('adminProcessLoginToken', ['token' => $token]);

            // Send message
            $email->setTo($providedEmail, '')
                ->setSubject('PitonCMS Login')
                ->setMessage("Click to login\n\n {$link}")
                ->send();
        }

        // Direct to home page
        return $this->redirect('home');
    }
public function requestLoginToken ( ) { // Get dependencies $ session = $ this -> container -> sessionHandler ; $ email = $ this -> container -> emailHandler ; $ security = $ this -> container -> accessHandler ; $ userMapper = ( $ this -> container -> dataMapper ) ( 'UserMapper' ) ; $ body = $ this -> request -> getParsedBody ( ) ; // Fetch all users $ userList = $ userMapper -> find ( ) ; // Clean provided email $ providedEmail = strtolower ( trim ( $ body [ 'email' ] ) ) ; $ foundValidUser = false ; foreach ( $ userList as $ user ) { if ( $ user -> email === $ providedEmail ) { $ foundValidUser = $ user ; break ; } } // Did we find a match? if ( ! $ foundValidUser ) { // No, log and silently redirect to home $ this -> container -> logger -> alert ( 'Failed login attempt: ' . $ body [ 'email' ] ) ; return $ this -> redirect ( 'home' ) ; } // Belt and braces/suspenders double check if ( $ foundValidUser -> email === $ providedEmail ) { // Get and set token, and user ID $ token = $ security -> generateLoginToken ( ) ; $ session -> setData ( [ $ this -> loginTokenKey => $ token , $ this -> loginTokenExpiresKey => time ( ) + 120 , 'user_id' => $ foundValidUser -> id , 'email' => $ foundValidUser -> email ] ) ; // Get request details to create login link and email to user $ scheme = $ this -> request -> getUri ( ) -> getScheme ( ) ; $ host = $ this -> request -> getUri ( ) -> getHost ( ) ; $ link = $ scheme . '://' . $ host ; $ link .= $ this -> container -> router -> pathFor ( 'adminProcessLoginToken' , [ 'token' => $ token ] ) ; // Send message $ email -> setTo ( $ providedEmail , '' ) -> setSubject ( 'PitonCMS Login' ) -> setMessage ( "Click to login\n\n {$link}" ) -> send ( ) ; } // Direct to home page return $ this -> redirect ( 'home' ) ; }
Request Login Token

Validates email and sends login link to user
Request Login Token