/** * Create the controller action service * * @param ContainerInterface $container * @return \Ultradata\Home\Controller\HomePageAction */ public function __invoke(ContainerInterface $container) { // set up database connection $config = $this->getConfig($container); \RedBeanPHP\R::setup(sprintf("mysql:host=%s;dbname=%s", $config['host'], $config['dname']), $config['username'], $config['password']); $router = $container->get('Zend\\Expressive\\Router\\RouterInterface'); $template = $container->has('Zend\\Expressive\\Template\\TemplateRendererInterface') ? $container->get('Zend\\Expressive\\Template\\TemplateRendererInterface') : null; $controller = new Controller($router, $template); return $controller; }
public function delete($id) { $item = R::findOne('ecatalog', 'id=?', [$id]); R::trash($item); @unlink('upload/' . $item['pdf_path']); @unlink('upload/' . $item['cover_path']); $this->slim->redirect($this->slim->request()->getRootUri() . '/ecatalog'); }
public function __invoke(Request $req, Response $res, callable $next) { $res = $next($req, $res); $identity = $this->authService->getIdentity(); if (!$identity) { return $res; } try { $user = R::findOne('user', 'mail = ?', [$identity->mail]); if (!$user) { $user = R::dispense('user'); $user->uid = $identity->uid; $user->mail = $identity->mail; $user->display_name = $identity->displayName; $user->office_name = $identity->officeName; $user->authentication_source = $identity->authenticationSource; $user->password = ''; $user->created = time(); $user->role = 'school'; $this->logger->info(sprintf('User %s imported from sso.sch.gr to database', $identity->mail)); } $user->last_login = time(); $user_id = R::store($user); $identityClass = get_class($identity); $newIdentity = new $identityClass($user_id, $user->uid, $user->mail, $user->display_name, $user->office_name, $user->authentication_source); $this->authService->getStorage()->write($newIdentity); } catch (\Exception $e) { $this->authService->clearIdentity(); $this->flash->addMessage('danger', 'A problem occured storing user in database. <a href="%s" title="SSO logout">SSO Logout</a>'); $this->logger->error('Problem inserting user form CAS in database', $identity->toArray()); $this->logger->debug('Exception', [$e->getMessage(), $e->getTraceAsString()]); return $res->withRedirect($this->userErrorRedirectUrl); } return $res; }
protected static function select($a) { self::init(); if ($a === 'write') { if (self::$_writeConnected && self::$_last === 'write') { return; } foreach (self::$_mcs as $i => $c) { R::selectDatabase("write:{$i}"); if (R::testConnection()) { R::freeze(true); self::$_writeConnected = true; self::$_last = 'write'; return; } } throw new \Exception('Master DB have down'); } if ($a === 'read') { if (self::$_readConnected && self::$_last === 'read') { return; } foreach (self::$_scs as $i => $c) { R::selectDatabase("read:{$i}"); if (R::testConnection()) { R::freeze(true); self::$_readConnected = true; self::$_last = 'read'; return; } } throw new \Exception('Slave and master DB have down'); } }
public function save() { if (!$this->emptyAttr('id')) { $menu = R::findOne('menu', 'id=?', [$this->getAttr('id')]); } else { $menu = R::dispense('menu'); } $menu->name = $this->getAttr('name'); $oldPicture = null; if (!$this->emptyAttr('picture') && $this->attr['picture']->uploaded) { $picture = $this->getAttr('picture'); $picture->file_new_name_body = $this->generateName("menu_picture_"); // $picture->image_resize = true; $picture->image_convert = 'jpeg'; // $picture->image_x = 964; // $picture->image_y = 1024; // $picture->image_ratio_y = true; $picture->process('upload/'); $oldPicture = $menu->picture; $menu->picture = $picture->file_dst_name; } $success = R::store($menu); if ($success) { if (!is_null($oldPicture)) { @unlink('upload/' . $oldPicture); } } return $success; }
/** * @RequestMapping(url="oauth/getdata",method="POST",type="json") * @RequestParams(true) */ public function oauthGetData($model) { $this::setupDB(); \Parichya\OAuthServer::init(); if (\Parichya\OAuthServer::$PHASE_SERVICE_VERIFICATION) { \Parichya\Service::verifyService(function ($publicKey, $privateKey, $authToken) { //Verify $publicKey, $privateKey, $authToken and if all valid send requested data //R::debug( TRUE ); $authdata = R::findOne('authtoken', ' authtoken = ? AND publickey = ?', array($authToken, $publicKey)); if (is_null($authdata)) { return array("success" => false); } else { $privateKeyData = R::findOne('subscriber', ' subscriber_privatekey = ? AND subscriber_publickey = ?', array($privateKey, $publicKey)); if (is_null($privateKeyData)) { return array("success" => false); } else { $user = R::findOne('users', 'id = ? ', array($authdata->user_id)); if (is_null($user)) { return false; } else { return array("success" => true, "otp:authToken" => $authToken, "otp:mobileNumber" => $user->phone, "otp:name" => $user->name, "otp:email" => $user->email); } } } }); } return "login"; }
public function crawlUrl() { $currentUrl = ['url' => $this->currentUrl, 'depth' => $this->currentDepth]; do { $this->setCurrentUrl($currentUrl); if (!($doc = parent::crawlUrl())) { continue; } $username = $doc['.vcard-username']->text(); $user = R::findOne('github', ' username = ? ', [$username]); //$user = R::find('github', " username=$username "); if (empty($user)) { $user = R::dispense('github'); $now = time(); $user->avatar = $doc['.vcard-avatar .avatar']->attr('src'); $user->fullname = $doc['.vcard-fullname']->text(); $user->username = $username; $user->email = $doc['.email']->text(); $user->worksFor = $doc['.vcard-detail[itemprop=worksFor]']->text(); $user->homeLocation = $doc['.vcard-detail[itemprop=homeLocation]']->text(); $user->blogUrl = $doc['.vcard-detail[itemprop=url]']->text(); $user->joinDate = $doc['.join-date']->attr('datetime'); $user->url = $this->currentUrl; $user->createdAt = $now; $user->updatedAt = $now; if (R::store($user)) { echo '存储用户', $username, '成功', PHP_EOL; } else { echo '存储用户', $username, '失败', PHP_EOL; } } else { echo '用户', $username, '已经被存储过了', PHP_EOL; } } while ($currentUrl = $this->nextUrl()); }
public function delete($id) { $item = R::findOne('news', 'id=?', [$id]); R::trash($item); @unlink('upload/' . $item['picture']); @unlink('upload/' . $item['thumb']); $this->slim->redirect($this->slim->request()->getRootUri() . '/news'); }
public function findSchoolApplicationForm($schoolId) { $appForm = R::findOne('applicationform', ' school_id = ? ORDER BY id DESC', [$schoolId]); if (null === $appForm) { return; } return $this->exportApplicationForm($appForm); }
public function delete($roomId, $id) { $item = R::findOne('room_pattern', 'id=?', [$id]); @unlink('upload/' . $item->picture); @unlink('upload/' . $item->thumb); R::trash($item); $this->slim->redirect($this->slim->request()->getRootUri() . '/room/' . $roomId . '/pattern'); }
public function findSchoolByRegistryNo($registryNo) { $school = R::findOne('school', ' registry_no = ? ', [$registryNo]); if (null === $school) { return; } return $this->exportSchool($school); }
public function setupMySql($host, $name, $user, $password) { $this->dbHost = $host; $this->dbName = $name; $this->dbUser = $user; $this->dbPassword = $password; R::setup('mysql:host=' . $host . ';dbname=' . $name, $user, $password); return $this; }
public function test(Request $request, Response $response, array $args) { $uid = $args['uid']; $myaccount = R::load('accounts', $uid); $accountId = $myaccount->accountid; $account = R::findOne('accounts', ' accountid = ?', [$accountId]); if (!empty($account)) { $apiKey = $account['apikey']; $type = $account['servertype']; $oandaInfo = new Broker_Oanda($type, $apiKey, $accountId); } else { $this->flash->addMessage('flash', "Oanda AccountId not found"); return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('homepage')); } $side = 'buy'; $pair = 'EUR_USD'; $price = '1.1400'; $expiry = time() + 60; $stopLoss = '1.1300'; $takeProfit = NULL; $risk = 1; // $side='buy'; // $pair='GBP_CHF'; // $price='2.1443'; // $expiry = $oandaInfo->getExpiry(time()+60); // $stopLoss='2.1452'; // $takeProfit=NULL; // $risk=1; //$oandaInfo->placeLimitOrder($side,$pair,$price,$expiry,$stopLoss,$takeProfit,$risk); $oandaInfo->processTransactions(); }
function addBeans($beans) { if (null == $beans) { return array(); } $this->data = R::exportAll($beans); }
public function notifyAction() { $id = 1; $settings = R::load('settings', $id); $time_before = c::now()->modify('+' . $settings->time_before)->toDateString(); $transport = \Swift_SmtpTransport::newInstance($settings->mail_host, $settings->mail_port)->setUsername($settings->mail_username)->setPassword($settings->mail_password); $mailer = \Swift_Mailer::newInstance($transport); $client = new \Services_Twilio($settings->twilio_sid, $settings->twilio_token); $recepients = R::findAll('recepients'); $events = R::find("events", "is_enabled = 1 AND date = '{$time_before}'"); foreach ($events as $event) { foreach ($recepients as $recepient) { $subject = preg_replace(array('/{title}/', '/{date}/'), array($event->title, $event->date), $settings->subject); $end_date = c::parse($event->date)->modify('+' . $event->days . ' days')->toDateString(); $body_patterns = array('/{name}/', '/{title}/', '/{start_date}/', '/<!(\\w+) ({\\w+})>/'); $body_replacements = array($settings->name, $event->title, $event->date, "\$1 {$end_date}"); if ($event->days == 1) { $body_replacements[3] = ''; } $body = preg_replace($body_patterns, $body_replacements, $settings->msg_template); if ($recepient->email && $settings->mail_username && $settings->mail_password) { $message = \Swift_Message::newInstance()->setSubject($subject)->setBody($body)->setFrom(array($settings->email => $settings->name))->setTo(array($recepient->email => $recepient->name)); try { $response = $mailer->send($message); } catch (\Exception $e) { //todo: log error } } else { if ($recepient->phone_number && $settings->twilio_sid && $settings->twilio_token && $settings->twilio_phonenumber) { $message = $client->account->messages->sendMessage($settings->twilio_phonenumber, $recepient->phone_number, $body); } } } } }
public static function DBSetup() { $config = \Config::getSection("DB1"); if (!self::$CONNECTED) { R::setup('mysql:host=localhost;dbname=' . $config['dbname'], $config['username'], $config['password']); self::$CONNECTED = true; } }
public function getOptions() { $sets = []; foreach (R::findAll('skemaset') as $setBean) { $sets[$setBean->getID()] = $setBean->name; } return $sets; }
/** * This function validates the credentials * @return bool */ function validate($signin) { $user = R::findOne('users', 'email = :email AND pass = :pass', [':email' => $signin['email'], ':pass' => md5($signin['pass'])]); if (empty($user)) { return false; } $this->getSession()->set('user', $user); return true; }
function connect() { $config = \configuration\load(); if (empty($config['dsn']) || empty($config['user']) || empty($config['password'])) { die("Please check the configuration\\database.php file"); } R::addDatabase('db', $config['dsn'], $config['user'], $config['password'], $config['frozen']); R::selectDatabase('db'); }
public function get($id) { $item = R::findOne('room', 'id=?', [$id]); $itemExport = $item->getProperties(); $this->build($itemExport); header('Content-Type: application/json'); echo json_encode($itemExport, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; }
public function add_view() { $id = $this->slim->request->post()['id']; $item = R::load('ecatalog', $id); $item->view_count += 1; R::store($item); echo '555'; exit; }
public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null) { $identity = $this->authService->getIdentity(); $user = R::load('user', $identity->id); if (!($school = $user->school)) { return false; } $appForm = $this->appFormService->findSchoolApplicationForm($school->id); return null === $appForm; }
public function register(Container $app) { $app['db'] = function () use($app) { $options = array('dsn' => null, 'username' => null, 'password' => null, 'frozen' => false); if (isset($app['db.options'])) { $options = array_replace($options, $app['db.options']); } R::setup($options['dsn'], $options['username'], $options['password'], $options['frozen']); }; }
/** * @param Set $linkedSet * @returns $this */ public function link(Set $linkedSet) { $bean = $this->getBean(); if ($bean === null) { $bean = $this->newBean(); } $this->linkedSetId = $bean->{$this->_('linkedSetId')} = $linkedSet->getBean()->getID(); R::store($bean); return $this; }
function store() { $email = R::dispense('email'); foreach (\app\run('input', 'keys', 'post') as $key) { $element = str_replace('-', '_', $key); $email->{$element} = \app\run('input', 'post', $key); } R::store($email); return null; }
public function setOptions($options) { $bean = $this->getBean(); if ($bean === null) { $bean = $this->newBean(); } $bean->{$this->_('options')} = implode(',', $options); R::store($bean); return $this; }
private function getAuthorsCleaned() { $users = R::findAll('user', 'is_active = 1'); $data = []; foreach ($users as $key => $user) { $this->unsetProperties($user); $data[] = $user->export(); } return $data; }
public function injectsStatus(&$items) { $cacheInjects = []; foreach ($items as &$item) { if (!isset($cacheInjects[(string) $item->status])) { $cacheInjects[(string) $item->status] = R::findOne('employer_status', 'id=?', [$item->status]); } $item->status_name = $cacheInjects[(string) $item->status]->name; } }
function check($data) { $recipient = \app\run('input', 'post', 'recipient'); $user = R::findOne('user', ' email = ?', [$recipient]); if (empty($user)) { return false; } return $user; }
public function setCheckedValue($checkedValue) { if ($this->bean === null) { $this->newBean(); } $bean = $this->bean; $bean->{$this->_('checkedValue')} = $checkedValue; R::store($bean); return $this; }