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; }
public function moveTo($id, $position) { $item = R::findOne($this->table, 'id=?', [$this->id]); $desItem = R::findOne($this->table, 'id=?', [$id]); $itemOrder = $item->sort_order; $destOrder = $desItem->sort_order; $item->sort_order = $destOrder; $op = $itemOrder < $destOrder ? "-" : "+"; if ($itemOrder < $destOrder) { $op = "-"; $execParam = [$itemOrder, $destOrder]; } else { $op = "+"; $execParam = [$destOrder, $itemOrder]; } // if($op == "-" && $position == "before") $destOrder--; // if($op == "+" && $position == "after") $destOrder++; $query = "UPDATE {$this->table} SET sort_order = sort_order {$op} 1"; $query .= " WHERE (sort_order BETWEEN ? AND ?) AND id != ?"; $execParam[] = $this->id; if ($op == "-" && $position == "before" || $op == "+" && $position == "after") { $query .= " AND id != ?"; $execParam[] = $id; $destOrder2 = $op == "-" && $position == "before" ? $destOrder - 1 : $destOrder + 1; } else { $destOrder2 = $destOrder; } R::exec($query, $execParam); $item->sort_order = $destOrder2; R::store($item); $this->makeUnique(); return true; }
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; }
public function login($request, $response, $args) { $data = json_decode($request->getBody()); $user = R::findOne('user', 'username = ?', [$data->username]); if ($user === null) { $this->logger->addError('Login Attempt', [$data]); $this->apiJson->addAlert('error', 'Invalid username or password.'); return $this->jsonResponse($response, 401); } if (!password_verify($data->password, $user->password_hash)) { $this->logger->addError('Login Attempt ', [$data]); $this->apiJson->addAlert('error', 'Invalid username or password.'); return $this->jsonResponse($response, 401); } if (!$user->is_active) { $this->logger->addError('Login Attempt Inactive User ', [$data]); $this->apiJson->addAlert('error', 'This username is not active.'); return $this->jsonResponse($response, 403); } $jwt = self::createJwt($user->id, $data->remember ? 100 : 1); $user = R::load('user', $user->id); $user->active_token = $jwt; $user->last_login = time(); $user->logins += 1; R::store($user); $this->apiJson->setSuccess(); $this->apiJson->addData($this->sanitizeUser($user)); return $this->jsonResponse($response); }
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()); }
/** * @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 findSchoolByRegistryNo($registryNo) { $school = R::findOne('school', ' registry_no = ? ', [$registryNo]); if (null === $school) { return; } return $this->exportSchool($school); }
public static function byId($id) { $bean = R::findOne('page', ' id = ? ', [$id]); if ($bean !== null) { return new Page($bean->name, $bean); } return null; }
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 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 dispatch(Request $request, Response $response, array $args) { $this->logger->info("Profile page action dispatched"); //grab identity id. $id = $this->authenticator->getIdentity(); $user = R::findOne('users', ' name = :username ', ['username' => $id['name']]); $this->view->render($response, 'profile.twig', $user->export()); return $response; }
public function __construct($name, $bean = null) { $this->name = $name; if ($bean === null) { $bean = R::findOne('publisher', 'name = :name', ['name' => $name]); } $this->_bean = $bean; $this->convertFromBean(); }
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(); }
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; }
/** * 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; }
public function injectsUser(&$items) { $cacheUsers = []; foreach ($items as &$item) { if (!isset($cacheUsers[(string) $item->user_id])) { $cacheUsers[(string) $item->user_id] = R::findOne('user', 'id=?', [$item->user_id]); } $item->user = $cacheUsers[(string) $item->user_id]; } }
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; } }
public function getByName() { $roomName = @$_GET["room_name"]; $room = R::findOne('room', 'name=?', [$roomName]); $item = R::findOne('room_pattern', 'room_id=? AND 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 validate() { $attr = $this->attr; $user = R::findOne('account', 'token=?', [$this->getAttr('token')]); if (!$user) { $this->pushError('Not found account'); return false; } $this->user = $user; return true; }
public function validate() { if (!empty($this->attr['email'])) { $account = R::findOne('account', 'email=?', [$this->getAttr('email')]); if (!empty($account)) { $this->pushError('DUPLICATE_EMAIL'); return false; } } return true; }
public function __construct($id = null, $bean = null) { if ($bean === null && $id !== null) { $this->_bean = R::findOne('gallery', ' id = :id ', ['id' => $id]); } else { $this->_bean = $bean; } if ($this->_bean === null) { throw new \Exception('Need bean or id'); } $this->convertFromBean(); }
public static function checkIn($number) { $bean = R::findOne('record', ' number = :number AND isnull(`in`) ', ['number' => $number]); if ($bean === null) { return null; } $bean->in = time(); $bean->checkInBy = App::user()->id; $record = new Record($number, $bean); R::store($bean); return $record; }
public function getAuthor($request, $response, $args) { $author = R::findOne('user', 'id = ?', [$args['id']]); if (!$author) { $this->apiJson->addAlert('error', 'No author found for id ' . $args['id'] . '.'); return $this->jsonResponse($response); } $this->unsetProperties($author); $this->apiJson->setSuccess(); $this->apiJson->addData($author->export()); return $this->jsonResponse($response); }
/** * require Args array $args = array( 'time' => time(), 'userid' => '', 'oanda' => array( 'accountId' => '', ), ); */ public function setUp() { parent::setUp(); $accountId = $this->args['oanda']['accountId']; $account = R::findOne('accounts', ' accountid = ?', [$accountId]); if (!empty($account)) { $apiKey = $account['apikey']; $type = $account['servertype']; $this->oandaInfo = new Broker_Oanda($type, $apiKey, $accountId); } else { throw new \Exception('Oanda AccountId not found'); } }
public function getBean(Set $set = null) { if ($this->bean !== null) { return $this->bean; } if ($set !== null) { $bean = R::findOne('skemafield', ' name = ? and skemaset_id = ? ', [$this->name, $set->getBean()->getID()]); if ($bean !== null) { $this->prerequisite = $bean->prerequisite; } return $this->bean = $bean; } return null; }
public function __construct($module, $component, Group $group = null, $bean = null) { $this->module = $module; $this->component = $component; if ($bean === null) { $this->_bean = R::findOne('perm', ' groupName = ? AND module = ? AND component = ?', [$this->groupName, $module, $component]); } else { $this->_bean = $bean; } if ($group !== null) { $this->_group = $group; $this->groupName = $group->name; } }
/** * Update a user. * @param Array $data * ['name','fullname','password'] * @return string * @throws \Exception */ public function updateUser($data) { if (empty($data['name'])) { throw new \Exception('need a user name to update'); } $user = R::findOne('user', ' name = ? ', [$data['name']]); if (!empty($user)) { $user->name = $data['name']; $user->fullname = $data['fullname']; if (!empty($data['password'])) { $user->hash = password_hash($data['password'], PASSWORD_DEFAULT); } R::store($user); } }
function check($data) { $recipient = \app\run('input', 'post', 'recipient'); $user = R::findOne('user', ' email = ?', [$recipient]); if (empty($user)) { return false; } return $user; }