Пример #1
0
 /**
  * @protected
  */
 public function _csrfToken()
 {
     $session = Registry::get("session");
     $csrf_token = Framework\StringMethods::uniqRandString(44);
     $session->set('Auth\\Request:$token', $csrf_token);
     if ($this->actionView) {
         $this->actionView->set('__token', $csrf_token);
     }
 }
Пример #2
0
 /**
  * @before _secure
  */
 public function raiseinvoice()
 {
     $this->seo(array("title" => "Create Invoice"));
     $view = $this->getActionView();
     $perfs = [];
     $start = RM::get("start");
     $end = RM::get("end");
     $user_id = RM::get("user_id", null);
     $view->set('user_id', $user_id)->set('start', $start)->set('end', $end);
     $dateQuery = Utils::dateQuery($start, $end);
     $query['created'] = ['$gte' => $dateQuery['start'], '$lte' => $dateQuery['end']];
     $query['user_id'] = $user_id;
     if ($user_id) {
         $user = \User::first(['type = ?' => 'advertiser', 'org_id = ?' => $this->org->_id, 'id = ?' => $user_id]);
         $view->set('advertiser', $user);
         $performances = Performance::all($query, ['clicks', 'impressions', 'conversions', 'created', 'revenue'], 'created', 'desc');
         foreach ($performances as $p) {
             $perfs[] = $p;
         }
         $view->set('performances', $perfs);
         $inv_exist = Invoice::exists($user_id, $start, $end);
         if ($inv_exist) {
             $view->set("message", "Invoice already exist for Date range from " . Framework\StringMethods::only_date($inv_exist->start) . " to " . Framework\StringMethods::only_date($inv_exist->end));
             return;
         }
     } else {
         $advertisers = \User::all(['type = ?' => 'advertiser', 'org_id' => $this->org->_id], ['id', 'name']);
         $view->set('advertisers', $advertisers);
     }
     if (RM::post("action") == "cinvoice" && RM::post("amount") > 0) {
         $invoice = new Invoice(["org_id" => $this->org->id, "user_id" => $user->id, "utype" => $user->type, "start" => end($perfs)->created, "end" => $perfs[0]->created, "amount" => RM::post("amount"), "live" => false]);
         $invoice->save();
         Registry::get("session")->set('$flashMessage', 'Payment Saved!!');
         $this->redirect("/billing/advertisers.html");
     }
 }