コード例 #1
0
ファイル: ClientCredentials.php プロジェクト: virusvn/fusio
    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');
        }
    }
コード例 #2
0
ファイル: GadgetAbstract.php プロジェクト: visapi/amun
 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
     }
 }
コード例 #3
0
ファイル: Setup.php プロジェクト: visapi/amun
 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');
     }
 }
コード例 #4
0
 /**
  * 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');
     }
 }
コード例 #5
0
ファイル: Date.php プロジェクト: visapi/amun
 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;
     }
 }
コード例 #6
0
ファイル: Handler.php プロジェクト: visapi/amun
 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');
     }
 }
コード例 #7
0
ファイル: Handler.php プロジェクト: visapi/amun
 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');
     }
 }
コード例 #8
0
ファイル: Handler.php プロジェクト: visapi/amun
 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');
     }
 }
コード例 #9
0
ファイル: Handler.php プロジェクト: visapi/amun
 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');
     }
 }
コード例 #10
0
ファイル: ActivityChart.php プロジェクト: visapi/amun
 /**
  * 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);
 }
コード例 #11
0
ファイル: Date.php プロジェクト: seytar/psx
 public function toString()
 {
     $date = $this->format('Y-m-d');
     $offset = $this->getOffset();
     if ($offset != 0) {
         $date .= DateTime::getOffsetBySeconds($offset);
     }
     return $date;
 }
コード例 #12
0
ファイル: Handler.php プロジェクト: visapi/amun
 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');
     }
 }
コード例 #13
0
ファイル: Index.php プロジェクト: visapi/amun
 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');
     }
 }
コード例 #14
0
ファイル: HtmlWriterVisitor.php プロジェクト: seytar/psx
 protected function getValue($value)
 {
     if ($value instanceof \DateTime) {
         return DateTime::getFormat($value);
     } elseif (is_bool($value)) {
         return $value ? 'true' : 'false';
     } else {
         return htmlspecialchars((string) $value);
     }
 }
コード例 #15
0
ファイル: Handler.php プロジェクト: visapi/amun
 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');
     }
 }
コード例 #16
0
ファイル: Recover.php プロジェクト: visapi/amun
 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());
     }
 }
コード例 #17
0
ファイル: Handler.php プロジェクト: visapi/amun
 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');
     }
 }
コード例 #18
0
ファイル: LatestActivity.php プロジェクト: visapi/amun
 private function display(array $result)
 {
     $now = new DateTime('NOW', $this->registry['core.default_timezone']);
     echo '<ul>';
     foreach ($result as $row) {
         $date = new DateTime($row['date'], $this->registry['core.default_timezone']);
         $interval = $now->diff($date);
         if ($interval->format('%d') == 0) {
             if ($interval->format('%h') == 0) {
                 $ago = 'ago ' . $interval->format('%i minutes');
             } else {
                 $ago = 'ago ' . $interval->format('%h hours');
             }
         } else {
             $ago = 'on ' . $date->format($this->registry['core.format_datetime']);
         }
         echo '<li>' . $row['summary'] . '<p class="muted">' . $ago . '</p></li>';
     }
     echo '</ul>';
     echo '<div class="clearfix"></div>';
 }
コード例 #19
0
ファイル: Handler.php プロジェクト: visapi/amun
 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');
     }
 }
コード例 #20
0
ファイル: Time.php プロジェクト: seytar/psx
 public function toString()
 {
     $time = $this->format('H:i:s');
     $ms = $this->getMicroSecond();
     $offset = $this->getOffset();
     if ($ms > 0) {
         $time .= '.' . $ms;
     }
     if ($offset != 0) {
         $time .= DateTime::getOffsetBySeconds($offset);
     }
     return $time;
 }
コード例 #21
0
ファイル: JsonxWriterVisitor.php プロジェクト: seytar/psx
 public function visitValue($value)
 {
     if ($value instanceof \DateTime) {
         $value = DateTime::getFormat($value);
     }
     if (is_int($value) || is_float($value)) {
         $this->writer->text($value);
     } elseif (is_bool($value)) {
         $this->writer->text($value ? 'true' : 'false');
     } elseif (is_null($value)) {
     } else {
         $this->writer->text((string) $value);
     }
 }
コード例 #22
0
ファイル: ResetPw.php プロジェクト: visapi/amun
 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());
     }
 }
コード例 #23
0
ファイル: Handler.php プロジェクト: visapi/amun
 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');
     }
 }
コード例 #24
0
ファイル: Handler.php プロジェクト: visapi/amun
 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');
     }
 }
コード例 #25
0
ファイル: ValidationVisitor.php プロジェクト: seytar/psx
 public function visitDateTime($data, Property\DateTimeType $property, $path)
 {
     $this->assertRequired($data, $property, $path);
     if ($data === null) {
         return true;
     } elseif ($data instanceof \DateTime) {
         return true;
     } elseif (is_string($data)) {
         $result = preg_match('/^' . DateTime::getPattern() . '$/', $data);
         if ($result) {
             return true;
         }
     }
     throw new ValidationException($path . ' must be an valid date-time format (full-date "T" full-time) [RFC3339]');
 }
コード例 #26
0
ファイル: Index.php プロジェクト: visapi/amun
 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;
 }
コード例 #27
0
ファイル: Connect.php プロジェクト: visapi/amun
 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');
     }
 }
コード例 #28
0
ファイル: Register.php プロジェクト: visapi/amun
 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());
     }
 }
コード例 #29
0
ファイル: Record.php プロジェクト: visapi/amun
 public function getLastModified()
 {
     $date = new DateTime();
     $date->setTimestamp(filemtime($this->getFile()));
     return $date;
 }
コード例 #30
0
ファイル: Sql.php プロジェクト: k42b3/psx-ws
 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)));
 }