本文整理汇总了PHP中GO::session方法的典型用法代码示例。如果您正苦于以下问题:PHP GO::session方法的具体用法?PHP GO::session怎么用?PHP GO::session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GO
的用法示例。
在下文中一共展示了GO::session方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: imapAuthenticate
/**
* Authenticate to imap and return
* @return \GO\Base\Model\User
*/
public function imapAuthenticate()
{
//disable password validation because we can't control the external passwords
\GO::config()->password_validate = false;
$imap = new \GO\Base\Mail\Imap();
try {
$imap->connect($this->config['host'], $this->config['port'], $this->imapUsername, $this->imapPassword, $this->config['ssl']);
\GO::debug('IMAPAUTH: IMAP login succesful');
$imap->disconnect();
$user = \GO\Base\Model\User::model()->findSingleByAttribute('username', $this->goUsername);
if ($user) {
\GO::debug("IMAPAUTH: Group-Office user already exists.");
if (!$user->checkPassword($this->imapPassword)) {
\GO::debug('IMAPAUTH: IMAP password has been changed. Updating Group-Office database');
$user->password = $this->imapPassword;
if (!$user->save()) {
throw new \Exception("Could not save user: " . implode("\n", $user->getValidationErrors()));
}
}
$this->user = $user;
if (\GO::modules()->isInstalled('email')) {
if (!$this->checkEmailAccounts($this->user, $this->config['host'], $this->imapUsername, $this->imapPassword)) {
$this->createEmailAccount($this->user, $this->config, $this->imapUsername, $this->imapPassword);
}
}
}
return true;
} catch (\Exception $e) {
\GO::debug('IMAPAUTH: Authentication to IMAP server failed with Exception: ' . $e->getMessage() . ' IMAP error:' . $imap->last_error());
$imap->clear_errors();
\GO::session()->logout();
//for clearing remembered password cookies
return false;
}
}
示例2: run
/**
* The code that needs to be called when the cron is running
*
* If $this->enableUserAndGroupSupport() returns TRUE then the run function
* will be called for each $user. (The $user parameter will be given)
*
* If $this->enableUserAndGroupSupport() returns FALSE then the
* $user parameter is null and the run function will be called only once.
*
* @param CronJob $cronJob
* @param \GO\Base\Model\User $user [OPTIONAL]
*/
public function run(CronJob $cronJob, \GO\Base\Model\User $user = null)
{
\GO::session()->runAsRoot();
$usersStmt = \GO\Base\Model\User::model()->findByAttribute('mail_reminders', 1);
while ($userModel = $usersStmt->fetch()) {
\GO::debug("Sending mail reminders to " . $userModel->username);
$remindersStmt = \GO\Base\Model\Reminder::model()->find(\GO\Base\Db\FindParams::newInstance()->joinModel(array('model' => 'GO\\Base\\Model\\ReminderUser', 'localTableAlias' => 't', 'localField' => 'id', 'foreignField' => 'reminder_id', 'tableAlias' => 'ru'))->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('user_id', $userModel->id, '=', 'ru')->addCondition('time', time(), '<', 'ru')->addCondition('mail_sent', '0', '=', 'ru')));
while ($reminderModel = $remindersStmt->fetch()) {
// $relatedModel = $reminderModel->getRelatedModel();
// var_dump($relatedModel->name);
// $modelName = $relatedModel ? $relatedModel->localizedName : \GO::t('unknown');
$subject = \GO::t('reminder') . ': ' . $reminderModel->name;
$time = !empty($reminderModel->vtime) ? $reminderModel->vtime : $reminderModel->time;
date_default_timezone_set($userModel->timezone);
$body = \GO::t('time') . ': ' . date($userModel->completeDateFormat . ' ' . $userModel->time_format, $time) . "\n";
$body .= \GO::t('name') . ': ' . str_replace('<br />', ',', $reminderModel->name) . "\n";
// date_default_timezone_set(\GO::user()->timezone);
$message = \GO\Base\Mail\Message::newInstance($subject, $body);
$message->addFrom(\GO::config()->noreply_email, \GO::config()->title);
$message->addTo($userModel->email, $userModel->name);
\GO\Base\Mail\Mailer::newGoInstance()->send($message, $failedRecipients);
if (!empty($failedRecipients)) {
trigger_error("Reminder mail failed for recipient: " . implode(',', $failedRecipients), E_USER_NOTICE);
}
$reminderUserModelSend = \GO\Base\Model\ReminderUser::model()->findSingleByAttributes(array('user_id' => $userModel->id, 'reminder_id' => $reminderModel->id));
$reminderUserModelSend->mail_sent = 1;
$reminderUserModelSend->save();
}
date_default_timezone_set(\GO::user()->timezone);
}
}
示例3: setAuthorized
/**
* Set an authorization for an action so the current session is authorized to
* process the action.
*
* @param string $name
*/
public static function setAuthorized($name)
{
if (empty(\GO::session()->values['Authorized'])) {
\GO::session()->values['Authorized'] = array();
}
\GO::session()->values['Authorized'][] = $name;
}
示例4: beforeSubmit
protected function beforeSubmit(&$response, &$model, &$params)
{
if (!\GO::user()) {
if (empty($params['serverclient_token']) || $params['serverclient_token'] != \GO::config()->serverclient_token) {
throw new \GO\Base\Exception\AccessDenied();
} else {
\GO::session()->runAsRoot();
}
}
if (isset($params['domain_id'])) {
$domainModel = \GO\Postfixadmin\Model\Domain::model()->findByPk($params['domain_id']);
} else {
$domainModel = \GO\Postfixadmin\Model\Domain::model()->findSingleByAttribute("domain", $params['domain']);
//serverclient module doesn't know the domain_id. It sends the domain name as string.
if (!$domainModel) {
//todo create new domain
$domainModel = new \GO\Postfixadmin\Model\Domain();
$domainModel->domain = $params['domain'];
$domainModel->user_id = \GO::user()->id;
$domainModel->save();
}
$params['domain_id'] = $domainModel->id;
$model->quota = $domainModel->default_quota;
}
if (isset($params['quota'])) {
$model->quota = \GO\Base\Util\Number::unlocalize($params['quota']) * 1024;
unset($params['quota']);
}
if ($params['password'] != $params['password2']) {
throw new \Exception(\GO::t('passwordMatchError'));
}
if (empty($params['password'])) {
unset($params['password']);
}
if (isset($params['username'])) {
$params['username'] .= '@' . $domainModel->domain;
}
if ($model->isNew) {
// $aliasModel = \GO\Postfixadmin\Model\Alias::model()->findSingleByAttribute('address', $params['username']);
// if (empty($aliasModel)) {
// $aliasModel = new \GO\Postfixadmin\Model\Alias();
// }
// $aliasModel->domain_id = $params['domain_id'];
// $aliasModel->address = $params['username'];
// $aliasModel->goto = $params['username'];
// $aliasModel->save();
if (!empty($params['alias']) && $params['alias'] != $params['username']) {
$aliasModel = \GO\Postfixadmin\Model\Alias::model()->findSingleByAttribute('address', $params['alias']);
if (empty($aliasModel)) {
$aliasModel = new \GO\Postfixadmin\Model\Alias();
}
$aliasModel->domain_id = $params['domain_id'];
$aliasModel->address = $params['alias'];
$aliasModel->goto = $params['username'];
$aliasModel->save();
}
}
}
示例5: run
/**
* The code that needs to be called when the cron is running
*
* If $this->enableUserAndGroupSupport() returns TRUE then the run function
* will be called for each $user. (The $user parameter will be given)
*
* If $this->enableUserAndGroupSupport() returns FALSE then the
* $user parameter is null and the run function will be called only once.
*
* @param \GO\Base\Cron\CronJob $cronJob
* @param \GO\Base\Model\User $user [OPTIONAL]
*/
public function run(\GO\Base\Cron\CronJob $cronJob, \GO\Base\Model\User $user = null)
{
\GO::session()->runAsRoot();
$pdf = $this->_getUserPdf($user);
if ($this->_sendEmail($user, $pdf)) {
\GO::debug("CRON MAIL IS SEND!");
} else {
\GO::debug("CRON MAIL HAS NOT BEEN SEND!");
}
}
示例6: export
/**
* Export the contact model to a .csv, including the company.
*
* @param array $params
*/
public function export($params)
{
GO::$disableModelCache = true;
GO::setMaxExecutionTime(420);
// Load the data from the session.
$findParams = \GO::session()->values['contact']['findParams'];
$findParams->getCriteria()->recreateTemporaryTables();
$model = \GO::getModel(\GO::session()->values['contact']['model']);
// Include the companies
$findParams->joinRelation('company', 'LEFT');
// Let the export handle all found records without a limit
$findParams->limit(0);
// Create the statement
$stmt = $model->find($findParams);
// Create the csv file
$csvFile = new \GO\Base\Fs\CsvFile(\GO\Base\Fs\File::stripInvalidChars('export.csv'));
// Output the download headers
\GO\Base\Util\Http::outputDownloadHeaders($csvFile, false);
$csvWriter = new \GO\Base\Csv\Writer('php://output');
$headerPrinted = false;
$attrs = array();
$compAttrs = array();
foreach ($stmt as $m) {
$iterationStartUnix = time();
if (!$headerPrinted) {
$attrs = $m->getAttributes();
$compAttrs = $m->company->getAttributes();
}
$header = array();
$record = array();
foreach ($attrs as $attr => $val) {
if (!$headerPrinted) {
$header[$attr] = $m->getAttributeLabel($attr);
}
$record[$attr] = $m->{$attr};
}
foreach ($compAttrs as $cattr => $cval) {
if (!$headerPrinted) {
$header[GO::t('company', 'addressbook') . $cattr] = GO::t('company', 'addressbook') . ':' . $m->company->getAttributeLabel($cattr);
}
$record[GO::t('company', 'addressbook') . $cattr] = $m->company->{$cattr};
}
if (!$headerPrinted) {
$csvWriter->putRecord($header);
$headerPrinted = true;
}
$csvWriter->putRecord($record);
}
}
示例7: __construct
public function __construct($arguments)
{
if (isset($arguments['user'])) {
$this->id = 'groupoffice::' . $arguments['user'] . '/';
$this->groupoffice_data = \GO::config()->file_storage_path;
\GO::session()->setCurrentUser(\GO\Base\Model\User::model()->findSingleByAttribute('username', $arguments['user']));
$this->groupoffice_shares['ownFolder'] = 'users/' . $arguments['user'];
$shares = \GO\Files\Model\Folder::model()->getTopLevelShares(\GO\Base\Db\FindParams::newInstance()->limit(100));
foreach ($shares as $folder) {
$this->groupoffice_shares[$folder->name] = $folder->path;
}
} else {
throw new \Exception('Creating \\OC\\Files\\Storage\\Groupoffice storage failed');
}
}
示例8: __construct
/**
* The constructor for the exporter
*
* @param \GO\Base\Data\Store $store
* @param \GO\Base\Data\ColumnModel $columnModel
* @param Boolean $header
* @param Boolean $humanHeaders
* @param String $title
* @param Mixed $orientation ('P' for Portrait,'L' for Landscape of false for none)
*/
public function __construct(\GO\Base\Data\AbstractStore $store, $header = true, $humanHeaders = true, $title = false, $orientation = false)
{
$this->store = $store;
$this->header = $header;
$this->title = $title;
$this->orientation = $orientation;
$this->humanHeaders = $humanHeaders;
if (is_a($store, "\\GO\\Base\\Data\\DbStore")) {
$exportName = $this->store->getFindParams()->getParam('export');
$this->totalizeColumns = isset(\GO::session()->values[$exportName]['totalizeColumns']) ? \GO::session()->values[$exportName]['totalizeColumns'] : array();
foreach ($this->totalizeColumns as $column) {
$this->totals[$column] = 0;
}
}
}
示例9: run
/**
* The code that needs to be called when the cron is running
*
* If $this->enableUserAndGroupSupport() returns TRUE then the run function
* will be called for each $user. (The $user parameter will be given)
*
* If $this->enableUserAndGroupSupport() returns FALSE then the
* $user parameter is null and the run function will be called only once.
*
* @param \GO\Base\Cron\CronJob $cronJob
* @param \GO\Base\Model\User $user [OPTIONAL]
*/
public function run(\GO\Base\Cron\CronJob $cronJob, \GO\Base\Model\User $user = null)
{
\GO::session()->runAsRoot();
\GO::debug("Start updating public calendars.");
$calendars = \GO\Calendar\Model\Calendar::model()->findByAttribute('public', true);
foreach ($calendars as $calendar) {
$file = new \GO\Base\Fs\File($calendar->getPublicIcsPath());
if (!$file->exists()) {
\GO::debug("Creating " . $file->path() . ".");
$file->touch(true);
}
$file->putContents($calendar->toVObject());
\GO::debug("Updating " . $calendar->name . " to " . $file->path() . ".");
}
\GO::debug("Finished updating public calendars.");
}
示例10: checkPassword
public function checkPassword($uid, $password)
{
$this->_user[$uid] = \GO::session()->login($uid, $password, false);
if (!$this->_user[$uid]) {
return false;
} else {
//workaround bug in ownCloud
$cache = \OC_User::getHome($uid) . '/cache';
if (!is_dir($cache)) {
mkdir($cache, 0755, true);
}
//make sure ownCloud folder exists in Group-Office
$folder = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'users/' . $uid . $this->_groupoffice_mount);
$folder->create();
return $uid;
}
}
示例11: actionSwitch
protected function actionSwitch($params)
{
//
// if(!\GO::user()->isAdmin())
// throw new \Exception("This feature is for admins only!");
$oldUsername = \GO::user()->username;
$debug = !empty(\GO::session()->values['debug']);
$user = \GO\Base\Model\User::model()->findByPk($params['user_id']);
\GO::session()->values = array();
//clear session
\GO::session()->setCurrentUser($user->id);
//\GO::session()->setCompatibilitySessionVars();
if ($debug) {
\GO::session()->values['debug'] = $debug;
}
\GO::infolog("ADMIN logged-in as user: \"" . $user->username . "\" from IP: " . $_SERVER['REMOTE_ADDR']);
if (\GO::modules()->isInstalled('log')) {
\GO\Log\Model\Log::create('switchuser', "'" . $oldUsername . "' logged in as '" . $user->username . "'");
}
$this->redirect();
}
示例12: dirname
<?php
$root = dirname(__FILE__) . '/';
//chdir($root);
//on the command line you can pass -c=/path/to/config.php to set the config file.
require_once $root . 'go/base/util/Cli.php';
$args = \GO\Base\Util\Cli::parseArgs();
if (isset($args['c'])) {
define("GO_CONFIG_FILE", $args['c']);
}
//initialize autoloading of library
require_once $root . 'go/GO.php';
\GO::init();
if (!isset($args['q'])) {
echo "\nGroup-Office CLI - Copyright Intermesh BV.\n\n";
}
if (PHP_SAPI != 'cli') {
exit("ERROR: This script must be run on the command line\n\n");
}
if (empty($args['r'])) {
echo "ERROR: You must pass a controller route to use the command line script.\n" . "eg.:\n\n" . "sudo -u www-data php index.php -c=/path/to/config.php -r=maintenance/upgrade --param=value\n\n";
exit;
} elseif (isset($args['u'])) {
$password = isset($args['p']) ? $args['p'] : \GO\Base\Util\Cli::passwordPrompt("Enter password for user " . $args['u'] . ":");
$user = \GO::session()->login($args['u'], $password);
if (!$user) {
echo "Login failed for user " . $args['u'] . "\n";
exit(1);
}
unset($args['u']);
}
\GO::router()->runController($args);
示例13: actionBuildSearchCache
/**
* Calls buildSearchIndex on each Module class.
* @return array
*/
protected function actionBuildSearchCache($params)
{
if (!$this->isCli() && !\GO::modules()->tools && \GO::router()->getControllerAction() != 'upgrade') {
throw new \GO\Base\Exception\AccessDenied();
}
GO::setIgnoreAclPermissions(true);
$this->lockAction();
if (!$this->isCli()) {
echo '<pre>';
}
\GO::session()->closeWriting();
//close writing otherwise concurrent requests are blocked.
$response = array();
// if(empty($params['keepexisting']))
// \GO::getDbConnection()->query('TRUNCATE TABLE go_search_cache');
//
//inserting is much faster without full text index. It's faster to add it again afterwards.
// echo "Dropping full text search index\n";
// try{
// \GO::getDbConnection()->query("ALTER TABLE go_search_cache DROP INDEX ft_keywords");
// }catch(\Exception $e){
// echo $e->getMessage()."\n";
// }
if (!empty($params['modelName'])) {
$modelName = $params['modelName'];
if (empty($params['keepexisting'])) {
$query = 'DELETE FROM go_search_cache WHERE model_name=' . \GO::getDbConnection()->quote($modelName);
\GO::getDbConnection()->query($query);
}
$models = array(new ReflectionClass($modelName));
} else {
if (empty($params['keepexisting'])) {
\GO::getDbConnection()->query('TRUNCATE TABLE go_search_cache');
}
$models = \GO::findClasses('model');
}
foreach ($models as $model) {
if ($model->isSubclassOf("GO\\Base\\Db\\ActiveRecord") && !$model->isAbstract()) {
echo "Processing " . $model->getName() . "\n";
flush();
$stmt = \GO::getModel($model->getName())->rebuildSearchCache();
}
}
if (empty($params['modelName'])) {
\GO::modules()->callModuleMethod('buildSearchCache', array(&$response));
}
// echo "Adding full text search index\n";
// \GO::getDbConnection()->query("ALTER TABLE `go_search_cache` ADD FULLTEXT ft_keywords(`name` ,`keywords`);");
echo "\n\nAll done!\n\n";
if (!$this->isCli()) {
echo '</pre>';
}
}
示例14: actionTicketList
/**
* Page to show the ticketlist when a user is logged in
*/
protected function actionTicketList()
{
if (!\GO::user()) {
$this->redirect(array('tickets/site/ticketlogin'));
}
// Build the findparams to retreive the ticketlist from the DB
$findParams = \GO\Base\Db\FindParams::newInstance();
$findParams->getCriteria()->addCondition('user_id', \GO::user()->id);
$findParams->order('mtime', 'DESC');
if (!isset(\GO::session()->values['sites_ticketlist'])) {
\GO::session()->values['sites_ticketlist'] = 'openprogress';
}
if (isset($_GET['filter'])) {
\GO::session()->values['sites_ticketlist'] = $_GET['filter'];
}
// Option to filter the tickets
switch (\GO::session()->values['sites_ticketlist']) {
case 'open':
$findParams->getCriteria()->addCondition('status_id', 0, '=');
break;
case 'progress':
$findParams->getCriteria()->addCondition('status_id', 0, '>');
break;
case 'openprogress':
$findParams->getCriteria()->addCondition('status_id', 0, '>=');
break;
case 'closed':
$findParams->getCriteria()->addCondition('status_id', 0, '<');
break;
default:
break;
}
// Create the pager for the ticket messages
$pager = new \GO\Site\Widgets\Pager('p', $_REQUEST, \GO\Tickets\Model\Ticket::model(), $findParams, \GO::user()->max_rows_list, 2);
// Render the ticketlist page
$this->render('ticketlist', array('pager' => $pager));
}
示例15: setCurrentUser
/**
* Sets current user for the entire session. Use it wisely!
* @param int/Model\User $user_id
*/
public function setCurrentUser($user_id)
{
// if(\GO::modules()->isInstalled("log"))
// \GO\Log\Model\Log::create ("setcurrentuser", "Set user ID to $user_id");
if ($user_id instanceof Model\User) {
$this->_user = $user_id;
$this->values['user_id'] = $user_id->id;
} else {
//remember user id in session
$this->values['user_id'] = $user_id;
}
if (!\GO::user()) {
throw new \Exception("Could not set user with id " . $user_id . " in Session::setCurrentUser()!");
}
date_default_timezone_set(\GO::user()->timezone);
\GO::language()->setLanguage(\GO::user()->language);
//for logging
\GO::session()->values['username'] = \GO::user()->username;
}