Пример #1
0
 public static function sendEmail($args)
 {
     $isEncrypted = OC_App::isEnabled('files_encryption');
     if (!$isEncrypted || isset($_POST['continue'])) {
         $continue = true;
     } else {
         $continue = false;
     }
     if (OC_User::userExists($_POST['user']) && $continue) {
         $token = hash('sha256', OC_Util::generate_random_bytes(30) . OC_Config::getValue('passwordsalt', ''));
         OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', hash('sha256', $token));
         // Hash the token again to prevent timing attacks
         $email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', '');
         if (!empty($email)) {
             $link = OC_Helper::linkToRoute('core_lostpassword_reset', array('user' => $_POST['user'], 'token' => $token));
             $link = OC_Helper::makeURLAbsolute($link);
             $tmpl = new OC_Template('core/lostpassword', 'email');
             $tmpl->assign('link', $link, false);
             $msg = $tmpl->fetchPage();
             $l = OC_L10N::get('core');
             $from = OCP\Util::getDefaultEmailAddress('lostpassword-noreply');
             try {
                 OC_Mail::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud');
             } catch (Exception $e) {
                 OC_Template::printErrorPage('A problem occurs during sending the e-mail please contact your administrator.');
             }
             self::displayLostPasswordPage(false, true);
         } else {
             self::displayLostPasswordPage(true, false);
         }
     } else {
         self::displayLostPasswordPage(true, false);
     }
 }
Пример #2
0
 public static function sendEmail($args)
 {
     if (OC_User::userExists($_POST['user'])) {
         $token = hash('sha256', OC_Util::generate_random_bytes(30) . OC_Config::getValue('passwordsalt', ''));
         OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', hash('sha256', $token));
         // Hash the token again to prevent timing attacks
         $email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', '');
         if (!empty($email)) {
             $link = OC_Helper::linkToRoute('core_lostpassword_reset', array('user' => $_POST['user'], 'token' => $token));
             $link = OC_Helper::makeURLAbsolute($link);
             $tmpl = new OC_Template('core/lostpassword', 'email');
             $tmpl->assign('link', $link, false);
             $msg = $tmpl->fetchPage();
             $l = OC_L10N::get('core');
             $from = 'lostpassword-noreply@' . OCP\Util::getServerHost();
             OC_Mail::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud');
             echo 'Mailsent';
             self::displayLostPasswordPage(false, true);
         } else {
             self::displayLostPasswordPage(true, false);
         }
     } else {
         self::displayLostPasswordPage(true, false);
     }
 }
Пример #3
0
 public function setUp()
 {
     OCA_mozilla_sync\Utils::setTestState();
     // Create Owncloud Test User
     OC_User::createUser($this->userName, $this->password);
     OC_Preferences::setValue($this->userName, 'settings', 'email', $this->email);
     OCA_mozilla_sync\OutputData::$outputFlag = OCA_mozilla_sync\OutputData::ConstOutputBuffer;
     OCA_mozilla_sync\Utils::setTestState();
     OCA_mozilla_sync\User::createUser($this->userHash, $this->password, $this->email);
 }
Пример #4
0
 public static function setupFS($user = '')
 {
     // configure the initial filesystem based on the configuration
     if (self::$fsSetup) {
         //setting up the filesystem twice can only lead to trouble
         return false;
     }
     // If we are not forced to load a specific user we load the one that is logged in
     if ($user == "" && OC_User::isLoggedIn()) {
         $user = OC_User::getUser();
     }
     // the filesystem will finish when $user is not empty,
     // mark fs setup here to avoid doing the setup from loading
     // OC_Filesystem
     if ($user != '') {
         self::$fsSetup = true;
     }
     $CONFIG_DATADIRECTORY = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
     //first set up the local "root" storage
     if (!self::$rootMounted) {
         OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $CONFIG_DATADIRECTORY), '/');
         self::$rootMounted = true;
     }
     if ($user != "") {
         //if we aren't logged in, there is no use to set up the filesystem
         $user_dir = '/' . $user . '/files';
         $user_root = OC_User::getHome($user);
         $userdirectory = $user_root . '/files';
         if (!is_dir($userdirectory)) {
             mkdir($userdirectory, 0755, true);
         }
         //jail the user into his "home" directory
         OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $user_root), $user);
         OC_Filesystem::init($user_dir);
         $quotaProxy = new OC_FileProxy_Quota();
         OC_FileProxy::register($quotaProxy);
         // Load personal mount config
         if (is_file($user_root . '/mount.php')) {
             $mountConfig = (include $user_root . '/mount.php');
             if (isset($mountConfig['user'][$user])) {
                 foreach ($mountConfig['user'][$user] as $mountPoint => $options) {
                     OC_Filesystem::mount($options['class'], $options['options'], $mountPoint);
                 }
             }
             $mtime = filemtime($user_root . '/mount.php');
             $previousMTime = OC_Preferences::getValue($user, 'files', 'mountconfigmtime', 0);
             if ($mtime > $previousMTime) {
                 //mount config has changed, filecache needs to be updated
                 OC_FileCache::triggerUpdate($user);
                 OC_Preferences::setValue($user, 'files', 'mountconfigmtime', $mtime);
             }
         }
         OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir));
     }
 }
Пример #5
0
 public function setUp()
 {
     OCA_mozilla_sync\Utils::setTestState();
     // Create ownCloud Test User
     OC_User::createUser($this->userName, $this->password);
     OC_User::setUserId($this->userName);
     OC_Preferences::setValue($this->userName, 'settings', 'email', $this->email);
     OCA_mozilla_sync\OutputData::$outputFlag = OCA_mozilla_sync\OutputData::ConstOutputBuffer;
     OCA_mozilla_sync\Utils::setTestState();
     $this->urlParser = new OCA_mozilla_sync\UrlParser('/1.0/' . $this->userHash);
 }
Пример #6
0
 public static function set($parameters)
 {
     OC_Util::checkLoggedIn();
     $user = OC_User::getUser();
     $app = addslashes(strip_tags($parameters['app']));
     $key = addslashes(strip_tags($parameters['key']));
     $value = OC_OCS::readData('post', 'value', 'text');
     if (OC_Preferences::setValue($user, $app, $key, $value)) {
         return new OC_OCS_Result(null, 100);
     }
 }
Пример #7
0
 public function dropTableEncryption()
 {
     $tableName = $this->tableName;
     if (!\OC_DB::tableExists($tableName)) {
         return;
     }
     $sql = "select `uid`, max(`recovery_enabled`) as `recovery_enabled`, min(`migration_status`) as `migration_status` from `*PREFIX*{$tableName}` group by `uid`";
     $query = \OCP\DB::prepare($sql);
     $result = $query->execute(array())->fetchAll();
     foreach ($result as $row) {
         \OC_Preferences::setValue($row['uid'], 'files_encryption', 'recovery_enabled', $row['recovery_enabled']);
         \OC_Preferences::setValue($row['uid'], 'files_encryption', 'migration_status', $row['migration_status']);
     }
     \OC_DB::dropTable($tableName);
 }
 /**
  * @brief Set email address
  * @param $uid The username
  */
 private function setEmail($uid)
 {
     if (!$this->db_conn) {
         return false;
     }
     $sql = 'SELECT email FROM auth_user WHERE username = :uid';
     $sth = $this->db->prepare($sql);
     if ($sth->execute(array(':uid' => $uid))) {
         $row = $sth->fetch();
         if ($row) {
             if (OC_Preferences::setValue($uid, 'settings', 'email', $row['email'])) {
                 return true;
             }
         }
     }
     return false;
 }
Пример #9
0
 public static function loadUserMountPoints($user)
 {
     $user_dir = '/' . $user . '/files';
     $user_root = OC_User::getHome($user);
     $userdirectory = $user_root . '/files';
     if (is_file($user_root . '/mount.php')) {
         $mountConfig = (include $user_root . '/mount.php');
         if (isset($mountConfig['user'][$user])) {
             foreach ($mountConfig['user'][$user] as $mountPoint => $options) {
                 OC_Filesystem::mount($options['class'], $options['options'], $mountPoint);
             }
         }
         $mtime = filemtime($user_root . '/mount.php');
         $previousMTime = OC_Preferences::getValue($user, 'files', 'mountconfigmtime', 0);
         if ($mtime > $previousMTime) {
             //mount config has changed, filecache needs to be updated
             OC_FileCache::triggerUpdate($user);
             OC_Preferences::setValue($user, 'files', 'mountconfigmtime', $mtime);
         }
     }
 }
Пример #10
0
 protected static function tryFormLogin()
 {
     if (!isset($_POST["user"]) || !isset($_POST['password'])) {
         return false;
     }
     OC_App::loadApps();
     //setup extra user backends
     OC_User::setupBackends();
     if (OC_User::login($_POST["user"], $_POST["password"])) {
         // setting up the time zone
         if (isset($_POST['timezone-offset'])) {
             $_SESSION['timezone'] = $_POST['timezone-offset'];
         }
         self::cleanupLoginTokens($_POST['user']);
         if (!empty($_POST["remember_login"])) {
             if (defined("DEBUG") && DEBUG) {
                 OC_Log::write('core', 'Setting remember login to cookie', OC_Log::DEBUG);
             }
             $token = OC_Util::generate_random_bytes(32);
             OC_Preferences::setValue($_POST['user'], 'login_token', $token, time());
             OC_User::setMagicInCookie($_POST["user"], $token);
         } else {
             OC_User::unsetMagicInCookie();
         }
         OC_Util::redirectToDefaultPage();
         exit;
     }
     return true;
 }
Пример #11
0
 /**
  * Sets a value in the preferences
  * @param string $user user
  * @param string $app app
  * @param string $key key
  * @param string $value value
  * @return bool
  *
  * Adds a value to the preferences. If the key did not exist before, it
  * will be added automagically.
  */
 public static function setUserValue($user, $app, $key, $value)
 {
     try {
         \OC_Preferences::setValue($user, $app, $key, $value);
     } catch (Exception $e) {
         return false;
     }
     return true;
 }
<?php

// Init owncloud
require_once '../../lib/base.php';
OC_JSON::checkLoggedIn();
$l = OC_L10N::get('core');
// Get data
if (isset($_POST['email']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
    $email = trim($_POST['email']);
    OC_Preferences::setValue(OC_User::getUser(), 'settings', 'email', $email);
    OC_JSON::success(array("data" => array("message" => $l->t("Email saved"))));
} else {
    OC_JSON::error(array("data" => array("message" => $l->t("Invalid email"))));
}
Пример #13
0
 public function testSetValueWithPreCondition()
 {
     // remove existing key
     $this->assertTrue(\OC_Preferences::deleteKey('Someuser', 'setvalueapp', 'newkey'));
     // add new preference with pre-condition should fails
     $this->assertFalse(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'newvalue', 'preCondition'));
     $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
     $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
     $row = $result->fetchRow();
     $this->assertFalse($row);
     // add new preference without pre-condition should insert the new value
     $this->assertTrue(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'newvalue'));
     $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
     $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
     $row = $result->fetchRow();
     $value = $row['configvalue'];
     $this->assertEquals('newvalue', $value);
     // wrong pre-condition, value should stay the same
     $this->assertFalse(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'othervalue', 'preCondition'));
     $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
     $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
     $row = $result->fetchRow();
     $value = $row['configvalue'];
     $this->assertEquals('newvalue', $value);
     // correct pre-condition, value should change
     $this->assertTrue(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'othervalue', 'newvalue'));
     $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
     $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
     $row = $result->fetchRow();
     $value = $row['configvalue'];
     $this->assertEquals('othervalue', $value);
 }
Пример #14
0
 private static function update_mail($uid, $email)
 {
     if ($email != OC_Preferences::getValue($uid, 'settings', 'email', '')) {
         OC_Preferences::setValue($uid, 'settings', 'email', $email);
         OC_Log::write('saml', 'Set email "' . $email . '" for the user: ' . $uid, OC_Log::DEBUG);
     }
 }
<?php

/**
 * Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
require_once '../../../lib/base.php';
OC_JSON::checkLoggedIn();
if (isset($_POST["duration"])) {
    OC_Preferences::setValue(OC_User::getUser(), 'calendar', 'duration', $_POST["duration"]);
    OC_JSON::success();
} else {
    OC_JSON::error();
}
?>
 
 
Пример #16
0
 /**
  * Tries to login a user using the formbased authentication
  * @return bool|void
  */
 protected static function tryFormLogin()
 {
     if (!isset($_POST["user"]) || !isset($_POST['password'])) {
         return false;
     }
     OC_JSON::callCheck();
     OC_App::loadApps();
     //setup extra user backends
     OC_User::setupBackends();
     if (OC_User::login($_POST["user"], $_POST["password"])) {
         // setting up the time zone
         if (isset($_POST['timezone-offset'])) {
             self::$server->getSession()->set('timezone', $_POST['timezone-offset']);
         }
         $userid = OC_User::getUser();
         self::cleanupLoginTokens($userid);
         if (!empty($_POST["remember_login"])) {
             if (defined("DEBUG") && DEBUG) {
                 OC_Log::write('core', 'Setting remember login to cookie', OC_Log::DEBUG);
             }
             $token = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(32);
             OC_Preferences::setValue($userid, 'login_token', $token, time());
             OC_User::setMagicInCookie($userid, $token);
         } else {
             OC_User::unsetMagicInCookie();
         }
         OC_Util::redirectToDefaultPage();
         exit;
     }
     return true;
 }
Пример #17
0
     // confirm credentials in cookie
     if (isset($_COOKIE['oc_token']) && OC_User::userExists($_COOKIE['oc_username']) && OC_Preferences::getValue($_COOKIE['oc_username'], "login", "token") === $_COOKIE['oc_token']) {
         OC_User::setUserId($_COOKIE['oc_username']);
         OC_Util::redirectToDefaultPage();
     } else {
         OC_User::unsetMagicInCookie();
     }
     // Someone wants to log in :
 } elseif (isset($_POST["user"]) and isset($_POST['password']) and isset($_SESSION['sectoken']) and isset($_POST['sectoken']) and $_SESSION['sectoken'] == $_POST['sectoken']) {
     if (OC_User::login($_POST["user"], $_POST["password"])) {
         if (!empty($_POST["remember_login"])) {
             if (defined("DEBUG") && DEBUG) {
                 OC_Log::write('core', 'Setting remember login to cookie', OC_Log::DEBUG);
             }
             $token = md5($_POST["user"] . time() . $_POST['password']);
             OC_Preferences::setValue($_POST['user'], 'login', 'token', $token);
             OC_User::setMagicInCookie($_POST["user"], $token);
         } else {
             OC_User::unsetMagicInCookie();
         }
         OC_Util::redirectToDefaultPage();
     } else {
         $error = true;
     }
     // The user is already authenticated using Apaches AuthType Basic... very usable in combination with LDAP
 } elseif (isset($_SERVER["PHP_AUTH_USER"]) && isset($_SERVER["PHP_AUTH_PW"])) {
     if (OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])) {
         //OC_Log::write('core',"Logged in with HTTP Authentication",OC_Log::DEBUG);
         OC_User::unsetMagicInCookie();
         $_REQUEST['redirect_url'] = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
         OC_Util::redirectToDefaultPage();
Пример #18
0
 /**
  * check if files are already migrated to the encryption system
  * @return int|false migration status, false = in case of no record
  * @note If records are not being returned, check for a hidden space
  *       at the start of the uid in db
  */
 public function getMigrationStatus()
 {
     $migrationStatus = false;
     if (\OCP\User::userExists($this->userId)) {
         $migrationStatus = \OC_Preferences::getValue($this->userId, 'files_encryption', 'migration_status');
         if ($migrationStatus === null) {
             \OC_Preferences::setValue($this->userId, 'files_encryption', 'migration_status', (string) self::MIGRATION_OPEN);
             $migrationStatus = self::MIGRATION_OPEN;
         }
     }
     return (int) $migrationStatus;
 }
Пример #19
0
<?php

// Init owncloud
require_once '../../lib/base.php';
$l = OC_L10N::get('settings');
OC_JSON::checkLoggedIn();
OCP\JSON::callCheck();
OC_JSON::checkAppEnabled('user_openid');
// Get data
if (isset($_POST['identity'])) {
    $identity = $_POST['identity'];
    OC_Preferences::setValue(OC_User::getUser(), 'user_openid', 'identity', $identity);
    OC_JSON::success(array("data" => array("message" => $l->t("OpenID Changed"))));
} else {
    OC_JSON::error(array("data" => array("message" => $l->t("Invalid request"))));
}
Пример #20
0
 protected static function tryFormLogin()
 {
     if (!isset($_POST["user"]) || !isset($_POST['password'])) {
         return false;
     }
     OC_App::loadApps();
     //setup extra user backends
     OC_User::setupBackends();
     if (OC_User::login($_POST["user"], $_POST["password"])) {
         if (!empty($_POST["remember_login"])) {
             if (defined("DEBUG") && DEBUG) {
                 OC_Log::write('core', 'Setting remember login to cookie', OC_Log::DEBUG);
             }
             $token = md5($_POST["user"] . time() . $_POST['password']);
             OC_Preferences::setValue($_POST['user'], 'login', 'token', $token);
             OC_User::setMagicInCookie($_POST["user"], $token);
         } else {
             OC_User::unsetMagicInCookie();
         }
         header('Location: ' . $_SERVER['REQUEST_URI']);
         exit;
     }
     return true;
 }
Пример #21
0
<?php

$l = OC_L10N::get('settings');
OC_JSON::checkLoggedIn();
OCP\JSON::callCheck();
// Get data
if (isset($_POST['lang'])) {
    $languageCodes = OC_L10N::findAvailableLanguages();
    $lang = $_POST['lang'];
    if (array_search($lang, $languageCodes) or $lang == 'en') {
        OC_Preferences::setValue(OC_User::getUser(), 'core', 'lang', $lang);
        OC_JSON::success(array("data" => array("message" => $l->t("Language changed"))));
    } else {
        OC_JSON::error(array("data" => array("message" => $l->t("Invalid request"))));
    }
} else {
    OC_JSON::error(array("data" => array("message" => $l->t("Invalid request"))));
}
<?php

/**
 * Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
require_once '../../../lib/base.php';
OC_JSON::checkLoggedIn();
if (isset($_POST["firstdayofweek"])) {
    OC_Preferences::setValue(OC_User::getUser(), 'calendar', 'firstdayofweek', $_POST["firstdayofweek"]);
    OC_JSON::success();
} else {
    OC_JSON::error();
}
?>
 
Пример #23
0
 /**
  * perform login using the magic cookie (remember login)
  *
  * @param string $uid the username
  * @param string $currentToken
  * @return bool
  */
 public function loginWithCookie($uid, $currentToken)
 {
     $this->manager->emit('\\OC\\User', 'preRememberedLogin', array($uid));
     $user = $this->manager->get($uid);
     if (is_null($user)) {
         // user does not exist
         return false;
     }
     // get stored tokens
     $tokens = \OC_Preferences::getKeys($uid, 'login_token');
     // test cookies token against stored tokens
     if (!in_array($currentToken, $tokens, true)) {
         return false;
     }
     // replace successfully used token with a new one
     \OC_Preferences::deleteKey($uid, 'login_token', $currentToken);
     $newToken = \OC_Util::generateRandomBytes(32);
     \OC_Preferences::setValue($uid, 'login_token', $newToken, time());
     $this->setMagicInCookie($user->getUID(), $newToken);
     //login
     $this->setUser($user);
     $this->manager->emit('\\OC\\User', 'postRememberedLogin', array($user));
     return true;
 }
Пример #24
0
<?php

/**
 * Copyright (c) 2010 Frank Karlitschek karlitschek@kde.org
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
*/
$RUNTIME_NOAPPS = TRUE;
//no apps
require_once '../../lib/base.php';
// Someone lost their password:
if (isset($_POST['user'])) {
    if (OC_User::userExists($_POST['user'])) {
        $token = sha1($_POST['user'] . md5(uniqid(rand(), true)));
        OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', $token);
        $email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', '');
        if (!empty($email) and isset($_POST['sectoken']) and isset($_SESSION['sectoken']) and $_POST['sectoken'] == $_SESSION['sectoken']) {
            $link = OC_Helper::linkToAbsolute('core/lostpassword', 'resetpassword.php') . '?user='******'user'] . '&token=' . $token;
            $tmpl = new OC_Template('core/lostpassword', 'email');
            $tmpl->assign('link', $link);
            $msg = $tmpl->fetchPage();
            $l = OC_L10N::get('core');
            $from = 'lostpassword-noreply@' . OC_Helper::serverHost();
            OC_MAIL::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud');
            echo 'sent';
        }
        $sectoken = rand(1000000, 9999999);
        $_SESSION['sectoken'] = $sectoken;
        OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => false, 'requested' => true, 'sectoken' => $sectoken));
    } else {
Пример #25
0
 /**
  * Tests that the home storage is not wrapped when no quota exists.
  */
 function testHomeStorageWrapperWithQuota()
 {
     $user1 = uniqid();
     \OC_User::createUser($user1, 'test');
     OC_Preferences::setValue($user1, 'files', 'quota', '1024');
     \OC_User::setUserId($user1);
     \OC_Util::setupFS($user1);
     $userMount = \OC\Files\Filesystem::getMountManager()->find('/' . $user1 . '/');
     $this->assertNotNull($userMount);
     $this->assertTrue($userMount->getStorage()->instanceOfStorage('\\OC\\Files\\Storage\\Wrapper\\Quota'));
     // ensure that root wasn't wrapped
     $rootMount = \OC\Files\Filesystem::getMountManager()->find('/');
     $this->assertNotNull($rootMount);
     $this->assertNotInstanceOf('\\OC\\Files\\Storage\\Wrapper\\Quota', $rootMount->getStorage());
     // clean up
     \OC_User::setUserId('');
     \OC_User::deleteUser($user1);
     OC_Preferences::deleteUser($user1);
     \OC_Util::tearDownFS();
 }
Пример #26
0
 /**
  * @brief sets a value in the preferences
  * @param string $user user
  * @param string $app app
  * @param string $key key
  * @param string $value value
  * @returns bool
  *
  * Adds a value to the preferences. If the key did not exist before, it
  * will be added automagically.
  */
 public static function setUserValue($user, $app, $key, $value)
 {
     return \OC_Preferences::setValue($user, $app, $key, $value);
 }
Пример #27
0
 /**
  * @brief Modifies the given project
  * @param Project ID
  * @param Project title
  * @param Description of the project
  * @param Deadline of the project
  * @param List of members working in the project and their roles
  * @param Member who updated the project
  * @param Whether or not the project has been completed
  * @return int|boolean (Post ID of the post specifying the project updation|false)
  */
 public static function updateProject($pid, $title, $desc, $deadline, $details, $updater, $completed)
 {
     $post_id = NULL;
     try {
         if ($completed && OC_Collaboration_Task::hasPendingTasks($pid)) {
             throw new \Exception('Cannot delete project with pending tasks');
         }
         \OCP\DB::beginTransaction();
         $query = \OCP\DB::prepare('UPDATE `*PREFIX*collaboration_project` SET `title`=?, `description`=?, `last_updated`=CURRENT_TIMESTAMP, `ending_date`=?, `completed`=? WHERE `pid`=?');
         $query->execute(array($title, $desc, OC_Collaboration_Time::convertUITimeToDBTime($deadline . ' 23:59:59'), $completed, $pid));
         $add_member = \OCP\DB::prepare('INSERT INTO `*PREFIX*collaboration_works_on`(`pid`, `member`, `role`) VALUES(?, ?, ?)');
         $cnt = count($details);
         if ($cnt != 0 && isset($details[0]['member'])) {
             foreach ($details as $detail) {
                 $member = strtolower($detail['member']);
                 if (!OC_User::userExists($member)) {
                     OC_User::createUser($member, $member);
                 }
                 $add_member->execute(array($pid, $member, $detail['role']));
                 OC_Preferences::setValue($member, 'settings', 'email', $detail['email']);
                 OC_Preferences::setValue($member, 'collaboration', 'mobile', $detail['mobile']);
             }
         }
         $post_id = OC_Collaboration_Post::createPost('Project Updated', 'Project \'' . $title . '\' has been updated' . '.', $updater, $pid, 'Project Updation', array(), true);
         \OCP\DB::commit();
     } catch (\Exception $e) {
         OC_Log::write('collaboration', __METHOD__ . ', Exception: ' . $e->getMessage(), OCP\Util::DEBUG);
         return false;
     }
     return $post_id;
 }
Пример #28
0
 public function testRememberLoginInvalidUser()
 {
     $session = $this->getMock('\\OC\\Session\\Memory', array(), array(''));
     $session->expects($this->never())->method('set');
     $managerMethods = get_class_methods('\\OC\\User\\Manager');
     //keep following methods intact in order to ensure hooks are
     //working
     $doNotMock = array('__construct', 'emit', 'listen');
     foreach ($doNotMock as $methodName) {
         $i = array_search($methodName, $managerMethods, true);
         if ($i !== false) {
             unset($managerMethods[$i]);
         }
     }
     $manager = $this->getMock('\\OC\\User\\Manager', $managerMethods, array());
     $backend = $this->getMock('OC_User_Dummy');
     $user = $this->getMock('\\OC\\User\\User', array(), array('foo', $backend));
     $user->expects($this->never())->method('getUID');
     $user->expects($this->never())->method('updateLastLoginTimestamp');
     $manager->expects($this->once())->method('get')->with('foo')->will($this->returnValue(null));
     //prepare login token
     $token = 'goodToken';
     \OC_Preferences::setValue('foo', 'login_token', $token, time());
     $userSession = new \OC\User\Session($manager, $session);
     $granted = $userSession->loginWithCookie('foo', $token);
     $this->assertSame($granted, false);
 }
Пример #29
0
 /**
  * updates the timestamp of the most recent login of this user
  */
 public function updateLastLoginTimestamp()
 {
     $this->lastLogin = time();
     \OC_Preferences::setValue($this->uid, 'login', 'lastLogin', $this->lastLogin);
 }
Пример #30
0
require_once '../../lib/base.php';
OC_JSON::checkSubAdminUser();
OCP\JSON::callCheck();
$username = isset($_POST["username"]) ? $_POST["username"] : '';
if ($username == '' && !OC_Group::inGroup(OC_User::getUser(), 'admin') || !OC_Group::inGroup(OC_User::getUser(), 'admin') && !OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username)) {
    $l = OC_L10N::get('core');
    OC_JSON::error(array('data' => array('message' => $l->t('Authentication error'))));
    exit;
}
//make sure the quota is in the expected format
$quota = $_POST["quota"];
if ($quota != 'none' and $quota != 'default') {
    $quota = OC_Helper::computerFileSize($quota);
    if ($quota == 0) {
        $quota = 'default';
    } else {
        $quota = OC_Helper::humanFileSize($quota);
    }
}
// Return Success story
if ($username) {
    OC_Preferences::setValue($username, 'files', 'quota', $quota);
} else {
    //set the default quota when no username is specified
    if ($quota == 'default') {
        //'default' as default quota makes no sense
        $quota = 'none';
    }
    OC_Appconfig::setValue('files', 'default_quota', $quota);
}
OC_JSON::success(array("data" => array("username" => $username, 'quota' => $quota)));