Ejemplo n.º 1
0
 /**
  * 根据加密串发送企业消息。
  * @Author   Woldy
  * @DateTime 2016-05-12T09:15:19+0800
  * @param    [type]                   $ACCESS_TOKEN [description]
  * @param    [type]                   $config      [description]
  * @param    [type]                   $code        [description]
  * @return   [type]                                [description]
  */
 public static function sendMessageByCode($ACCESS_TOKEN, $config, $code)
 {
     $join = self::decode($code);
     $param = json_decode($join, true);
     if (!isset($config->get('dd')['notice'][$param['user']])) {
         die('api用户不存在!');
     } else {
         if ($config->get('dd')['notice'][$param['user']]['password'] != $param['password']) {
             die('api密码错误!');
         } else {
             $AgentID = $config->get('dd')['AgentID'];
             $content = base64_decode($param['content']);
             $touser = $config->get('dd')['notice'][$param['user']]['touser'];
             if (isset($param['emails']) && !empty($param['emails'])) {
                 $touser = [];
                 $emails = explode(',', $param['emails']);
                 foreach ($emails as $email) {
                     array_push($touser, self::getUser($email));
                 }
                 $touser = implode('|', $touser);
             }
             $toparty = $config->get('dd')['notice'][$param['user']]['toparty'];
             self::sendMessage($touser, $toparty, $content, $AgentID, $ACCESS_TOKEN);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * /
  * @param  [type] $app [description]
  * @return [type]      [description]
  */
 public function route($app)
 {
     $app->view->setLayout('frontend');
     $app->get('/login', function () use($app) {
         $app->render('login');
     })->name('user_login_form');
     $app->post('/login', function () use($app) {
         $credentials = $app->handler->handlePostRequest();
         $app->doorman->login($credentials);
         if ($app->doorman->isUserAuthenticated()) {
             $app->redirect('admin_panel');
         } else {
             $app->redirect('user_login_form');
         }
     })->name('user_login');
     $app->get('/signup', function () use($app) {
         $app->render('signup');
     })->name('user_signup_form');
     $app->post('/signup', function () use($app) {
         $record = new Record($app->request->post());
         $token = User::query($app->db, 'signUp', $record);
         $sent = $app->handler->sendSignUpConfirmation($record, $token);
         $app->redirect('user_login_form');
     })->name('user_signup');
     $app->get('/signup/confirm/:token', function ($user_id, $token) use($app) {
         $result = User::query($app->db, 'validate', $token, 'activation');
         if ((int) $result->isSuccessful()) {
             $app->redirect('user_login');
         }
         $app->errorForbidden();
     })->name('confirm_signup')->conditions(array('token' => '\\w+'));
     $app->get('/password/forgot', function () use($app) {
         $app->render('password.forgot');
     })->name('forgot_password_form');
     $app->post('/password/forgot', function () use($app) {
         $record = new Record($app->request->post());
         $token = User::query($app->db, 'forgot', $record->get('user_id'));
         $sent = $app->handler->sendPasswordReset($record, $token);
         $app->redirect('user_login_form');
     })->name('forgot_password');
     $app->get('/password/new/:token', function ($token) use($app) {
         $result = User::query($app->db, 'validate', $token, 'forgot');
         if ($result->isSuccessful()) {
             $app->render('password.new');
             $app->stop();
         } else {
             $app->handler->errorForbidden();
         }
     })->name('new_password_form')->conditions(array('token' => '\\w+'));
     $app->post('/password/new', function () use($app) {
         $record = new Record($app->request->post());
         $result = User::query($app->db, 'resetPassword', $record->get('new_password'));
         $app->redirect($app->urlFor('user_login_form'));
     })->name('new_password');
     return $app;
 }
 /**
  * Check if the recipe ingredient qty is available in the
  * ridge or not.
  *
  * @param  Ingredient $contestant [description]
  * @return boolean                return TRUE if qty can be met, FALSE if not
  */
 public function isSatisfiedBy($contestant)
 {
     $qty_available = 0;
     if ($this->usable_ingredients->count()) {
         if ($this->usable_ingredients->get($contestant->getName())) {
             $qty_available = $this->usable_ingredients->get($contestant->getName())->getQty();
         }
     }
     if ($contestant->getQty() <= $qty_available) {
         return TRUE;
     }
     $this->addMessage('INGREDIENTS', 'Required amount of ingredients is not available in the fridge.');
     return FALSE;
 }
Ejemplo n.º 4
0
 /**
  * /
  * @param  [type] $app [description]
  * @return [type]      [description]
  */
 public function route($app)
 {
     /*
      * UPLOAD
      */
     $app->get('/upload', function () use($app) {
         $app->render('upload');
     });
     $app->post('/upload', function () use($app) {
         $validator = new \FileUpload\Validator\Simple(1024 * 1024 * 2, $app->allowedFileTypes);
         $pathresolver = new \FileUpload\PathResolver\Simple('/var/www/html/files/');
         $filesystem = new \FileUpload\FileSystem\Simple();
         $fileupload = new \FileUpload\FileUpload($_FILES['files'], $_SERVER);
         $fileupload->setPathResolver($pathresolver);
         $fileupload->setFileSystem($filesystem);
         $fileupload->addValidator($validator);
         list($files, $headers) = $fileupload->processAll();
         foreach ($headers as $header => $value) {
             $app->response->headers->set($header . ': ' . $value);
         }
         $body = json_encode(array('files' => $files));
         $app->response->setBody($body);
         $app->stop();
     });
     return $app;
 }
Ejemplo n.º 5
0
 /**
  * /
  * @param  [type] $app [description]
  * @return [type]      [description]
  */
 public function route($app)
 {
     $app->get('', function () use($app) {
     });
     $app->post('', function () use($app) {
     });
 }
Ejemplo n.º 6
0
 /**
  * Saves the new application key if there isn't already one set
  * We need this set early on so it doesn't screw up our tokens
  * and password hashes.
  *
  * @return void
  */
 public function saveNewApplicationKey()
 {
     $env = $this->EnvironmentFileManager->get();
     if (!array_key_exists('APP_KEY', $env)) {
         $this->EnvironmentFileManager->merge(['APP_KEY' => str_random(32)]);
     }
 }
Ejemplo n.º 7
0
 /**
  * /
  * @param  [type] $app [description]
  * @return [type]      [description]
  */
 public function route($app)
 {
     $app->post('/api/calendar', function () use($app) {
     });
     $app->get('/api/event/:id', function () use($app) {
     });
     $app->post('/api/event/save', function () use($app) {
     });
     return $app;
 }
Ejemplo n.º 8
0
 /**
  * Makes a request to the Yelp API and returns the response
  *
  * @param    string $path    The path of the APi after the domain
  *
  * @return   stdClass The JSON response from the request
  * @throws   Exception
  */
 protected function request($path)
 {
     $url = $this->buildUnsignedUrl($this->apiHost, $path);
     try {
         $response = $this->httpClient->get($url, ['auth' => 'oauth']);
     } catch (ClientException $e) {
         $exception = new Exception($e->getMessage());
         throw $exception->setResponseBody($e->getResponse()->getBody());
     }
     return json_decode($response->getBody());
 }
Ejemplo n.º 9
0
 /**
  * /
  * @param  [type] $app [description]
  * @return [type]      [description]
  */
 public function route($app)
 {
     $app->get('/admin/:appliance', function ($appliance) use($app) {
         $app->response->headers->set('Content-Type', 'text/html');
         $info = array('' => '');
         $app->handler->setViewInfo($info);
         $body = $app->handler->render($appliance);
         $app->response->setBody($body);
         $app->stop();
     });
 }
Ejemplo n.º 10
0
    /**
     * Sends A requst for shipping label and info to endicia
     * @param  array $data Array of data to be formated as XML see Endicia documentation
     * @return array The Response data from Endicia as an array , endica actually returns XML
     */
    public function request_shipping_label($data)
    {
        // Note you may want to associate this in some other way, like with a database ID.
        $this->PartnerTransactionID = substr(uniqid(rand(), true), 0, 10);
        $xml = '<LabelRequest ImageFormat="GIF" Test="YES">
					<RequesterID>' . $this->RequesterID . '</RequesterID>
					<AccountID>' . $this->AccountID . '</AccountID>
					<PassPhrase>' . $this->PassPhrase . '</PassPhrase>
					<PartnerTransactionID>' . $this->PartnerTransactionID . '</PartnerTransactionID>';
        if (!empty($data)) {
            foreach ($data as $node_key => $node_value) {
                $xml .= '<' . $node_key . '>' . $node_value . '</' . $node_key . '>';
            }
        }
        $xml .= '<ResponseOptions PostagePrice="TRUE"/>
				</LabelRequest>';
        $data = ['labelRequestXML' => $xml];
        $response = $this->client->get('https://labelserver.endicia.com/LabelService/EwsLabelService.asmx/GetPostageLabelXML', ['query' => $data]);
        return $response->xml();
    }
Ejemplo n.º 11
0
 /**
  * [saveSiteSettings description]
  * @return [type] [description]
  */
 public function saveSiteSettings()
 {
     if ($check = $this->canEdit()) {
         $content = $this->file->get($this->settings);
         $field = str_replace(' ', '', trim("'{$this->input['item_name']}'=>"));
         $old_value = \Tool::getBetween($content, $field, ',');
         $search = $field . $old_value;
         if (isset($this->input['action'])) {
             // Process true/false
             $replace = $field . $this->input['action'];
         } else {
             // Process values
             $replace = $field . $this->input['value'];
             if ($this->input['item_name'] == 'theme') {
                 $replace = $field . "'{$this->input['value']}'";
             }
         }
         $content = str_replace($search, $replace, $content);
         $this->file->put($this->settings, $content);
         return $this->setSuccess('alert.success.settings_saved');
     } else {
         return $check;
     }
 }
Ejemplo n.º 12
0
 /**
  * Get Parents Recursively
  *
  * @param  [type] $page      [description]
  * @param  string $direction [description]
  * @return [type]            [description]
  */
 public function getRecursiveParents($page, $sort = 'ASC')
 {
     // new item list object to store parents
     // this way we have access to all page vars
     $parents = new ItemList();
     // starting at current page loop through in
     // reverse order until our parent page doesnt have a parent
     while ($page->get('parent') != 0) {
         $page = new Page($page->get('parent'));
         $parents->add($page);
     }
     // return parents
     return $sort == 'ASC' ? $parents->reverse() : $parents;
 }
Ejemplo n.º 13
0
 /**
  * @param [type] $request [description]
  *
  * @return [type] [description]
  */
 public function authorizeGet($request)
 {
     // CSRF protection
     $_SESSION['csrfToken'] = Util\OAuth::generateCsrfToken();
     $params = new Set($request->get());
     $requiredParams = ['response_type', 'client_id', 'redirect_uri', 'scope'];
     //TODO: Use json-schema validator
     foreach ($requiredParams as $requiredParam) {
         if (!$params->has($requiredParam)) {
             throw new \Exception('Parameter ' . $requiredParam . ' is missing!', Resource::STATUS_BAD_REQUEST);
         }
     }
     if ($params->get('response_type') !== 'code') {
         throw new \Exception('Invalid response_type specified.', Resource::STATUS_BAD_REQUEST);
     }
     $collection = $this->getDocumentManager()->getCollection('oAuthClients');
     $cursor = $collection->find();
     $cursor->where('clientId', $params->get('client_id'));
     $clientDocument = $cursor->current();
     if (null === $clientDocument) {
         throw new \Exception('Invalid client_id', Resource::STATUS_BAD_REQUEST);
     }
     if ($params->get('redirect_uri') !== $clientDocument->getRedirectUri()) {
         throw new \Exception('Redirect_uri mismatch!', Resource::STATUS_BAD_REQUEST);
     }
     $collection = $this->getDocumentManager()->getCollection('authScopes');
     $scopeDocuments = [];
     $scopes = explode(',', $params->get('scope'));
     foreach ($scopes as $scope) {
         $cursor = $collection->find();
         $cursor->where('name', $scope);
         $scopeDocument = $cursor->current();
         if (null === $scopeDocument) {
             throw new \Exception('Invalid scope given!', Resource::STATUS_BAD_REQUEST);
         }
         $scopeDocuments[] = $scopeDocument;
     }
     $this->client = $clientDocument;
     $this->scopes = $scopeDocuments;
 }
Ejemplo n.º 14
0
 /**
  * Delete an image by id
  * @param  int $imageId Image entity id
  * @return bool
  */
 public function deleteImage($imageId)
 {
     $image = $this->_imagesTable->get($imageId);
     return $this->deleteImageEntity($image);
 }
Ejemplo n.º 15
0
 /**
  * [getAccessToken description].
  *
  * @return [type]
  */
 public function getExpiresIn()
 {
     return $this->fileManager->get('expires_in');
 }
Ejemplo n.º 16
0
 /**
  * /
  * @param  [type] $token [description]
  * @return [type]        [description]
  */
 public function verify($token)
 {
     $nonce = $this->session->get('token.nonce');
     return (string) $token === (string) $nonce;
 }
 /**
  * @Template("RofilRepoContentBundle:Default:_random.html.twig")
  * [randomProjectAction description]
  * @param  integer $n [description]
  * @return [type]     [description]
  */
 public function randomProjectAction(Request $request, $n = 4)
 {
     return ['entities' => $this->projectRepo->get(['limit' => 5])];
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //var_dump(get_class_methods($this->hmvc));
     echo $this->hmvc->get('/');
 }
Ejemplo n.º 19
0
 /**
  * /
  * @param  [type] $app [description]
  * @return [type]      [description]
  */
 public function route($app)
 {
     /*
      * MUSTACHE TEMPLATES
      */
     $app->get('/template/:name', function ($name) use($app) {
         $file = '/public/assets/mustache/' . $name . '.mustache';
         if (!is_file($file) || !is_readable($file)) {
             throw new \Exception("File not accessible", 1);
         }
         $body = file_get_contents($file);
         if (!$body) {
             throw new \Exception("File not accessible", 1);
         }
         $app->response->headers->set('Content-Type', $type);
         $app->response->setBody($body);
         $app->stop();
     });
     /*
      * ASSETS
      */
     $app->get('/asset/:name/:extension', function ($name, $extension) use($app) {
         if (in_array($extension, array('css', 'js', 'gif', 'jpg', 'jpeg', 'png'))) {
             switch ($extension) {
                 case 'css':
                     $type = 'text/css';
                     break;
                 case 'js':
                     $type = 'application/javascript';
                     break;
                 default:
                     throw new \Exception("Unrecognized asset mimetype.", 01);
                     break;
             }
             $file = '/public/assets/' . $extension . '/' . $name . '.' . $extension;
             if (!is_file($file) || !is_readable($file)) {
                 throw new \Exception("File not accessible", 1);
             }
             $body = file_get_contents($file);
             if (!$body) {
                 throw new \Exception("Empty file", 1);
             }
             $app->response->headers->set('Content-Type', $type);
             $app->response->setBody($body);
         }
         $app->stop();
     });
     /*
      * IMAGE FILES
      * (TODO: implement Imagine PHP lib)
      */
     $app->get('/media/:name/:extension', function ($name, $extension) use($app) {
         if (in_array($extension, array('gif', 'jpg', 'jpeg', 'png'))) {
             switch ($extension) {
                 case 'jpg':
                     $type = 'image/jpeg';
                     break;
                 case 'jpeg':
                     $type = 'image/jpeg';
                     break;
                 case 'gif':
                     $type = 'image/gif';
                     break;
                 case 'png':
                     $type = 'image/png';
                     break;
                 default:
                     throw new \Exception("Unrecognized media mimetype.", 01);
                     break;
             }
             $app->response->headers->set('Content-Type', $type);
             $file = '/public/media/' . $name . '.' . $extension;
             if (!is_file($file) || !is_readable($file)) {
                 throw new \Exception("File not accessible", 1);
             }
             $body = file_get_contents($file);
             if (!$body) {
                 throw new \Exception("Empty file", 1);
             }
             $app->response->setBody($body);
         }
         $app->stop();
     });
     /*
      * FORCE DOWNLOAD
      * (TODO: log downloaded files)
      */
     $app->get('/download/:name/:extension', function ($name, $extension) use($app) {
         $file = '/public/media/' . $name . '.' . $extension;
         if (!is_file($file) || !is_readable($file)) {
             throw new \Exception("File not accessible", 1);
         }
         $body = file_get_contents('/public/media/' . $name . '.' . $extension);
         if (!$body) {
             throw new \Exception("Empty file", 1);
         }
         $mimes = $app->config('mimetypes.download');
         if (isset($mimes[$extension])) {
             $app->response->headers->set('Content-Type', $mimes[$extension]);
             $app->response->setBody($body);
         }
         $app->stop();
     });
     return $app;
 }
Ejemplo n.º 20
0
 /**
  * Is page Active based on current segment
  *
  * @param  [type]  $page [description]
  * @return boolean       [description]
  */
 public static function isPageActive($page)
 {
     $segments = self::getCurrentPathSegments();
     return $page->get('alias') == array_pop($segments);
 }
Ejemplo n.º 21
0
 /**
  * /
  * @param  [type] $app [description]
  * @return [type]      [description]
  */
 public function route($app)
 {
     $app->view->setLayout($layout);
     $app->get('/tag/:tag', function ($tag) use($app) {
     })->name('tag')->conditions(array('' => ''));
     $app->get('/', function () use($app) {
         $result = Content::query($app->db, 'findPublished');
         $app->view->setData($result);
         $app->view->render('');
     })->name('home');
     $app->get('/perfil', function () use($app) {
         $result = User::query($app->db, 'show', $app->sessionDataStore->getUserId());
         $app->view->setData($result);
         $app->view->render('');
     })->name('perfil');
     $app->get('/perfil/editar', function () use($app) {
         $app->view->setData($result);
         $app->view->render('');
     })->name('salvar_perfil');
     $app->post('/perfil/salvar', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $app->redirect($app->urlFor(''));
     })->name('salvar_perfil');
     $app->post('/comentar', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $app->redirect($app->urlFor(''));
     })->name('comentar');
     $app->get('/programacao(/:pagina)', function ($pagina = 1) use($app) {
         $result = Event::query($app->db, 'findPublished', $pagina);
         $app->view->setData($result);
         $app->view->render('');
     })->name('programacao')->conditions(array('' => ''));
     $app->get('/evento/:slug/:id', function ($slug, $id) use($app) {
         $result = Event::query($app->db, 'showPublished', $id);
         $app->view->setData($result);
         $app->view->render('');
     })->name('evento')->conditions(array('' => ''));
     $app->get('/espacos(/:pagina)', function ($pagina = 1) use($app) {
         $result = Content::query($app->db, 'findPublished', $pagina);
         $app->view->setData($result);
         $app->view->render('');
     })->name('espacos')->conditions(array('' => ''));
     $app->get('/espaco/:slug/:id', function ($slug, $id) use($app) {
         $result = Content::query($app->db, 'showPublished', $id);
         $app->view->setData($result);
         $app->view->render('');
     })->name('espaco')->conditions(array('' => ''));
     $app->get('/galerias(/:pagina)', function ($pagina = 1) use($app) {
         $result = Content::query($app->db, 'findPublished', $pagina);
         $app->view->setData($result);
         $app->view->render('');
     })->name('galerias')->conditions(array('' => ''));
     $app->get('/galeria/:slug/:id', function ($slug, $id) use($app) {
         $result = Content::query($app->db, 'showPublished', $id);
         $app->view->setData($result);
         $app->view->render('');
     })->name('galeria')->conditions(array('' => ''));
     $app->get('/revista(/:pagina)', function ($pagina = 1) use($app) {
         $result = Content::query($app->db, 'findPublished', $pagina);
         $app->view->setData($result);
         $app->view->render('');
     })->name('revista')->conditions(array('' => ''));
     $app->get('/materia/:slug/:id', function ($slug, $id) use($app) {
         $result = Content::query($app->db, 'showPublished', $id);
         $app->view->setData($result);
         $app->view->render('');
     })->name('materia')->conditions(array('' => ''));
     $app->get('/notas(/:pagina)', function ($pagina = 1) use($app) {
         $result = Content::query($app->db, 'findPublished', $pagina);
         $app->view->setData($result);
         $app->view->render('');
     })->name('notas')->conditions(array('' => ''));
     $app->get('/secao/:slug/:id', function ($id) use($app) {
         $result = Content::query($app->db, 'showPublished', $id);
         $app->view->setData($result);
         $app->view->render('');
     })->name('nota')->conditions(array('' => ''));
     $app->get('/equipe', function () use($app) {
         $result = Equipe::query($app->db, 'findPublished', $pagina);
         $app->view->setData($result);
         $app->view->render('');
     })->name('equipe');
     $app->get('/consultas(/:pagina)', function ($pagina = 1) use($app) {
         $result = ConsultaPublica::query($app->db, 'findPublished', $pagina);
         $app->view->setData($result);
         $app->view->render('');
     })->name('consultas')->conditions(array('' => ''));
     $app->get('/consulta/:id', function ($id) use($app) {
         $result = ConsultaPublica::query($app->db, 'showPublished', $id);
         $app->view->setData($result);
         $app->view->render('');
     })->name('consulta')->conditions(array('' => ''));
     $app->get('/editais(/:pagina)', function ($pagina = 1) use($app) {
         $result = Edital::query($app->db, 'findPublished', $pagina);
         $app->view->setData($result);
         $app->view->render('');
     })->name('editais')->conditions(array('' => ''));
     $app->get('/edital/:id', function ($id) use($app) {
         $result = Edital::query($app->db, 'showPublished', $id);
         $app->view->setData($result);
         $app->view->render('');
     })->name('edital')->conditions(array('' => ''));
     $app->get('/projetos(/:pagina)', function ($pagina = 1) use($app) {
         $result = Content::query($app->db, 'findPublished', $pagina);
         $app->view->setData($result);
         $app->view->render('');
     })->name('projetos')->conditions(array('' => ''));
     $app->get('/projeto/:id', function ($id) use($app) {
         $result = Content::query($app->db, 'showPublished', $id);
         $app->view->setData($result);
         $app->view->render('');
     })->name('projeto')->conditions(array('' => ''));
     $app->get('/leis(/:pagina)', function ($pagina = 1) use($app) {
         $result = LeiIncentivo::query($app->db, 'findPublished', $pagina);
         $app->view->setData($result);
         $app->view->render('');
     })->name('leis')->conditions(array('' => ''));
     $app->get('/lei/:id', function ($id) use($app) {
         $result = LeiIncentivo::query($app->db, 'showPublished', $id);
         $app->view->setData($result);
         $app->view->render('');
     })->name('lei')->conditions(array('id' => '\\d+'));
     return $app;
 }
Ejemplo n.º 22
0
/**
 * [deleteRepeatData deleteRepeatData 与数据库的数据进行比对,去除待写入数据中重复的数据]
 * @param  array  $data  [description]
 * @param  string $table [description]
 * @param  [type] $db    [description]
 * @return [type]        [description]
 */
function deleteRepeatData($data = array(), $table = '', $fieldname = '', $db = '')
{
    /* 去重复,并按序单条插入
    	foreach ($data as $key => $value) {
    	$this->db->where('rolename', $value['rolename']);
    	$q = $this->db->get($table);
    
    	if ($q->num_rows() > 0) {
    	$this->db->where('user_id', $id);
    	$this->db->update('profile', $data);
    	} else {
    	$this->db->set('user_id', $id);
    	$this->db->insert('profile', $data);
    	}
    	}
    	//print_R($db);
    	 */
    foreach ($data as $key => $value) {
        $db->where($fieldname, $value[$fieldname]);
        $q = $db->get($table);
        if ($q->num_rows() > 0) {
            unset($data[$key]);
        }
    }
    return array_values($data);
}
Ejemplo n.º 23
0
 /**
  * /
  * @param  [type] $app [description]
  * @return [type]      [description]
  */
 public function route($app)
 {
     $app->get('/api/project/:id/devs', function () use($app) {
         $result = Project::query($app->db, 'getDevs', $id);
         $app->handler->handleApiResponse($result);
     })->name('project_devs')->conditions(array('id' => '\\d+'));
     $app->get('/api/project/:id/users', function () use($app) {
         $result = Project::query($app->db, 'getUsers', $id);
         $app->handler->handleApiResponse($result);
     })->name('project_users')->conditions(array('id' => '\\d+'));
     $app->get('/api/project/:id/tickets', function () use($app) {
         $result = Project::query($app->db, 'getTickets', $id);
         $app->handler->handleApiResponse($result);
     })->name('project_tickets')->conditions(array('id' => '\\d+'));
     $app->get('/api/project/:id/invoices', function () use($app) {
         $result = Project::query($app->db, 'getInvoices', $id);
         $app->handler->handleApiResponse($result);
     })->name('project_invoices')->conditions(array('id' => '\\d+'));
     $app->get('/api/project/:id/hours', function () use($app) {
         $result = Project::query($app->db, 'getBillableHours', $id);
         $app->handler->handleApiResponse($result);
     })->name('project_hours')->conditions(array('id' => '\\d+'));
     $app->get('/api/invoice(/:pg(/:key(/:order)))', function ($pg = 1, $key = 'title', $order = 'asc') use($app) {
         $result = Invoice::query($app->db, 'find', $pg, $app->config('per_page'), $key, $order);
         $app->handler->handleApiResponse($result);
     })->name('invoice_list')->conditions(array('pg' => '\\d+', 'key' => '\\w+', 'order' => '\\w+'));
     $app->get('/api/invoice/:id/show', function ($id) use($app) {
         $result = Invoice::query($app->db, 'show', $id);
         $app->handler->handleApiResponse($result);
     })->name('invoice_show')->conditions(array('id' => '\\d+'));
     $app->map('/api/invoice/delete', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = Invoice::query($app->db, 'delete', $id);
         $app->handler->handleApiResponse($result);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'invoice', $id, 'delete', '', '', $app->nonce->get());
     })->via('POST', 'DELETE')->name('invoice_delete');
     $app->get('/api/project/:id/invoice/create', function ($id) use($app) {
         $result = Project::query($app->db, 'createInvoice', $id);
         $app->handler->handleApiResponse($result);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'project', $id, 'create_invoice', 'invoice', $result->getLastInsertId(), $app->nonce->get());
     })->name('project_create_invoice')->conditions(array('id' => '\\d+'));
     $app->get('/api/project(/:pg(/:key(/:order)))', function ($pg = 1, $key = 'title', $order = 'asc') use($app) {
         $result = Project::query($app->db, 'find', $pg, $app->config('per_page'), $key, $order);
         $app->handler->handleApiResponse($result);
     })->name('project_list')->conditions(array('pg' => '\\d+', 'key' => '\\w+', 'order' => '\\w+'));
     $app->get('/api/project/:id/show', function ($id) use($app) {
         $result = Project::query($app->db, 'show', $id);
         $app->handler->handleApiResponse($result);
     })->name('project_show')->conditions(array('id' => '\\d+'));
     $app->map('/api/project/save', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = Project::query($app->db, 'save', $record);
         $id = $record->has('id') ? $record->get('id') : $result->getLastInsertId();
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'project', $id, 'save', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'PUT')->name('project_save');
     $app->map('/api/project/delete', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = Project::query($app->db, 'delete', $id);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'project', $id, 'delete', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'DELETE')->name('project_delete');
     $app->get('/api/track/:ticket_id/start', function ($ticket_id) use($app) {
         $result = TimeTracking::query($app->db, 'start', $ticket_id);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'ticket', $id, 'time_started', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->name('track_start')->conditions(array('ticket_id' => '\\d+'));
     $app->get('/api/track/:ticket_id/stop', function ($ticket_id) use($app) {
         $result = TimeTracking::query($app->db, 'stop', $ticket_id);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'ticket', $id, 'time_stoped', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->name('track_stop')->conditions(array('ticket_id' => '\\d+'));
     $app->get('/api/ticket/latest', function () use($app) {
         $result = Ticket::query($app->db, 'find', 'modified');
         $app->handler->handleApiResponse($result);
     })->name('ticket_latest');
     $app->get('/api/ticket/list(/:pg', function ($pg = 1) use($app) {
         $result = Ticket::query($app->db, 'findAll', $pg, $per_page);
         $app->handler->handleApiResponse($result);
     })->name('ticket_list');
     $app->map('/api/ticket/save', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = Ticket::query($app->db, 'save', $record);
         $id = $record->has('id') ? $record->get('id') : $result->getLastInsertId();
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'ticket', $id, 'save', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'PUT')->name('ticket_save');
     $app->map('/api/ticket/priority', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = Ticket::query($app->db, 'changePriority', $id, $priority);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'ticket', $id, 'change_priority', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'PUT')->name('ticket_change_priority');
     $app->map('/api/ticket/delete', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = Ticket::query($app->db, 'delete', $id);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'ticket', $id, 'delete', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'DELETE')->name('ticket_delete');
     $app->get('/api/ticket/:id/dev', function ($id) use($app) {
         $app->handler->handleApiResponse($result);
     })->name('ticket_dev')->conditions(array('id' => '\\d+'));
     $app->map('/api/ticket/close', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $closed = Ticket::query($app->db, 'close', $record->get('id'));
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'ticket', $id, 'close', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'PUT')->name('ticket_close');
     $app->map('/api/ticket/comment', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $user_id = $app->sessionDataStore->getUserId();
         $result = Ticket::query($app->db, 'comment', $id, $user_id, $record->get('comment'));
         Log::query($app->db, 'log', $user_id, 'ticket', $id, 'close');
         $app->handler->handleApiResponse($result);
     })->via('POST', 'PUT')->name('ticket_comment');
     $app->map('/api/ticket/call', function () use($app) {
         $record = $app->handler->handlePostRequest();
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'ticket', $id, 'close', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'PUT')->name('ticket_request_call');
     return $app;
 }
Ejemplo n.º 24
0
 /**
  * [_handSuperGroupGitlab description]
  * @param  [type] $group [description]
  * @return [type]        [description]
  */
 private function _handSuperGroupGitlab($group)
 {
     // get needed config vars
     $gitlabManagement = $this->config->get('super_gitlab', 0);
     $gitlabUrl = $this->config->get('super_gitlab_url', '');
     $gitlabKey = $this->config->get('super_gitlab_key', '');
     // do we have repo management on
     // dont output message
     if (!$gitlabManagement) {
         return;
     }
     // make sure we have a url and key if repot management is on
     if ($gitlabManagement && ($gitlabUrl == '' || $gitlabKey == '')) {
         Notify::warning(Lang::txt('COM_GROUPS_GITLAB_NOT_SETUP'));
         return;
     }
     // make sure this is production hub
     $environment = strtolower(Config::get('application_env', 'development'));
     if ($environment != 'production') {
         return;
     }
     // build group & project names
     $host = explode('.', $_SERVER['HTTP_HOST']);
     $groupName = strtolower($host[0]);
     $projectName = $group->get('cn');
     // instantiate new gitlab client
     $client = new Gitlab($gitlabUrl, $gitlabKey);
     // get list of groups
     $groups = $client->groups();
     // attempt to get already existing group
     $gitLabGroup = null;
     foreach ($groups as $g) {
         if ($groupName == $g['name']) {
             $gitLabGroup = $g;
             break;
         }
     }
     // create group if doesnt exist
     if ($gitLabGroup == null) {
         $gitLabGroup = $client->createGroup(array('name' => $groupName, 'path' => strtolower($groupName)));
     }
     //get groups projects
     $projects = $client->projects();
     // attempt to get already existing project
     $gitLabProject = null;
     foreach ($projects as $p) {
         if ($projectName == $p['name'] && $p['namespace']['id'] == $gitLabGroup['id']) {
             $gitLabProject = $p;
             break;
         }
     }
     // create project if doesnt exist
     if ($gitLabProject == null) {
         $gitLabProject = $client->createProject(array('namespace_id' => $gitLabGroup['id'], 'name' => $projectName, 'description' => $group->get('description'), 'issues_enabled' => true, 'merge_requests_enabled' => true, 'wiki_enabled' => true, 'snippets_enabled' => true));
     }
     // path to group folder
     $uploadPath = PATH_APP . DS . trim($this->config->get('uploadpath', '/site/groups'), DS) . DS . $group->get('gidNumber');
     // build author info for making first commit
     $authorInfo = '"' . Config::get('sitename') . ' Groups <groups@' . $_SERVER['HTTP_HOST'] . '>"';
     // check to see if we already have git repo
     // only run gitlab setup once.
     if (is_dir($uploadPath . DS . '.git')) {
         return;
     }
     // build command to run via shell
     // this will init the git repo, make the inital commit and push to the repo management machine
     $cmd = 'sh ' . dirname(dirname(__DIR__)) . DS . 'assets' . DS . 'scripts' . DS . 'gitlab_setup.sh ';
     $cmd .= $uploadPath . ' ' . $authorInfo . ' ' . $gitLabProject['ssh_url_to_repo'] . ' 2>&1';
     // execute command
     $output = shell_exec($cmd);
     // make sure everything went well
     if (preg_match("/Host key verification failed/uis", $output)) {
         Notify::warning(Lang::txt('COM_GROUPS_GITLAB_NOT_SETUP_SSH'));
         return;
     }
     // protect master branch
     // allows only admins to accept Merge Requests
     $protected = $client->protectBranch(array('id' => $gitLabProject['id'], 'branch' => 'master'));
 }
Ejemplo n.º 25
0
 /**
  * /
  * @return [type] [description]
  */
 public function getUserId()
 {
     return $this->session->get('user.id');
 }
Ejemplo n.º 26
0
 /**
  * /
  * @param  [type] $app [description]
  * @return [type]      [description]
  */
 public function route($app)
 {
     /*
      * USERS
      */
     $app->get('/api/user(/:pg(/:key(/:order)))', function ($pg = 1, $key = 'modified', $order = 'desc') use($app) {
         $result = User::query($app->db, 'find', $pg, $app->config('per_page'), $key, $order);
         $app->handler->handleApiResponse($result);
     })->name('api_user_list')->conditions(array('pg' => '\\d+', 'key' => '\\w+', 'order' => 'asc|desc'));
     $app->get('/api/user/:id/show', function ($id) use($app) {
         $result = User::query($app->db, 'show', $id);
         $app->handler->handleApiResponse($result);
     })->name('api_user_show')->conditions(array());
     $app->get('/api/user/profile', function ($id) use($app) {
         $result = User::query($app->db, 'show', $app->sessionDataStore->getUserId());
         $app->handler->handleApiResponse($result);
     })->name('api_user_profile');
     $app->post('/api/user/delete', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $id = $record->get('id');
         $result = User::query($app->db, 'delete', $id);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'user', $id, 'delete', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'DELETE')->name('api_user_delete');
     $app->map('/api/user/save', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = User::query($app->db, 'save', $record);
         $id = $record->has('id') ? $record->get('id') : $result->getLastInsertId();
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), $model, $id, 'save', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'PUT')->name('api_user_save');
     /*
      * TYPES
      */
     $app->get('/api/type(/:pg(/:key(/:order)))', function ($pg = 1, $key = 'name', $order = 'asc') use($app) {
         $result = Type::query($app->db, 'display');
         $app->handler->handleApiResponse($result);
     })->name('api_type_list')->conditions(array('pg' => '\\d+', 'key' => '\\w+', 'order' => 'asc|desc'));
     $app->post('/api/type/delete', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $id = $record->get('id');
         $result = Type::query($app->db, 'delete', $id);
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'type', $id, 'delete', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->name('api_type_delete');
     $app->post('/api/type/save', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = Type::query($app->db, 'save', $record);
         $id = $record->has('id') ? $record->get('id') : $result->get('last.insert.id');
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), $model, $id, 'save', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->name('api_type_save');
     /*
      * SYSTEM
      */
     $app->get('/api/config', function () use($app) {
         $result = Config::query($app->db, 'display');
         $app->handler->handleApiResponse($result);
     })->name('api_config_list')->conditions(array());
     $app->map('/api/config', function () use($app) {
         $record = $app->handler->handlePostRequest();
         $result = Config::query($app->db, 'save', $record);
         $id = $record->has('id') ? $record->get('id') : $result->getLastInsertId();
         Log::query($app->db, 'log', $app->sessionDataStore->getUserId(), 'config', $id, 'save', '', '', $app->nonce->get());
         $app->handler->handleApiResponse($result);
     })->via('POST', 'PUT')->name('api_config_save');
     $app->get('/api/log(/:pg)', function ($pg = 1) use($app) {
         $result = Log::query($app->db, 'find', $pg, $app->config('per_page'));
         $app->handler->handleApiResponse($result);
     })->name('api_log_list')->conditions(array('pg' => '\\d+'));
     /*
      * LANG
      */
     $app->get('/api/lang/:lang', function ($lang) use($app) {
         $app->session->set('language', $lang);
     })->name('api_set_lang')->conditions(array('lang' => '\\w+'));
     /*
      * NONCE
      */
     $app->get('/api/nonce', function () use($app) {
         $app->nonce->generate();
         $result = new Result(array('success' => true, 'message' => 'Nonce has been generated.', 'nonce' => $app->nonce->get()));
         $app->handler->handleApiResponse($result);
     });
     return $app;
 }
Ejemplo n.º 27
0
 /**
  * Test get
  * @return [type] [description]
  */
 public function testGet()
 {
     $got = $this->loadedXls->get();
     $this->assertInstanceOf('Maatwebsite\\Excel\\Collections\\RowCollection', $got);
     $this->assertCount(2, $got);
 }
Ejemplo n.º 28
0
 /**
  * Make the client request and get the response
  * @param string $relativeUrl
  * @return  void
  */
 public function setResponse($relativeUrl)
 {
     $this->response = $this->client->get($this->baseUrl . $relativeUrl, []);
 }