/** * Look up the supplied oauth_token from storage. * * We need to retrieve access token data as we create and verify tokens. * * @param string $oauth_token * The token string. * * @return IOAuth2AccessToken * * @ingroup oauth2_section_7 */ public function getAccessToken($oauth_token) { $access_token_bean = $this->redbean->findOne($this->tables['access_token'], ' token = ? ', array($oauth_token)); if (!$access_token_bean) { $access_token_bean = $this->redbean->dispense($this->tables['access_token']); } $access_token = new AccessToken($access_token_bean); return $access_token; }
public static function defaultLayer() { $layer = R::findOne('layer', 'identifier = ?', array('justmapit')); if (!$layer) { $layer = R::dispense('user'); $layer->identifier = 'justmapit'; $layer->creator = "admin"; $layer->title = "testing"; $layer->description = 'This is the base layer for Just Map It add any points of interest'; $layer->security = JMIAuthenticationType::ANONYMOUS; R::store($layer); } return $layer; }
function loginUser() { $success = false; RedBean_Facade::setup('mysql:host=' . Database::HOST . ';dbname=' . Database::NAME, Database::USERNAME, Database::PASSWORD); //echo hash('sha256', $_POST['password']); $user = RedBean_Facade::findOne('user', ' username = :username AND password = :password LIMIT 1', array(':username' => $_POST['username'], ':password' => hash('sha256', $_POST['password']))); if (isset($user)) { $currentUser = new User($user["username"], $user["firstname"], $user["name"], $user["is_admin"], $user["id"]); $_SESSION['username'] = $user["username"]; $_SESSION['user_id'] = $user["id"]; $_SESSION['name'] = $user["name"]; $_SESSION['firstname'] = $user["firstname"]; $_SESSION['is_admin'] = $user["is_admin"]; $success = true; } return $success; }
function API() { $app = \Slim\Slim::getInstance(); $app->view(new \JsonApiView()); $app->add(new \JsonApiMiddleware()); $app->response->headers->set('Content-Type', 'application/json'); $app->response->headers->set('Access-Control-Allow-Methods', 'GET,HEAD,POST,PUT,DELETE,OPTIONS'); $app->response->headers->set('Access-Control-Allow-Headers', 'Auth-Token,Content-Type'); $app->response->headers->set('Access-Control-Allow-Credentials', 'true'); $uri = array_values(array_filter(explode('/', $app->request->getResourceUri()))); $package = R::findOne('managepackages', ' name = ?', array($uri[0])); if ($package) { $origin = $package->origin; if (!$origin) { $origin = 'http://localhost'; } } else { $origin = 'http://localhost'; } $app->response->headers->set("Access-Control-Allow-Origin", $origin); }
public static function tagged($beanType, $tagList) { if ($tagList !== false && !is_array($tagList)) { $tags = explode(",", (string) $tagList); } else { $tags = $tagList; } $collection = array(); foreach ($tags as $tag) { $retrieved = array(); $tag = RedBean_Facade::findOne('tag', ' title = ? ', array($tag)); if ($tag) { $retrieved = RedBean_Facade::related($tag, $beanType); } foreach ($retrieved as $key => $bean) { $collection[$key] = $bean; } } return $collection; }
if (ENV != PRODUCTION) { $app->config('debug', true); } $app->get('/', function () use($app) { $app->render('index.php'); }); $app->post('/get', function () use($app) { $email = $app->request->post('email'); $ip = $app->request()->getIp(); if ($email == NULL || $email == '' || !check_email_address($email)) { echo json_encode(array('success' => FALSE, 'error' => 'INVALID')); } else { if (R::count('email', 'ip=:ip AND time>=:time', array(':ip' => $ip, ':time' => time() + 119 * 60)) >= 20) { echo json_encode(array('success' => FALSE, 'error' => 'LIMITATION')); } else { $bean = R::findOne('email', 'forwardto=:email AND time >= :time', array(':email' => $email, ':time' => time())); if ($bean) { $bean->time = time() + 120 * 60; R::store($bean); echo json_encode(array('success' => TRUE, 'email' => $bean->email . '@tempmail.ir')); } else { $rndmail = ''; do { $rndmail = generateRandomString(8); } while (R::count('email', 'email=:email AND time>=:time', array(':email' => $rndmail, ':time' => time())) > 0); $bean = R::dispense('email'); $bean->email = $rndmail; $bean->forwardto = $email; $bean->time = time() + 120 * 60; $bean->ip = $ip; R::store($bean);
static function getModelId($model) { $temp = R::findOne('models', 'name = ?', [$model]); if (isset($temp)) { return $temp->id; } }
/** * Validates data (or post) to create a new account * @param array $post * @return boolean */ public function validateCreate($post) { // Check security system if (!empty($post['reserved'])) { BootWiki::setMessage('Invalid submission. Are you a human?'); return false; } // Check if username is in use $account = R::findOne('account', 'username = ?', array($post['username'])); if (!empty($account)) { BootWiki::setMessage('Invalid username. Try another username'); return false; } if (!$this->validatePassword($post)) { return false; } return true; }
<?php use RedBean_Facade as R; if (empty($id)) { throw new \Exception('id is required', 412); } $q = R::findOne('question', '`id` = ?', array($id)); if (!$q) { throw new \Exception('Question not found', 404); } $q = $q->export(); $q['options'] = json_decode($q['options'], true); $app->result = $q;
<?php require_once 'models/Answer.php'; use RedBean_Facade as R; $payload = $app->request()->getBody(); $params = array('userid' => 'userid', 'questionid' => 'questionid', 'answer' => 'answer'); $payload = array_intersect_key($payload, $params); if (empty($payload['questionid'])) { throw new \Exception('questionid is required!', 412); } $quetion = R::findOne('question', '`id` = ?', array($payload['questionid'])); if (!$quetion) { throw new \Exception('Question not found', 404); } $answer = new Answer($payload, $quetion); $answer->validateAnswer(); R::exec('INSERT INTO `answer` (`userid`, `questionid`, `answer`) VALUES (:userid, :questionid, :answer)', array(':userid' => $answer->getValue('userid'), ':questionid' => $answer->getValue('questionid'), ':answer' => $answer->getValue('answer'))); $app->result = $answer->getValues();
static function existsShop($shop) { return R::findOne('shops', 'name = ?', [$shop]); }
<?php $r = Util::getInstance(); $app = \Slim\Slim::getInstance(); use RedBean_Facade as R; $r->registerHook('manage', 'packages', 'afterGet', function ($data) { if (!$_SESSION['authenticated']) { return false; } return $data; }); $r->registerHook('manage', 'packages', 'beforeInsert', function ($data) { if (!$_SESSION['authenticated']) { return false; } $existing = R::findOne('managepackages', 'name = ?', array($data['name'])); if ($existing) { return false; } if (isset($data['hook'])) { try { include_once 'lint.php'; \Lint\Lint::checkSourceCode($data['hook'], false); } catch (Exception $e) { $data['hook'] = '<?php' . "\n\n" . '/*' . "\nBroken PHP. Hook Hidden.\n\n" . str_replace('<?php', '', $data['hook']) . '*/'; } } if (isset($data['routes'])) { try { include_once 'lint.php'; \Lint\Lint::checkSourceCode($data['routes'], false);
/** * Starts a session for an account * @param string $username * @param string $password * @return boolean */ public static function login($username, $password) { $passwd = self::encrypt($password); $result = R::findOne('account', 'username = ? and password = ?', array($username, $passwd)); if (!empty($result)) { $account = new Account(); $account->importBean($result); $account->password = null; self::setLoggedAccount($account); return true; } self::setMessage('Invalid username or password'); return false; }
<?php use RedBean_Facade as R; if (empty($id)) { throw new \Exception('id is required', 412); } $q = R::findOne('user', '`id` = ?', array($id)); if (!$q) { throw new \Exception('User not found', 404); } $app->result = $q->export();
public function checkLimit($package) { $thisHour = floor(time() / 60 / 60); if (isset($_SESSION['requestHour']) && $_SESSION['requestHour'] == $thisHour) { $_SESSION['requestCount']++; } else { $_SESSION['requestHour'] = $thisHour; $_SESSION['requestCount'] = 1; } $package = R::findOne('managepackages', ' name = ?', array($this->cleanup($package))); $this->app->response()->header('Api-Utilization', $_SESSION['requestCount']); $this->app->response()->header('Api-Limit', $package->rate); if ($package->rate >= $_SESSION['requestCount']) { return true; } return false; }
/** * This will do the inverse operation * It receives a bean and returns the bean with the current data * * @param RedBean_OODBBean $bean * @return RedBean_OODBBean */ public function exportToBean($bean) { $bean = parent::exportToBean($bean); $bean->image = $this->image->src; $bean->idiom = R::findOne('idiom', 'code = ?', array($this->idiom->code)); return $bean; }