public function update(User $user, Request $request, Database $db, $id)
 {
     $error = null;
     $filter = ['id = ? and id <> ?', $id, $user->get('id')];
     $record = $db->findOne('user', $filter);
     if (!$record) {
         $user->message('warning', 'Data tidak ditemukan');
         return $this->redirect($this->homeUrl);
     }
     $fields = ['name' => $request->get('name', $record['name']), 'username' => $request->get('username', $record['username']), 'password' => $request->get('password', $record['password']), 'level' => $request->get('level', $record['level'])];
     $labels = $this->app->load('app/config/translations/user-labels.php');
     if ($request->isPost()) {
         $rules = ['name,username,password' => 'required'];
         $error = $this->validation->setData($fields)->setRules($rules)->setLabels($labels)->validate()->getError();
         if (!$error) {
             $saved = $db->update('user', $fields, $filter);
             if ($saved) {
                 $user->message('success', 'Data sudah disimpan!');
                 return $this->redirect($this->homeUrl);
             } else {
                 $error = 'Data gagal disimpan!';
             }
         }
         $user->message('error', $error);
     }
     $form = $this->form->setData($fields)->setLabels($labels)->setAttrs(['class' => 'form-horizontal'])->setDefaultControlAttrs(['class' => 'form-control'])->setDefaultLabelAttrs(['class' => 'form-label col-md-2']);
     return $this->render('user/update', ['form' => $form, 'homeUrl' => $this->homeUrl]);
 }
Example #2
0
 public function addFilter($filterName, $filterClass, $filterElementName = '')
 {
     if (!isset($this->_filters[$filterName]) && class_exists($filterClass)) {
         $this->_filters[$filterName] = new $filterClass($this->_pixie);
         $elementName = empty($filterElementName) ? $this->_filters[$filterName]->getFieldName() : $filterElementName;
         $postData = $this->_request->post($elementName);
         $value = !empty($postData) ? $postData : $this->_request->get($elementName);
         $this->_filters[$filterName]->setValue($value);
     }
 }
 public function main(User $user, Request $request, Database $db)
 {
     if ($user->is('admin')) {
         return $this->redirect('admin');
     } elseif ($user->hasBeenLogin()) {
         return $this->redirect('index');
     }
     $username = $request->get('username');
     $password = $request->get('password');
     $error = null;
     if ($request->isPost()) {
         $filter = ['username = ? and password = ?', $username, $password];
         $data = $db->findOne('user', $filter);
         if (empty($data)) {
             $error = 'Login gagal! Username atau password tidak cocok!';
         } else {
             $user->login('admin', $data);
             return $this->redirect('admin');
         }
     }
     $form = $this->form->setData(['username' => $username])->setAttrs(['id' => 'login-form'])->setDefaultLabelAttrs(['class' => 'sr-only'])->setDefaultControlAttrs(['class' => 'form-control form-block']);
     return $this->render(null, ['form' => $form, 'error' => $error]);
 }
 public function account(User $user, Database $db, Request $request)
 {
     $fields = ['username' => $request->get('username', $user->get('username')), 'password' => $request->get('password', $user->get('password')), 'new_password' => $request->get('new_password', $user->get('new_password')), 'name' => $request->get('name', $user->get('name'))];
     $error = null;
     $selfUrl = $this->homeUrl . '/account';
     $labels = $this->app->load('app/config/translations/user-labels.php');
     if ($request->isPost()) {
         $old_password = $user->get('password');
         $rules = ['name,username' => 'required', 'password' => 'required,Password saat ini tidak boleh kosong', '-password' => "equal({$old_password}),Password saat ini tidak valid", 'new_password' => 'minLength(4,allowEmpty)'];
         $error = $this->validation->setData($fields)->setRules($rules)->setLabels($labels)->validate()->getError();
         if (!$error) {
             // handle file
             $filename = $request->baseDir() . 'asset/avatars/user-' . $user->get('id');
             if (Helper::handleFileUpload('avatar', $filename, $this->app->get('imageTypes'))) {
                 $fields['avatar'] = basename($filename);
             }
             if ($fields['new_password']) {
                 $fields['password'] = $fields['new_password'];
             }
             unset($fields['new_password']);
             $filter = ['id = ?', $user->get('id')];
             $saved = $db->update('user', $fields, $filter);
             if ($saved) {
                 $user->register($fields);
                 $user->message('success', 'Data sudah diupdate');
                 return $this->redirect($selfUrl);
             } else {
                 $error = 'Data gagal disimpan!';
             }
         }
         $user->message('error', $error);
     }
     $avatar = $user->get('avatar');
     $avatar = $this->app->asset($avatar ? 'asset/avatars/' . $avatar : 'asset/images/avatar.png');
     $form = $this->form->setData($fields)->setLabels($labels)->setAttrs(['class' => 'form-horizontal', 'enctype' => 'multipart/form-data'])->setDefaultControlAttrs(['class' => 'form-control'])->setDefaultLabelAttrs(['class' => 'form-label col-md-4']);
     return $this->render('profil', ['form' => $form, 'avatar' => $avatar, 'backUrl' => 'index']);
 }
Example #5
0
 /**
  * @param Request $request
  * @param \PHPixie\View $view
  * @param PaymentOperation $operation
  * @param Payment $payment
  * @param bool $isTesting
  * @return mixed|void
  */
 public function getRefundParameters(Request $request, \PHPixie\View $view, PaymentOperation $operation, Payment $payment, $isTesting = false)
 {
     if (!$operation || !$operation->loaded()) {
         $operation = $this->pixie->payments->createRefundOperation($payment);
         $payment->refund_operation_id = $operation->id();
         $payment->save();
     }
     if ($operation->status != PaymentOperation::STATUS_COMPLETED) {
         $operation->setStatus(PaymentOperation::STATUS_PENDING);
         $operation->save();
     }
     if ($payment->payment_operation && $payment->payment_operation->loaded()) {
         $operation->setRrn($payment->payment_operation->getRrn());
         $operation->setInternalReference($payment->payment_operation->getInternalReference());
     }
     $refundRequest = $this->createRequestFromPaymentOperation($operation);
     $refundRequest->setMerchantUrl($this->getMerchantUrl());
     if ($isTesting && $request->get('amount')) {
         $refundRequest->setAmount($request->get('amount'));
     }
     $macFields = null;
     if ($isTesting) {
         $macFieldsArr = $request->get('mac_fields');
         if (is_array($macFieldsArr)) {
             $macFields = $macFieldsArr;
         } else {
             if ($macFieldsArr == 'none') {
                 $macFields = [];
             }
         }
     }
     $refundRequest->setPSign($this->calculateRequestMAC($refundRequest, $macFields));
     $view->gatewayParameters = $refundRequest->getParametersArray();
     $paymentConfig = $this->pixie->config->get('payment');
     $view->gatewayUrl = $paymentConfig['gateway_url'];
 }
Example #6
0
 /**
  * @param Request $request
  * @return ProcessResult
  * @throws HttpException
  * @throws NotFoundException
  * @throws \Exception
  */
 public function processResponse(Request $request)
 {
     $user = $this->pixie->auth->user();
     if (!$user) {
         throw new ForbiddenException();
     }
     $orderUid = $request->get('order_id');
     if (!$orderUid) {
         throw new ForbiddenException();
     }
     /** @var Order $orderModel */
     $orderModel = $this->pixie->orm->get('order');
     $order = $orderModel->getByUid($orderUid);
     if (!$order) {
         throw new NotFoundException("Заказа с таким ID не существует.");
     }
     if ($order->customer->id() != $user->id()) {
         throw new NotFoundException("Заказа с таким ID не существует.");
     }
     if (!$order->isPayable()) {
         throw new ForbiddenException("Заказ №" . $orderUid . " не может быть оплачен.");
     }
     $operation = $order->payment->payment_operation;
     //var_dump($operation->as_array(), $order->payment->as_array()); exit;
     if (!$operation || !$operation->loaded()) {
         throw new HttpException("Отсутствует операция оплаты для платежа {$order->payment->id}");
     }
     $info = $this->checkOrderStatus($order);
     $this->validateOperationState($operation, $info);
     $processResult = new ProcessResult();
     $processResult->setOrder($order);
     $processResult->setOperation($operation);
     $processResult->setTransactionType($operation->getTransactionType());
     $processResult->setResult(true);
     return $processResult;
 }