<commit_before><?php
/*
 * Copyright 2007-2011 <NAME> <contact (at) cdujeu.me>
 * This file is part of AjaXplorer.
 *
 * AjaXplorer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * AjaXplorer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with AjaXplorer.  If not, see <http://www.gnu.org/licenses/>.
 *
 * The latest code can be found at <http://www.ajaxplorer.info/>.
 */
defined('AJXP_EXEC') or die( 'Access not allowed');

/**
 * @package info.ajaxplorer.auth
 * @class AbstractAuthDriver
 * Abstract representation of an authentication driver. Must be implemented by the auth plugin
 */
class AbstractAuthDriver extends AJXP_Plugin {
	
	var $options;
	var $driverName = "abstract";
	var $driverType = "auth";
					
	public function switchAction($action, $httpVars, $fileVars)	{
		if(!isSet($this->actions[$action])) return;
		$mess = ConfService::getMessages();
		
		switch ($action){

            case "login" :

                if(!AuthService::usersEnabled()) return;
                $rememberLogin = "";
                $rememberPass = "";
                $secureToken = "";
                $loggedUser = null;
                include_once(AJXP_BIN_FOLDER."/class.CaptchaProvider.php");
        		if(AuthService::suspectBruteForceLogin() && (!isSet($httpVars["captcha_code"]) || !CaptchaProvider::checkCaptchaResult($httpVars["captcha_code"]))){
        			$loggingResult = -4;
        		}else{
        			$userId = (isSet($httpVars["userid"])?$httpVars["userid"]:null);
        			$userPass = (isSet($httpVars["password"])?$httpVars["password"]:null);
        			$rememberMe = ((isSet($httpVars["remember_me"]) && $httpVars["remember_me"] == "true")?true:false);
        			$cookieLogin = (isSet($httpVars["cookie_login"])?true:false);
        			$loggingResult = AuthService::logUser($userId, $userPass, false, $cookieLogin, $httpVars["login_seed"]);
        			if($rememberMe && $loggingResult == 1){
        				$rememberLogin = "notify";
        				$rememberPass = "<PASSWORD>";
        				$loggedUser = AuthService::getLoggedUser();
        			}
        			if($loggingResult == 1){
        				session_regenerate_id(true);
        				$secureToken = AuthService::generateSecureToken();
        			}
        			if($loggingResult < 1 && AuthService::suspectBruteForceLogin()){
        				$loggingResult = -4; // Force captcha reload
        			}
        		}
                $loggedUser = AuthService::getLoggedUser();
                if($loggedUser != null)
               	{
                       $force = $loggedUser->getPref("force_default_repository");
                       $passId = -1;
                       if(isSet($httpVars["tmp_repository_id"])){
                           $passId = $httpVars["tmp_repository_id"];
                       }else if($force != "" && $loggedUser->canSwitchTo($force) && !isSet($httpVars["tmp_repository_id"])){
                           $passId = $force;
                       }
                       $res = ConfService::switchUserToActiveRepository($loggedUser, $passId);
                       if(!$res){
                           AuthService::disconnect();
                           $loggingResult = -3;
                       }
               	}

                if($loggedUser != null && (AuthService::hasRememberCookie() || (isSet($rememberMe) && $rememberMe ==true))){
                    AuthService::refreshRememberCookie($loggedUser);
                }
        		AJXP_XMLWriter::header();
        		AJXP_XMLWriter::loggingResult($loggingResult, $rememberLogin, $rememberPass, $secureToken);
        		AJXP_XMLWriter::close();


            break;

			//------------------------------------
			//	CHANGE USER PASSWORD
			//------------------------------------	
			case "pass_change":
							
				$userObject = AuthService::getLoggedUser();
				if($userObject == null || $userObject->getId() == "guest"){
					header("Content-Type:text/plain");
					print "SUCCESS";
				}
				$oldPass = $httpVars["old_pass"];
				$newPass = $httpVars["new_pass"];
				$passSeed = $httpVars["pass_seed"];
				if(strlen($newPass) < ConfService::getCoreConf("PASSWORD_MINLENGTH", "auth")){
					header("Content-Type:text/plain");
					print "PASS_ERROR";
				}
				if(AuthService::checkPassword($userObject->getId(), $oldPass, false, $passSeed)){
					AuthService::updatePassword($userObject->getId(), $newPass);
				}else{
					header("Content-Type:text/plain");
					print "PASS_ERROR";
				}
				header("Content-Type:text/plain");
				print "SUCCESS";
				
			break;					

            case "logout" :

                AuthService::disconnect();<commit_msg>[AbstractAuthDriver] Wrong ajax response on pass-change error, reported by @ultreia<commit_after><?php
/*
 * Copyright 2007-2011 <NAME> <contact (at) cdujeu.me>
 * This file is part of AjaXplorer.
 *
 * AjaXplorer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * AjaXplorer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with AjaXplorer.  If not, see <http://www.gnu.org/licenses/>.
 *
 * The latest code can be found at <http://www.ajaxplorer.info/>.
 */
defined('AJXP_EXEC') or die( 'Access not allowed');

/**
 * @package info.ajaxplorer.auth
 * @class AbstractAuthDriver
 * Abstract representation of an authentication driver. Must be implemented by the auth plugin
 */
class AbstractAuthDriver extends AJXP_Plugin {
	
	var $options;
	var $driverName = "abstract";
	var $driverType = "auth";
					
	public function switchAction($action, $httpVars, $fileVars)	{
		if(!isSet($this->actions[$action])) return;
		$mess = ConfService::getMessages();
		
		switch ($action){

            case "login" :

                if(!AuthService::usersEnabled()) return;
                $rememberLogin = "";
                $rememberPass = "";
                $secureToken = "";
                $loggedUser = null;
                include_once(AJXP_BIN_FOLDER."/class.CaptchaProvider.php");
        		if(AuthService::suspectBruteForceLogin() && (!isSet($httpVars["captcha_code"]) || !CaptchaProvider::checkCaptchaResult($httpVars["captcha_code"]))){
        			$loggingResult = -4;
        		}else{
        			$userId = (isSet($httpVars["userid"])?$httpVars["userid"]:null);
        			$userPass = (isSet($httpVars["password"])?$httpVars["password"]:null);
        			$rememberMe = ((isSet($httpVars["remember_me"]) && $httpVars["remember_me"] == "true")?true:false);
        			$cookieLogin = (isSet($httpVars["cookie_login"])?true:false);
        			$loggingResult = AuthService::logUser($userId, $userPass, false, $cookieLogin, $httpVars["login_seed"]);
        			if($rememberMe && $loggingResult == 1){
        				$rememberLogin = "notify";
        				$rememberPass = "<PASSWORD>";
        				$loggedUser = AuthService::getLoggedUser();
        			}
        			if($loggingResult == 1){
        				session_regenerate_id(true);
        				$secureToken = AuthService::generateSecureToken();
        			}
        			if($loggingResult < 1 && AuthService::suspectBruteForceLogin()){
        				$loggingResult = -4; // Force captcha reload
        			}
        		}
                $loggedUser = AuthService::getLoggedUser();
                if($loggedUser != null)
               	{
                       $force = $loggedUser->getPref("force_default_repository");
                       $passId = -1;
                       if(isSet($httpVars["tmp_repository_id"])){
                           $passId = $httpVars["tmp_repository_id"];
                       }else if($force != "" && $loggedUser->canSwitchTo($force) && !isSet($httpVars["tmp_repository_id"])){
                           $passId = $force;
                       }
                       $res = ConfService::switchUserToActiveRepository($loggedUser, $passId);
                       if(!$res){
                           AuthService::disconnect();
                           $loggingResult = -3;
                       }
               	}

                if($loggedUser != null && (AuthService::hasRememberCookie() || (isSet($rememberMe) && $rememberMe ==true))){
                    AuthService::refreshRememberCookie($loggedUser);
                }
        		AJXP_XMLWriter::header();
        		AJXP_XMLWriter::loggingResult($loggingResult, $rememberLogin, $rememberPass, $secureToken);
        		AJXP_XMLWriter::close();


            break;

			//------------------------------------
			//	CHANGE USER PASSWORD
			//------------------------------------	
			case "pass_change":
							
				$userObject = AuthService::getLoggedUser();
				if($userObject == null || $userObject->getId() == "guest"){
					header("Content-Type:text/plain");
					print "SUCCESS";
                    break;
				}
				$oldPass = $httpVars["old_pass"];
				$newPass = $httpVars["new_pass"];
				$passSeed = $httpVars["pass_seed"];
				if(strlen($newPass) < ConfService::getCoreConf("PASSWORD_MINLENGTH", "auth")){
					header("Content-Type:text/plain");
					print "PASS_ERROR";
                    break;
				}
				if(AuthService::checkPassword($userObject->getId(), $oldPass, false, $passSeed)){
					AuthService::updatePassword($userObject->getId(), $newPass);
				}else{
					header("Content-Type:text/plain");
					print "PASS_ERROR";
                    break;
				}
				header("Content-Type:text/plain");
				print "SUCCESS";
				
			break;					

            case "logout" :

                AuthService::disconnect();
{'fraction_non_alphanumeric': 0.1482341557813256, 'fraction_numerical': 0.003096274794388002, 'mean_word_length': 2.312820512820513, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5103700', 'n_tokens_mistral': 3273, 'n_tokens_neox': 2906, 'n_words': 613}