コード例 #1
0
ファイル: IndexController.php プロジェクト: hanif/stokq
 /**
  * @param Request $request
  * @return array|\Zend\Http\Response
  * @throws \Exception
  */
 public function helpAction($request)
 {
     $this->layout('layout/single-column');
     $this->getNavService()->setActive('setting');
     $helpForm = $this->autoFilledForm(HelpForm::class);
     $helpForm->populateValues($this->user()->getArrayCopy());
     if ($request->isPost()) {
         if ($formValid = $helpForm->isValid()) {
             $config = $this->service('Config');
             if (is_array($config) && isset($config['slack']['webhook']['help-support'])) {
                 $formData = $helpForm->getData();
                 $data = ['fields' => [['name' => 'Name', 'value' => $formData['name'], 'short' => true], ['name' => 'Email', 'value' => $formData['email'], 'short' => true], ['name' => 'Contact No.', 'value' => $formData['contact_no'], 'short' => true], ['name' => 'Type', 'value' => $formData['type'], 'short' => true], ['name' => 'Severity', 'value' => $formData['severity'], 'short' => true], ['name' => 'Need Reply?', 'value' => $formData['need_reply'], 'short' => true], ['name' => 'Message', 'value' => $formData['message'], 'short' => false]]];
                 $json = sprintf('payload=%s', json_encode($data));
                 $ch = curl_init($config['slack']['webhook']['help-support']['url']);
                 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
                 curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                 curl_exec($ch);
                 curl_close($ch);
                 $this->flashMessenger()->addSuccessMessage('Terimakasih, pesan Anda telah terkirim.');
                 return $this->redirect()->toRoute(...$this->routeSpec('web.index.help'));
             }
             $this->flashMessenger()->addErrorMessage('Maaf, tidak dapat mengirim pesan Anda saat ini, mohon hubungi admin.');
             return $this->redirect()->toRoute(...$this->routeSpec('web.index.help'));
         }
     }
     return compact('helpForm', 'formValid');
 }
コード例 #2
0
 /**
  * @param string $name
  * @param mixed $default
  * @return mixed
  */
 public function request($name, $default = null)
 {
     //The RequestInterface expects this method to return values from a form submission or from
     //the decoded JSON body
     if ($this->data === null) {
         /* @var $contentType ContentType */
         $mediaType = $this->httpRequest->getHeaders('Content-type') ? $this->httpRequest->getHeaders('Content-type')->getFieldValue() : null;
         if ($mediaType == 'application/x-www-form-urlencoded' && ($this->httpRequest->isPut() || $this->httpRequest->isDelete())) {
             parse_str($this->httpRequest->getContent(), $this->data);
         } else {
             if ($mediaType == 'application/json' && ($this->httpRequest->isPost() || $this->httpRequest->isPut() || $this->httpRequest->isDelete())) {
                 $this->data = json_decode($this->httpRequest->getContent(), true);
             } else {
                 $this->data = $this->httpRequest->getPost()->toArray();
             }
         }
     }
     return isset($this->data[$name]) ? $this->data[$name] : $default;
 }
コード例 #3
0
 public function TreatRequest()
 {
     $request = new Request();
     if ($request->isGet()) {
         $this->DoGet();
     } else {
         if ($request->isPost()) {
             $this->DoPost();
         } else {
             return new \Exception();
         }
     }
 }
コード例 #4
0
ファイル: WordController.php プロジェクト: sebaks/Translate
 public function saveAction(Request $request, Create $createService, Form $form, View $view, Redirect $redirect)
 {
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $createService->create($form->getData());
             return $redirect->toRoute('admin-translate-words');
         }
     }
     $view->setForm($form);
     $view->setTemplate('translate/admin/word/edit');
     return $view;
 }
コード例 #5
0
 public function TreatRequest()
 {
     $req = new Request();
     if ($req->isGet()) {
         return $this->DoGet();
     }
     if ($req->isDelete() && $this->IsAuthorized()) {
         return $this->DoDelete();
     } else {
         if ($req->isPost()) {
             return $this->DoPost();
         } else {
             return new \Exception();
         }
     }
 }
コード例 #6
0
 public function Edit()
 {
     if (CommonController::IsAuthentified()) {
         $request = new Request();
         if ($request->isGet()) {
             $data = json_decode($this->GetCurrentCollection(), true);
             if (!is_null($data)) {
                 CommonController::SetView("collection", "edit", array_merge($data, array('url' => array('edit' => CommonController::GetLink("Collection", "edit", $data['collection']['id'])))));
                 return;
             }
         } else {
             if ($request->isPost()) {
                 $label = $request->getPost('label');
                 $description = $request->getPost('description');
                 $id = $request->getPost('id');
                 if (!is_null($label) && !is_null($description)) {
                     if (!is_null($id)) {
                         $WSCtrl = new WebServicesController();
                         $return = $WSCtrl->Call("Collection", "POST", array("id" => $id, "label" => $label, "description" => $description));
                         var_dump($return);
                         if ($return == "true") {
                             CommonController::Redirect("Collection", "Index", $id);
                         } else {
                             $data = json_decode($this->GetCurrentCollection(), true);
                             if (!is_null($data)) {
                                 CommonController::SetView("collection", "index", array_merge($data, array('url' => array('edit' => CommonController::GetLink("Collection", "edit", $data['collection']['id']), 'delete' => CommonController::GetLink("Collection", "delete", $data['collection']['id'])), 'error' => 'Impossible de sauver la collection')));
                                 return;
                             }
                         }
                     } else {
                         //Create
                     }
                 }
             }
         }
     }
     CommonController::Redirect("home");
 }
コード例 #7
0
 public function TreatRequest()
 {
     if ($this->IsAuthorized()) {
         $request = new Request();
         if ($request->isGet()) {
             return $this->DoGet();
         } else {
             if ($request->isPost()) {
                 return $this->DoPost();
             } else {
                 if ($request->isPut()) {
                     return $this->DoPut();
                 } else {
                     if ($request->isDelete()) {
                         return $this->DoDelete();
                     }
                 }
             }
         }
     } else {
         throw new \Exception();
     }
 }
コード例 #8
0
ファイル: SettingController.php プロジェクト: hanif/stokq
 /**
  * @param Request $request
  * @return array|\Zend\Stdlib\ResponseInterface
  */
 public function changePasswordAction($request)
 {
     $this->layout('layout/single-column');
     $this->getNavService()->setActive('setting');
     $changePasswordForm = $this->autoFilledForm(ChangePasswordForm::class);
     if ($request->isPost()) {
         if ($formValid = $changePasswordForm->isValid()) {
             /** @var PasswordInterface $passwordService */
             $passwordService = $this->service(PasswordInterface::class);
             $data = $changePasswordForm->getData();
             if ($passwordService->verify($data['old_password'], $this->user()->getPassword())) {
                 $user = $this->user();
                 $user->setPassword($passwordService->create($data['new_password']));
                 $this->persist($user)->commit();
                 $this->flashMessenger()->addSuccessMessage('Password yang baru telah di simpan.');
                 return $this->redirect()->toRoute(...$this->routeSpec('web.setting.change-password'));
             }
             $this->flashMessenger()->addErrorMessage('Password yang lama tidak cocok.');
             return $this->redirect()->toRoute(...$this->routeSpec('web.setting.change-password'));
         }
     }
     return compact('changePasswordForm', 'formValid');
 }
コード例 #9
0
 /**
  * Validates a token.
  *
  * Automatically validates a token when a request has an header with authorization.
  *
  * @since 4.3.0
  *
  * @return int|false user-id when token is valid, false when it is invalid.
  */
 function validate_token()
 {
     $request = new Request();
     if ($request->isGet() || $request->isPost()) {
         $authHeader = $request->getHeader('authorization');
         if ($authHeader) {
             list($jwt) = sscanf($authHeader->toString(), 'Authorization: Bearer %s');
             if ($jwt) {
                 try {
                     $secretKey = base64_decode(get_option('jwt_secret'));
                     $token = JWT::decode($jwt, $secretKey, array('HS256'));
                     return $token->data->userId;
                 } catch (Exception $e) {
                     // FALSE if token is invalid
                     return false;
                 }
             } else {
                 //  FALSE if no token was passed
                 return false;
             }
         }
     }
     return false;
 }
コード例 #10
0
ファイル: admin.php プロジェクト: jkatajamki/lummox
        }
    }
    $data = json_decode($app->request()->getBody());
    if (null !== $token) {
        $response = array("success" => true, "data" => $app->dataAccessService->getUser($data));
        $app->apiService->json(200, $response);
    } else {
        $response = array("success" => false, "data" => "Invalid token!");
        $app->apiService->json(401, $response);
    }
});
$app->post('/admin/users/verify', function () use($app) {
    // user role id for user (verified)
    $verified = 3;
    $request = new Request();
    if ($request->isPost()) {
        $header = $request->getHeader('authorization');
        if ($header) {
            $token = $app->apiService->extractToken($header);
        }
    }
    $data = json_decode($app->request()->getBody());
    if (null !== $token) {
        $app->dataAccessService->updateUserRole($data->user_name, $verified);
        $response = array("success" => true, "data" => "User verified successfully.");
        $app->apiService->json(200, $response);
    } else {
        $response = array("success" => false, "data" => "Invalid token!");
        $app->apiService->json(401, $response);
    }
});
コード例 #11
0
ファイル: AccessController.php プロジェクト: hanif/stokq
 /**
  * @param Request $request
  * @return mixed
  */
 public function firstRunAction($request)
 {
     $accountMapper = $this->mapper(Account::class);
     if ($accountMapper->count()) {
         return $this->notFoundAction();
     }
     /** @var FirstRunForm $firstRunForm */
     $firstRunForm = $this->autoFilledForm(FirstRunForm::class);
     if ($request->isPost()) {
         if ($formValid = $firstRunForm->isValid()) {
             $this->getAccountMService()->setupFirstRun($accountMapper, $this->mapper(User::class), $firstRunForm);
             $this->getStockService()->createDefaultUnit($this->mapper(StockUnit::class), $this->getStockService()->createDefaultUnitType($this->mapper(UnitType::class)));
             $this->getStockService()->createDefaultCategory($this->mapper(Category::class));
             $this->getStockService()->createDefaultStorageType($this->mapper(StorageType::class));
             $this->getMenuService()->createDefaultIngredientType($this->mapper(IngredientType::class));
             $this->getMenuService()->createDefaultMenuType($this->mapper(Type::class));
             $this->commit();
             $this->flashMessenger()->addSuccessMessage('Akun anda telah dibuat, silahkan login dengan user & password yang dipilih.');
             return $this->redirect()->toRoute(...$this->routeSpec('web.access.login'));
         }
     }
     $model = new ViewModel();
     $model->setTemplate('stokq/web/access/first-run');
     $model->setVariables(compact('firstRunForm', 'formValid'));
     $model->setTerminal(true);
     return $model;
 }
コード例 #12
0
// Wczytujemy wcześniej zdefiniowany plik ustawień
require 'phpsettings.php';
require 'vendor/autoload.php';
// Na wszelki wypadek przechwytujemy wszystkie potencjalne wyjątki
try {
    /* @var $container Zend\ServiceManager\ServiceManager */
    $container = (require 'config/container.php');
    $request = new Request();
    $paramPage = $request->getQuery('page');
    switch ($paramPage) {
        case 'login':
            /* @var $form \Aura\Input\Form */
            $form = $container->get(App\Form\LoginForm::class);
            if ($request->isGet()) {
                require 'views/login.php';
            } elseif ($request->isPost()) {
                $data = $request->getPost()->toArray();
                $form->fill($data);
                if ($form->filter()) {
                    $userGateway = $container->get(App\Db\UserTableGateway::class);
                    $result = $userGateway->fetchByEmail($request->getPost('email'));
                    if (password_verify($request->getPost('password'), $result['password'])) {
                        echo 'Użytkownik zalogowany prawidłowo.';
                    } else {
                        echo 'Nie udało się zalogować użytkownika.';
                    }
                } else {
                    require 'views/login.php';
                }
            }
            break;