示例#1
0
     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();
     } else {
示例#2
0
文件: base.php 项目: krsvital/core
 /**
  * Tries to login a user using the form based authentication
  * @return bool|void
  */
 protected static function tryFormLogin()
 {
     if (!isset($_POST["user"]) || !isset($_POST['password'])) {
         return false;
     }
     if (!OC_Util::isCallRegistered()) {
         return false;
     }
     OC_App::loadApps();
     //setup extra user backends
     OC_User::setupBackends();
     if (OC_User::login((string) $_POST["user"], (string) $_POST["password"])) {
         $userId = OC_User::getUser();
         // setting up the time zone
         if (isset($_POST['timezone-offset'])) {
             self::$server->getSession()->set('timezone', (string) $_POST['timezone-offset']);
             self::$server->getConfig()->setUserValue($userId, 'core', 'timezone', (string) $_POST['timezone']);
         }
         self::cleanupLoginTokens($userId);
         if (!empty($_POST["remember_login"])) {
             $config = self::$server->getConfig();
             if ($config->getSystemValue('debug', false)) {
                 self::$server->getLogger()->debug('Setting remember login to cookie', array('app' => 'core'));
             }
             $token = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(32);
             $config->setUserValue($userId, 'login_token', $token, time());
             OC_User::setMagicInCookie($userId, $token);
         } else {
             OC_User::unsetMagicInCookie();
         }
         OC_Util::redirectToDefaultPage();
         exit;
     }
     return true;
 }
示例#3
0
文件: base.php 项目: pinoniq/core
 /**
  * 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;
 }
示例#4
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;
 }
示例#5
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;
 }