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'])) { self::$session->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_Util::generateRandomBytes(32); OC_Preferences::setValue($userid, 'login_token', $token, time()); OC_User::setMagicInCookie($userid, $token); } else { OC_User::unsetMagicInCookie(); } OC_Util::redirectToDefaultPage(); exit; } return true; }
/** * logout the user from the session */ public function logout() { $this->manager->emit('\OC\User', 'logout'); $this->setUser(null); $this->setLoginName(null); $this->unsetMagicInCookie(); $this->session->clear(); }
/** * will keep the session instance in sync with \OC::$session * @return \OC\Session\Session */ private function getSession() { //keep $this->session in sync with \OC::$session if ($this->session !== \OC::$session) { \OC::$server->getLogger()->debug('\\OC::$session has been replaced with a new instance. ' . 'Closing and replacing session in UserSession instance.'); $this->session->close(); $this->session = \OC::$session; } return $this->session; }
/** * get the login name of the current user * * @return string */ public function getLoginname() { if ($this->activeUser) { return $this->session->get('loginname'); } else { $uid = $this->session->get('user_id'); if ($uid) { $this->activeUser = $this->manager->get($uid); return $this->session->get('loginname'); } else { return null; } } }
public function close() { session_write_close(); parent::close(); }
public function testNotExistsAfterClear() { $this->instance->set('foo', 1); $this->instance->clear(); $this->assertFalse($this->instance->exists('foo')); }