public function confirm(UserInterface $user, $code) { if ($user->getId() == $this->user_id && $user->getPhoneNumber() == $this->phone) { if ($code && $code != $this->code) { return false; } $this->getWriteConnection()->begin(); try { $user->setPhoneNumberConfirmed(true); Assert::noMessages($user); $this->save(['active' => null, 'result' => 1]); Assert::noMessages($this); $this->expireAnother(); $this->getWriteConnection()->commit(); } catch (Exception $e) { $this->getWriteConnection()->rollback(); throw $e; } return true; } else { $this->save(['active' => null, 'result' => 0]); Assert::noMessages($this); } return false; }
/** * @param $param1 AdapterInterface|Closure * @param $param2 Closure|null * * @throws Exception * @return mixed */ public static function transaction() { switch (func_num_args()) { case 1: $db = DI::getDefault()['db']; $callback = func_get_arg(0); break; case 2: $db = func_get_arg(0); $callback = func_get_arg(1); break; default: throw new Exception("Bad parameter count"); } /** @var $db AdapterInterface */ /** @var $callback Closure */ //Assert::true($db instanceof AdapterInterface); Assert::true($callback instanceof Closure); $db->begin(); try { $ret = $callback($db); $db->commit(); return $ret; } catch (Exception $e) { $db->rollback(); throw $e; } }
public function send() { /** @var \Rj\SmsGate\Herald $mailer */ $gate = $this->getDI()->getShared('SmsGate'); try { if ($num = Helper::sanitizePhone($this->phone)) { $result = $gate->send($num, $this->text, ['uid' => $this->sms_queue_id]); } else { trigger_error('Invalid phone number ' . $this->phone); $result = false; } if ($result) { $this->sent_at = date('Y-m-d H:i:s'); $this->err = null; $this->status = static::STATUS_OK; } else { if ($error = error_get_last()) { $this->err = $error['message']; $this->status = static::STATUS_ERR; } else { $this->status = static::STATUS_ERR; } } } catch (Exception $e) { $this->err = $e->getMessage(); $this->status = static::STATUS_ERR; } $this->save(); Assert::noMessages($this); }
public static function test() { if (file_exists(self::_getTableDataFileName())) { Assert::true(is_writeable(self::_getTableDataFileName())); } else { Assert::true(is_writeable(dirname(self::_getTableDataFileName()))); } }
public static function set($key, $value) { $entry = static::findFirst(['key = ?0', 'bind' => [$key]]); if (!$entry) { $entry = new static(); $entry->key = $key; } $entry->save(['value' => $value]); Assert::noMessages($entry); }
/** * Executes the validation * * @param \Phalcon\Validation $validation * @param string $field * @return boolean */ public function validate($validator, $attribute) { Assert::true($modelName = $this->getOption('model')); Assert::true($fieldName = $this->getOption('field') ?: $attribute); $model = $modelName::findFirst(["{$fieldName} = ?0", 'bind' => [$validator->getValue($attribute)]]); if ($model) { $message = $this->getOption('message') ?: "Field '{$attribute}' is not unique"; $validator->appendMessage(new Message($message, $attribute)); return false; } }
public function execute(Console $console) { $this->getWriteConnection()->execute("\n\t\t\tupdate {$this->getSource()} set executed_at = ? where cron_job_id = ?\n\t\t", [$this->executed_at = date("Y-m-d H:i:s"), $this->cron_job_id]); try { $console->handle(array('task' => $this->task_name, 'action' => $this->action_name)); $this->save(['last_message' => '', 'completed_at' => date('Y-m-d H:i:s'), 'locked_till' => time() + $this->delay]); Assert::saved($this); return static::RESULT_OK; } catch (Exception $e) { $this->getLogger()->exception($e); $this->save(['last_message' => get_class($e) . ': ' . $e->getMessage(), 'completed_at' => null, 'locked_till' => time() + $this->delay]); return static::RESULT_ERR; } }
public function indexAction() { $this->view->noRender(); Assert::found($query = $this->dispatcher->getParam('query')); Assert::found($pkg = $this->getPackage($query)); $dst = DOCROOT . '/../public/media/'; @Helper::mkdir($dst . dirname($query), 0777); Assert::found($f = fopen('zip://' . $pkg . '#' . $query, 'r')); Assert::true($d = fopen($dst . $query, 'w')); $content = ''; while (!feof($f)) { $content .= $data = fread($f, 8 * 1024); fwrite($d, $data); } fclose($f); $mime = null; if ($ext = strtolower(pathinfo($query, PATHINFO_EXTENSION))) { $mime = empty(FileInfo::$types[$ext]) ? null : FileInfo::$types[$ext]; } if ($mime) { $this->response->setHeader('Content-Type', $mime); } return $this->response->setContent($content); }
public static function post(RequestInterface $request, $message = "Only POST requests allowed") { Assert::true($request->isPost(), $message); }
public static function fileDownload($url, $fileName) { try { Assert::true($f = fopen($url, 'r')); Assert::true($fd = fopen($fileName, 'w+')); while (!feof($f)) { fwrite($fd, fread($f, 8 * 1024)); } fclose($f); fclose($fd); return true; } catch (Exception $e) { return false; } }
public function confirm() { if ($user = $this->_getUserModel()) { $this->getWriteConnection()->begin(); try { $this->save(['expires_at' => new Phalcon_RawValue('NULL'), 'confirm_success' => 'y']); Assert::noMessages($this); $this->expireOlder(); $this->_confirm(); $this->getWriteConnection()->commit(); } catch (Exception $e) { $this->getWriteConnection()->rollback(); throw $e; } } else { throw new Exception('Bad confirmation record: no such user'); } }
public function crud_edit(Closure $success = null) { Assert::found($this->_crud_model); $this->view->setVar('userData', $this->_crud_model->toArray()); return $this->crud_create($this->_crud_model, $success); }