/**
  * {@inheritdoc}
  */
 protected function authorizeUser(App $app, $email, $password)
 {
     if (isset($app['db'])) {
         $db = $app['db'];
     } else {
         if (isset($app['orm.em'])) {
             $db = $app['orm.em']->getConnection();
         } else {
             throw new Exception("DB connection not found");
         }
     }
     // User array
     $userArray = Users::getInstance($db)->getByEmail($email);
     // User for encode password
     $user = new User($email, $password, array('ROLE_USER'), true, true, true, true);
     // Encoded password
     $encodedPasswd = $app['security.encoder.digest']->encodePassword($password, $user->getSalt());
     if ($userArray['password'] !== $encodedPasswd) {
         $token = false;
     } else {
         // Datetime tomorrow
         $date = new \DateTime('tomorrow');
         // Json Web Token
         $jws = new SimpleJWS(array('alg' => 'RS256'));
         $jws->setPayload(array('uid' => $userArray['id'], 'exp' => $date->format('U')));
         $privateKey = openssl_pkey_get_private('file://' . $app->getAppDir() . '/private.key', '123456789');
         $jws->sign($privateKey);
         $token = $jws->getTokenString();
     }
     return $token;
 }
 /**
  * Delete action page
  * 
  * @param App $app
  * @param int $id
  * @return JsonResponse
  */
 function delete(App $app, $id)
 {
     if (isset($app['db'])) {
         $db = $app['db'];
     } else {
         if (isset($app['orm.em'])) {
             $db = $app['orm.em']->getConnection();
         } else {
             throw new Exception("DB connection not found");
         }
     }
     if ("DELETE" == $app['request']->getMethod()) {
         // Affected rows
         $affectedRows = Users::getInstance($db)->delete($id);
         return new JsonResponse(array('deleted' => $affectedRows > 0), 200);
     }
     return new JsonResponse(array('error' => 'Only method DELETE allowed'), 400);
 }