protected function generate(Credentials $credentials, $scope) { $sql = 'SELECT id, name, password FROM fusio_user WHERE name = :name AND status = :status'; $user = $this->connection->fetchAssoc($sql, array('name' => $credentials->getClientId(), 'status' => User::STATUS_ADMINISTRATOR)); if (!empty($user)) { if (password_verify($credentials->getClientSecret(), $user['password'])) { $scopes = ['backend']; // generate access token $expires = new \DateTime(); $expires->add(new \DateInterval('PT1H')); $now = new \DateTime(); $accessToken = hash('sha256', uniqid()); $this->connection->insert('fusio_app_token', ['appId' => App::BACKEND, 'userId' => $user['id'], 'status' => AppToken::STATUS_ACTIVE, 'token' => $accessToken, 'scope' => implode(',', $scopes), 'ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1', 'expire' => $expires->format($this->connection->getDatabasePlatform()->getDateTimeFormatString()), 'date' => $now->format($this->connection->getDatabasePlatform()->getDateTimeFormatString())]); $token = new AccessToken(); $token->setAccessToken($accessToken); $token->setTokenType('bearer'); $token->setExpiresIn($expires->getTimestamp()); $token->setScope(implode(',', $scopes)); return $token; } else { throw new ServerErrorException('Invalid password'); } } else { throw new ServerErrorException('Unknown user'); } }
protected function insertGroup() { $count = $this->sql->count($this->registry['table.user_group']); if ($count == 0) { $this->logger->info('Create user groups'); $date = new DateTime('NOW'); // administrator group $this->sql->insert($this->registry['table.user_group'], array('title' => 'Administrator', 'date' => $date->format(DateTime::SQL))); $groupId = $this->sql->getLastInsertId(); $rights = $this->sql->getCol('SELECT id FROM ' . $this->registry['table.user_right']); foreach ($rights as $rightId) { $this->sql->insert($this->registry['table.user_group_right'], array('groupId' => $groupId, 'rightId' => $rightId)); } $this->logger->info('> Created administrator group'); $handler = new UserGroup\Handler($this->container); // normal group $group = $handler->getRecord(); $group->setTitle('Normal'); $group = $handler->create($group); $this->setRights($group->id, array('user_view', 'user_account_view', 'user_account_edit', 'user_activity_view', 'user_activity_add', 'user_friend_view', 'user_friend_add', 'user_friend_edit', 'user_friend_delete', 'user_friend_group_view', 'user_friend_group_add', 'user_friend_group_delete', 'media_view', 'swagger_view', 'sitemap_view', 'content_view', 'login_view', 'my_view', 'my_friends_view', 'my_activities_view', 'my_settings_view', 'profile_view', 'page_view', 'comment_view', 'comment_add', 'news_view', 'news_comment_add', 'file_view', 'php_view', 'redirect_view', 'pipe_view')); $this->logger->info('> Created normal group'); // set default user group $con = new Condition(array('name', '=', 'core.default_user_group')); $this->sql->update($this->registry['table.core_registry'], array('value' => $group->id), $con); // anonymous group $group = $handler->getRecord(); $group->setTitle('Anonymous'); $group = $handler->create($group); $this->setRights($group->id, array('user_view', 'media_view', 'swagger_view', 'sitemap_view', 'content_view', 'login_view', 'my_view', 'profile_view', 'page_view', 'comment_view', 'news_view', 'file_view', 'php_view', 'redirect_view', 'pipe_view')); $this->logger->info('> Created anonymous group'); } }
public function onLoad() { // set parameters $this->container->setParameter('session.name', 'amun-' . md5($this->config['psx_url'])); $this->container->setParameter('user.id', User::findUserId($this->getSession(), $this->getRegistry())); $this->container->setParameter('gadget.id', $this->location->getServiceId()); // dependencies $this->get = $this->getInputGet(); $this->post = $this->getInputPost(); $this->registry = $this->getRegistry(); $this->session = $this->getSession(); $this->user = $this->getUser(); $this->gadget = $this->getGadget(); $this->args = $this->gadget->getArgs(); // manager $this->hm = $this->getHandlerManager(); // load cache if ($this->gadget->hasCache() && Base::getRequestMethod() == 'GET') { $expire = $this->gadget->getExpire(); $expire = $expire instanceof DateInterval ? $expire : new DateInterval('P1D'); $modified = new DateTime(); $expires = clone $modified; $expires->add($expire); $type = $this->user->isAnonymous() ? 'public' : 'private'; $maxAge = DateTime::convertIntervalToSeconds($expire); header('Expires: ' . $expires->format(DateTime::RFC1123)); header('Last-Modified: ' . $modified->format(DateTime::RFC1123)); header('Cache-Control: ' . $type . ', max-age=' . $maxAge); header('Pragma:'); // remove pragma header } }
/** * Inserts an record for approval * * @param integer $type * @param PSX_Data_RecordInterface $record * @return void */ public function approveRecord($type, RecordInterface $record) { $type = Record::getType($type); if ($type !== false) { $date = new DateTime('NOW', $this->registry['core.default_timezone']); $this->sql->insert($this->registry['table.core_approval_record'], array('userId' => $this->user->id, 'type' => $type, 'table' => $this->table->getName(), 'record' => serialize($record->getFields()), 'date' => $date->format(DateTime::SQL))); } else { throw new Exception('Invalid approve record type'); } }
public function apply($value) { try { if (empty($value)) { throw new InvalidArgumentException('Empty value'); } $date = new DateTime($value, new DateTimeZone('UTC')); return $date->format('Y-m-d'); } catch (\Exception $e) { return $this->emptyAllowed ? null : false; } }
public function create(RecordInterface $record) { if ($record->hasFields('userId', 'name')) { $date = new DateTime('NOW', $this->registry['core.default_timezone']); $record->date = $date->format(DateTime::SQL); $this->table->insert($record->getData()); $record->id = $this->sql->getLastInsertId(); $this->notify(RecordAbstract::INSERT, $record); return $record; } else { throw new Exception('Missing field in record'); } }
public function create(RecordInterface $record) { if ($record->hasFields('projectId', 'authorId', 'url', 'message', 'commitDate')) { $record->globalId = $this->base->getUUID('vcshook:' . $record->projectId . ':' . uniqid()); $date = new DateTime('NOW', $this->registry['core.default_timezone']); $record->date = $date->format(DateTime::SQL); $this->table->insert($record->getData()); $record->id = $this->sql->getLastInsertId(); $this->notify(RecordAbstract::INSERT, $record); return $record; } else { throw new Exception('Missing field in record'); } }
public function create(RecordInterface $record) { if ($record->hasFields('status', 'name', 'email', 'url', 'title', 'description')) { $record->consumerKey = Security::generateToken(); $record->consumerSecret = Security::generateToken(); $date = new DateTime('NOW', $this->registry['core.default_timezone']); $record->date = $date->format(DateTime::SQL); $this->table->insert($record->getData()); $record->id = $this->sql->getLastInsertId(); $this->notify(RecordAbstract::INSERT, $record); return $record; } else { throw new Exception('Missing field in record'); } }
public function create(RecordInterface $record) { if ($record->hasFields('refId', 'type', 'table')) { $record->userId = $this->user->getId(); $date = new DateTime('NOW', $this->registry['core.default_timezone']); $record->date = $date->format(DateTime::SQL); $this->table->insert($record->getData(), Sql::DELAYED); $record->id = $this->sql->getLastInsertId(); // if a log record is created we create a log record // that the log record is created we dont want that ;) //$this->notify(amun_data_record::INSERT, $record); return $record; } else { throw new Exception('Missing field in record'); } }
/** * onLoad * * @param count integer */ public function onLoad() { parent::onLoad(); $count = $this->args->get('count', 8); $now = new DateTime('NOW', $this->registry['core.default_timezone']); $past = new DateTime('NOW', $this->registry['core.default_timezone']); $past->sub(new DateInterval('P' . $count . 'D')); $act = array(); // condition $con = new Condition(); $con->add('scope', '=', 0); $con->add('date', '>=', $past->format(DateTime::SQL)); // get activities $handler = $this->hm->getHandler('AmunService\\User\\Activity'); $result = $handler->getAll(array('id', 'scope', 'summary', 'date', 'authorId', 'authorName', 'authorThumbnailUrl'), 0, 64, 'date', Sql::SORT_ASC, $con); foreach ($result as $row) { $date = new DateTime($row['date'], $this->registry['core.default_timezone']); $interval = $date->diff($now); $key = $interval->format('%d'); if (!isset($act[$key])) { $act[$key] = 1; } else { $act[$key]++; } } // build params $chd = array(); $labels = array(); $max = 0; $days = 0; for ($i = $count - 1; $i >= 0; $i--) { if (isset($act[$i])) { if ($act[$i] > $max) { $max = $act[$i]; } $chd[$i] = $act[$i]; } else { $chd[$i] = 0; } $labels[] = date('d M', time() - $i * 3600 * 24); $days++; } $params = array('cht' => 'ls', 'chd' => 't:' . implode(',', $chd), 'chs' => '320x100', 'chco' => '0077CC', 'chds' => '0,' . $max, 'chxt' => 'x', 'chxl' => '0:|' . implode('|', $labels), 'chxr' => '0,1,' . $days . ',1'); $this->display($params); }
public function create(RecordInterface $record) { if ($record->hasFields('title')) { $con = new Condition(array('userId', '=', $this->user->getId())); if ($this->table->count($con) > $this->registry['my.max_group_count']) { throw new Exception('Max count of groups reached'); } $record->userId = $this->user->getId(); $date = new DateTime('NOW', $this->registry['core.default_timezone']); $record->date = $date->format(DateTime::SQL); $this->table->insert($record->getData()); $record->id = $this->sql->getLastInsertId(); $this->notify(RecordAbstract::INSERT, $record); return $record; } else { throw new Exception('Missing field in record'); } }
public function onLoad() { parent::onLoad(); if ($this->user->hasRight('file_view')) { $file = $this->getHandler()->getOneByPageId($this->page->getId()); if (!empty($file)) { $date = new DateTime($file['date'], $this->registry['core.default_timezone']); header('Content-Type: ' . $file['contentType']); header('Last-Modified: ' . $date->format(DateTime::RFC2822)); echo $file['content']; exit; } else { throw new Exception('No file set'); } } else { throw new Exception('Access not allowed'); } }
public function create(RecordInterface $record) { if ($record->hasFields('pageId', 'content')) { $record->globalId = $this->base->getUUID('service:page:' . $record->pageId . ':' . uniqid()); $record->userId = $this->user->getId(); $date = new DateTime('NOW', $this->registry['core.default_timezone']); $record->date = $date->format(DateTime::SQL); if (!$this->hasApproval($record)) { $this->table->insert($record->getData()); $record->id = $this->sql->getLastInsertId(); $this->notify(RecordAbstract::INSERT, $record); } else { $this->approveRecord(Approval\Record::INSERT, $record); } return $record; } else { throw new Exception('Missing field in record'); } }
public function onPost() { try { $email = $this->post->email('string', array(new Filter\Length(3, 64), new Filter\Email())); $captcha = $this->post->captcha('string'); // check captcha if anonymous $captchaProvider = Captcha::factory($this->config['amun_captcha']); if (!$captchaProvider->verify($captcha)) { throw new Exception('Invalid captcha'); } if (!$this->validate->hasError()) { $handler = $this->getHandler('AmunService\\User\\Account'); $account = $handler->getOneByIdentity(sha1($this->config['amun_salt'] . $email), array('id', 'name', 'status', 'email'), Sql::FETCH_OBJECT); if ($account instanceof Account\Record) { if (!in_array($account->status, array(Account\Record::NORMAL, Account\Record::ADMINISTRATOR))) { throw new Exception('Account has an invalid status'); } if (!empty($account->email)) { $token = Security::generateToken(); $link = $this->page->getUrl() . '/login/resetPw?token=' . $token; $date = new DateTime('NOW', $this->registry['core.default_timezone']); // update status $account->setStatus(Account\Record::RECOVER); $account->setToken($token); $handler->update($account); // send mail $values = array('account.name' => $account->name, 'host.name' => $this->base->getHost(), 'recover.ip' => $_SERVER['REMOTE_ADDR'], 'recover.link' => $this->page->getUrl() . '/resetPw?token=' . $token, 'recover.date' => $date->format($this->registry['core.format_date'])); $mail = new Mail($this->registry); $mail->send('LOGIN_RECOVER', $account->email, $values); $this->template->assign('success', true); } else { throw new Exception('No public email address is set for this account'); } } else { throw new Exception('Account does not exist'); } } else { throw new Exception($this->validate->getLastError()); } } catch (\Exception $e) { $this->template->assign('error', $e->getMessage()); } }
public function create(RecordInterface $record) { if ($record->hasFields('serviceId', 'name', 'title', 'class')) { $record->globalId = $this->base->getUUID('content:gadget:' . $record->name . ':' . uniqid()); if (!isset($record->cache)) { $record->cache = 0; $record->expire = ''; } if (!isset($record->expire)) { $record->expire = ''; } $date = new DateTime('NOW', $this->registry['core.default_timezone']); $record->date = $date->format(DateTime::SQL); $this->table->insert($record->getData()); $record->id = $this->sql->getLastInsertId(); $this->notify(RecordAbstract::INSERT, $record); return $record; } else { throw new Exception('Missing field in record'); } }
public function create(RecordInterface $record) { if ($record->hasFields('url', 'type')) { $record->globalId = $this->base->getUUID('vcshook:' . uniqid()); $record->userId = $this->user->getId(); $record->secret = Security::generateToken(40); // check whether project exists $type = TypeAbstract::factory($record->type); if (!$type->hasProject($record->url)) { throw new Exception('Project doesnt exist'); } $date = new DateTime('NOW', $this->registry['core.default_timezone']); $record->date = $date->format(DateTime::SQL); $this->table->insert($record->getData()); $record->id = $this->sql->getLastInsertId(); $this->notify(RecordAbstract::INSERT, $record); return $record; } else { throw new Exception('Missing field in record'); } }
public function onGet() { try { $token = $this->get->token('string', array(new Filter\Length(40, 40), new Filter\Xdigit())); if ($token !== false) { $handler = $this->getHandler('AmunService\\User\\Account'); $account = $handler->getRecoverByToken($token); if ($account instanceof Account\Record) { if (!empty($account->email)) { if ($_SERVER['REMOTE_ADDR'] == $account->ip) { $security = new Security($this->registry); $pw = $security->generatePw(); $date = new DateTime('NOW', $this->registry['core.default_timezone']); $account->setStatus(Account\Record::NORMAL); $account->setPw($pw); $handler->update($account); // send mail $values = array('account.name' => $account->name, 'account.pw' => $pw, 'host.name' => $this->base->getHost(), 'recover.link' => $this->page->getUrl(), 'recover.date' => $date->format($this->registry['core.format_date'])); $mail = new Mail($this->registry); $mail->send('LOGIN_RECOVER_SUCCESS', $account->email, $values); $this->template->assign('success', true); } else { throw new Exception('Recover process was requested from another IP'); } } else { throw new Exception('No public email address is set for this account'); } } else { throw new Exception('Invalid token'); } } else { throw new Exception('Token not set'); } } catch (\Exception $e) { $this->template->assign('error', $e->getMessage()); } }
public function create(RecordInterface $record) { if ($record->hasFields('parentId', 'serviceId', 'status', 'urlTitle', 'title')) { if (!isset($record->load)) { $record->load = Record::NAV | Record::PATH; } // build path for node $record->path = $this->buildPath($record); // set global id $record->globalId = $this->base->getUUID('content:page:' . $record->path . ':' . uniqid()); $date = new DateTime('NOW', $this->registry['core.default_timezone']); $record->date = $date->format(DateTime::SQL); $this->table->insert($record->getData()); $pageId = $this->sql->getLastInsertId(); if ($pageId == 0) { throw new Exception('Couldnt insert page'); } $record->id = $pageId; // set gadgets $gadgets = isset($record->gadgets) ? $record->gadgets : null; if (!empty($gadgets)) { $handler = $this->hm->getHandler('AmunService\\Content\\Page\\Gadget', $this->user); foreach ($gadgets as $k => $gadgetId) { $gadgetRecord = $handler->getRecord(); $gadgetRecord->pageId = $record->id; $gadgetRecord->gadgetId = $gadgetId; $gadgetRecord->sort = $k; $handler->create($gadgetRecord); } } $this->notify(RecordAbstract::INSERT, $record); return $record; } else { throw new Exception('Missing field in record'); } }
public function create(RecordInterface $record) { if ($record->hasFields('title')) { $date = new DateTime('NOW', $this->registry['core.default_timezone']); $record->date = $date->format(DateTime::SQL); $this->table->insert($record->getData()); $record->id = $this->sql->getLastInsertId(); // insert rights if available $rights = isset($record->rights) ? $record->rights : null; if (!empty($rights)) { $handler = $this->hm->getHandler('AmunService\\User\\Group\\Right', $this->user); foreach ($rights as $rightId) { $rightRecord = $handler->getRecord(); $rightRecord->groupId = $record->id; $rightRecord->rightId = $rightId; $handler->create($rightRecord); } } $this->notify(RecordAbstract::INSERT, $record); return $record; } else { throw new Exception('Missing field in record'); } }
public function save($opEndpoint, Association $assoc) { $now = new DateTime(); $this->sql->insert($this->table, array('opEndpoint' => $opEndpoint, 'assocHandle' => $assoc->getAssocHandle(), 'assocType' => $assoc->getAssocType(), 'sessionType' => $assoc->getSessionType(), 'secret' => $assoc->getSecret(), 'expires' => $assoc->getExpire(), 'date' => $now->format(DateTime::SQL))); }
public function create(RecordInterface $record) { if ($record->hasFields('summary')) { if (!isset($record->globalId)) { $record->globalId = $this->base->getUUID('user:activity:' . $record->summary . ':' . uniqid()); } $record->userId = $this->user->getId(); $record->verb = isset($record->verb) ? $record->verb : 'post'; if (!isset($record->date)) { $date = new DateTime('NOW', $this->registry['core.default_timezone']); $record->date = $date->format(DateTime::SQL); } $this->table->insert($record->getData()); $record->id = $this->sql->getLastInsertId(); $this->notify(RecordAbstract::INSERT, $record); $this->sendToReceiver($record); return $record; } else { throw new Exception('Missing field in record'); } }
private function getNews() { $con = $this->getRequestCondition(); $con->add('pageId', '=', $this->page->getId()); // archive $year = (int) $this->getUriFragments('year'); $month = (int) $this->getUriFragments('month'); // i think this software will not be used after the year 3000 if so // please travel back in time and slap me in the face ... nothing // happens ;D if ($year > 2010 && $year < 3000 && ($month > 0 && $month < 13)) { $date = new DateTime($year . '-' . ($month < 10 ? '0' : '') . $month . '-01', $this->registry['core.default_timezone']); $con->add('date', '>=', $date->format(DateTime::SQL)); $con->add('date', '<', $date->add(new DateInterval('P1M'))->format(DateTime::SQL)); } $url = new Url($this->base->getSelf()); $count = $url->getParam('count') > 0 ? $url->getParam('count') : 8; $count = $count > 16 ? 16 : $count; $result = $this->getHandler()->getResultSet(array(), $url->getParam('startIndex'), $count, $url->getParam('sortBy'), $url->getParam('sortOrder'), $con, SQL::FETCH_OBJECT); $paging = new Paging($url, $result); $this->template->assign('pagingNews', $paging, 0); return $result; }
/** * This method tries to figure out whether a user tries to abuse the system. * Every user can insert, update or delete "core.input_limit" records * in the last "core.input_interval" minutes without entering an captcha * After this the user has to solve an captcha * * @return boolean */ public function hasInputExceeded() { if ($this->isAdministrator()) { return false; } $now = new DateTime('NOW', $this->registry['core.default_timezone']); $now->sub(new DateInterval($this->registry['core.input_interval'])); $con = new Condition(); $con->add('userId', '=', $this->id); $con->add('date', '>=', $now->format(DateTime::SQL)); $count = $this->sql->count($this->registry['table.log'], $con); if ($count > $this->registry['core.input_limit']) { $expire = time() - $now->getTimestamp(); $percentage = ceil($count * 100 / ($this->registry['core.input_limit'] * 2)); $expire = $expire - $expire * ($percentage / 100); $lastVerified = isset($_SESSION['captcha_verified']) ? $_SESSION['captcha_verified'] : 0; $diff = time() - $lastVerified; if ($diff > $expire) { return true; } } return false; }
private function denyAccess($token, $callback) { // insert access $now = new DateTime('NOW', $this->registry['core.default_timezone']); $this->getSql()->replace($this->registry['table.oauth_access'], array('apiId' => $this->apiId, 'userId' => $this->user->getId(), 'allowed' => 0, 'date' => $now->format(DateTime::SQL))); // delete token $con = new Condition(array('token', '=', $token)); $this->getSql()->delete($this->registry['table.oauth_request'], $con); // redirect if callback available if ($callback != 'oob') { $url = new Url($callback); // here we can inform the consumer that the request has been denied $url->addParam('oauth_token', $token); $url->addParam('x_oauth_error', 'request+denied'); header('Location: ' . strval($url)); exit; } else { header('Location: ' . $this->config['psx_url']); exit; } }
public function onPost() { try { $name = $this->post->name('string', array(new Filter\Length(3, 32)), 'name', 'Name'); $identity = $this->post->identity('string', array(new Filter\Length(3, 128), new Filter\Email()), 'email', 'Email'); $pw = $this->post->pw('string'); $pwRepeat = $this->post->pwRepeat('string'); $longitude = $this->post->longitude('float'); $latitude = $this->post->latitude('float'); $captcha = $this->post->captcha('string'); if (!$this->validate->hasError()) { // check whether registration is enabled if (!$this->registry['login.registration_enabled']) { throw new Exception('Registration is disabled'); } // compare pws if (strcmp($pw, $pwRepeat) != 0) { throw new Exception('Password ist not the same'); } // check captcha if anonymous $captchaProvider = Captcha::factory($this->config['amun_captcha']); if (!$captchaProvider->verify($captcha)) { throw new Exception('Invalid captcha'); } // create account record $handler = $this->getHandler('AmunService\\User\\Account'); $account = $handler->getRecord(); $account->setGroupId($this->registry['core.default_user_group']); $account->setStatus(Account\Record::NOT_ACTIVATED); $account->setIdentity($identity); $account->setName($name); $account->setPw($pw); $account->setLongitude($longitude); $account->setLatitude($latitude); $account = $handler->create($account); if (isset($account->id)) { // send activation mail $date = new DateTime('NOW', $this->registry['core.default_timezone']); $values = array('account.name' => $account->name, 'account.identity' => $identity, 'host.name' => $this->base->getHost(), 'register.link' => $this->page->getUrl() . '/register/activate?token=' . $account->token, 'register.date' => $date->format($this->registry['core.format_date'])); $mail = new Mail($this->registry); $mail->send('LOGIN_REGISTRATION', $identity, $values); $this->template->assign('success', true); } else { throw new Exception('Your account was added for approval'); } } else { throw new Exception($this->validate->getLastError()); } } catch (\Exception $e) { $this->template->assign('name', htmlspecialchars($name)); $this->template->assign('identity', htmlspecialchars($identity)); $this->template->assign('error', $e->getMessage()); } }
protected function getResponse(Provider\Consumer $consumer, Provider\Request $request) { if ($this->nonce == $request->getNonce()) { throw new Exception('Nonce hasnt changed'); } if ($this->verifier != $request->getVerifier()) { throw new Exception('Invalid verifier'); } // the access token can be used six month $expire = 'P6M'; // generate a new access token $token = Security::generateToken(); $tokenSecret = Security::generateToken(); $date = new DateTime('NOW', $this->registry['core.default_timezone']); $con = new Condition(array('id', '=', $this->requestId)); $this->sql->update($this->registry['table.oauth_request'], array('status' => Oauth\Record::ACCESS, 'token' => $token, 'tokenSecret' => $tokenSecret, 'expire' => $expire, 'date' => $date->format(DateTime::SQL)), $con); $response = new Provider\Response(); $response->setToken($token); $response->setTokenSecret($tokenSecret); return $response; }
public function increase() { $date = new DateTime('NOW', $this->registry['core.default_timezone']); $this->sql->replace($this->registry['table.login_attempt'], array('ip' => $_SERVER['REMOTE_ADDR'], 'count' => $this->getCount() + 1, 'date' => $date->format(DateTime::SQL))); }
public function setTimestamp($timestamp) { $timestamp = $this->_validate->apply($timestamp, 'string', array(new Filter\Length(4, 32)), 'timestamp', 'Timestamp'); if (!$this->_validate->hasError()) { if (is_numeric($timestamp)) { $timestamp = '@' . $timestamp; } $date = new DateTime($timestamp, new DateTimeZone('UTC')); $date->setTimezone($this->_registry['core.default_timezone']); $this->commitDate = $date->format(DateTime::SQL); } else { throw new Exception($this->_validate->getLastError()); } }
private function handleOauthExt() { $consumerKey = isset($this->oauth['consumer']) ? $this->oauth['consumer'] : null; $row = $this->getHandler('AmunService\\Openid')->getOneByConsumerKey($consumerKey); if (!empty($row)) { $token = Security::generateToken(40); $verifier = Security::generateToken(32); $date = new DateTime('NOW', $this->registry['core.default_timezone']); $this->getSql()->insert($this->registry['table.oauth_request'], array('apiId' => $row['id'], 'userId' => $this->user->getId(), 'status' => Oauth\Record::APPROVED, 'ip' => $_SERVER['REMOTE_ADDR'], 'nonce' => Security::generateToken(16), 'callback' => 'oob', 'token' => $token, 'tokenSecret' => '', 'verifier' => $verifier, 'timestamp' => time(), 'expire' => 'PT30M', 'date' => $date->format(DateTime::SQL))); // insert access $this->getSql()->replace($this->registry['table.oauth_access'], array('apiId' => $row['id'], 'userId' => $this->user->getId(), 'allowed' => 1, 'date' => $date->format(DateTime::SQL))); // return params $params = array(); $params['openid.ns.oauth'] = Extension\Oauth::NS; $params['openid.oauth.request_token'] = $token; $params['openid.oauth.verifier'] = $verifier; return $params; } else { throw new Exception('Invalid consumer'); } }
public function create(RecordInterface $record) { if ($record->hasFields('name', 'mimeType', 'size', 'path')) { $record->globalId = $this->base->getUUID('content:media:' . $record->path . ':' . uniqid()); if ($record->path instanceof File) { // check mime type $type = $this->getType($record->path->getType()); if ($type === false) { throw new Exception('Invalide type'); } // check size $size = $record->path->getTmpSize(); if ($size < 1 || $size > $this->registry['media.upload_size']) { throw new Exception('Invalid upload size'); } // move file $folder = isset($record->folder) ? $record->folder : '.'; $name = $record->name; $path = $this->registry['media.path'] . '/' . $folder . '/' . $name; if (is_file($path)) { throw new Exception('File already exists'); } if ($record->path->move($path)) { $record->type = $type; $record->path = $folder == '.' ? $name : $folder . '/' . $name; } else { throw new Exception('Could not move file'); } } else { if (!is_file($record->path)) { throw new Exception('Invalid path'); } } $date = new DateTime('NOW', $this->registry['core.default_timezone']); $record->date = $date->format(DateTime::SQL); $this->table->insert($record->getData()); $record->id = $this->sql->getLastInsertId(); $this->notify(RecordAbstract::INSERT, $record); return $record; } else { throw new Exception('Missing field in record'); } }