<commit_before><?php
/**
 * Copyright 2015 <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @file login.php
 * Webpagesection OIDC-button.
 */

$isTutor = false;
$user_oidc_profile = new stdClass();
$user_database_entry = NULL;

abstract class USER_STATUS
{
    const NO_SESSION = 0;
    const LAS2PEER_CONNECT_ERROR = 1;
    const OIDC_UNAUTHORIZED = 2;
    const OIDC_ERROR = 3;
    const DATABASE_ERROR = 4;
    const USER_NOT_CONFIRMED = 5;
    const USER_IS_TUTOR = 6;
}

$status = -1;


if(!isset($_SESSION['access_token'])) {
	$status = USER_STATUS::NO_SESSION;
} else {
  // fake login
  //$_SESSION['access_token'] = '<KEY>';
  //$_SESSION['sub'] = '8f55-3f84d7524753';
  //FB::log($_SESSION);
  $user_oidc_profile->access_token = $_SESSION['access_token'];
  $user_oidc_profile->sub = $_SESSION['sub'];
  
	// following is not needed for fake login
	// require '../config/config.php';
	require_once '../php/tools.php';
	//
	// $aRes = httpRequest("GET", $las2peerUrl.'/'.'user'.'?access_token='.$_SESSION['access_token']);	
	//
	// if($aRes->bOk == FALSE) { $status = USER_STATUS::LAS2PEER_CONNECT_ERROR;
	// } else if($aRes->iStatus === 401) { $status = USER_STATUS::OIDC_UNAUTHORIZED;
	// } else if($aRes->iStatus !== 200) { $status = USER_STATUS::OIDC_ERROR;
	// } else {
	//	// OIDC is OK
	//	// check if user is confirmed as tutor
	//	$user_oidc_profile = json_decode($aRes->sMsg);

	try {
		   $user_database_entry = getSingleDatabaseEntryByValue('users', 'openIdConnectSub', $user_oidc_profile->sub);
		   
		   if(!$user_database_entry) {
		   	// User has no databaseentry
				$status = USER_STATUS::USER_NOT_CONFIRMED;
		   } else {
		   	if($user_database_entry['confirmed'] != 1) {
					$status = USER_STATUS::USER_NOT_CONFIRMED;
				} else {
					$status = USER_STATUS::USER_IS_TUTOR;			
				}
		   }
	} catch (Exception $e) {
			$status = USER_STATUS::DATABASE_ERROR;
			error_log($e->getMessage());
	}
	
	// DEBUG:
	// if($aRes->bOk == FALSE or $aRes->iStatus !== 200) {
	// 	error_log('3dnrt/user call unsuccessfull: '.$aRes->sMsg);
	// }
}

switch($status) {
	case USER_STATUS::NO_SESSION:
		$err_msg = 'This feature can only be used as a lecturer. We cannot confirm that you are a lecturer when you are not logged in. If you are a lecturer, please click the "Sign in" button to log in.';
		break;
	case USER_STATUS::LAS2PEER_CONNECT_ERROR:
		$err_msg = 'Unable to check your login, sorry!';
		break;
	case USER_STATUS::OIDC_UNAUTHORIZED:
		$err_msg = 'Your logindata is invalid. Probably the session has expired and you have to login again.';
		break;
	case USER_STATUS::OIDC_ERROR:
		$err_msg = 'Some error with your account-validation occured, sorry!';
		break;
	case USER_STATUS::DATABASE_ERROR:
		$err_msg = 'Your tutor-status could not be checked, sorry! You may try again later.';
		break;
	case USER_STATUS::USER_NOT_CONFIRMED:
		$err_msg = 'At the moment, you do not have a lecturer account. If you are a lecturer, you can request your account being upgraded to a lecturer account by clicking the "I am a lecturer!" button.';
		break;
	case USER_STATUS::USER_IS_TUTOR:
		$err_msg = '';
		break;
}

/////////////// Start Output
	
switch($status) {
	case USER_STATUS::NO_SESSION:<commit_msg>Not logged in: Shortened text<commit_after><?php
/**
 * Copyright 2015 <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @file login.php
 * Webpagesection OIDC-button.
 */

$isTutor = false;
$user_oidc_profile = new stdClass();
$user_database_entry = NULL;

abstract class USER_STATUS
{
    const NO_SESSION = 0;
    const LAS2PEER_CONNECT_ERROR = 1;
    const OIDC_UNAUTHORIZED = 2;
    const OIDC_ERROR = 3;
    const DATABASE_ERROR = 4;
    const USER_NOT_CONFIRMED = 5;
    const USER_IS_TUTOR = 6;
}

$status = -1;


if(!isset($_SESSION['access_token'])) {
	$status = USER_STATUS::NO_SESSION;
} else {
  // fake login
  //$_SESSION['access_token'] = '<KEY>';
  //$_SESSION['sub'] = '8f55-<KEY>';
  //FB::log($_SESSION);
  $user_oidc_profile->access_token = $_SESSION['access_token'];
  $user_oidc_profile->sub = $_SESSION['sub'];
  
	// following is not needed for fake login
	// require '../config/config.php';
	require_once '../php/tools.php';
	//
	// $aRes = httpRequest("GET", $las2peerUrl.'/'.'user'.'?access_token='.$_SESSION['access_token']);	
	//
	// if($aRes->bOk == FALSE) { $status = USER_STATUS::LAS2PEER_CONNECT_ERROR;
	// } else if($aRes->iStatus === 401) { $status = USER_STATUS::OIDC_UNAUTHORIZED;
	// } else if($aRes->iStatus !== 200) { $status = USER_STATUS::OIDC_ERROR;
	// } else {
	//	// OIDC is OK
	//	// check if user is confirmed as tutor
	//	$user_oidc_profile = json_decode($aRes->sMsg);

	try {
		   $user_database_entry = getSingleDatabaseEntryByValue('users', 'openIdConnectSub', $user_oidc_profile->sub);
		   
		   if(!$user_database_entry) {
		   	// User has no databaseentry
				$status = USER_STATUS::USER_NOT_CONFIRMED;
		   } else {
		   	if($user_database_entry['confirmed'] != 1) {
					$status = USER_STATUS::USER_NOT_CONFIRMED;
				} else {
					$status = USER_STATUS::USER_IS_TUTOR;			
				}
		   }
	} catch (Exception $e) {
			$status = USER_STATUS::DATABASE_ERROR;
			error_log($e->getMessage());
	}
	
	// DEBUG:
	// if($aRes->bOk == FALSE or $aRes->iStatus !== 200) {
	// 	error_log('3dnrt/user call unsuccessfull: '.$aRes->sMsg);
	// }
}

switch($status) {
	case USER_STATUS::NO_SESSION:
		$err_msg = 'This feature can only be used as a lecturer. If you are a lecturer, please click the "Sign in" button to log in.';
		break;
	case USER_STATUS::LAS2PEER_CONNECT_ERROR:
		$err_msg = 'Unable to check your login, sorry!';
		break;
	case USER_STATUS::OIDC_UNAUTHORIZED:
		$err_msg = 'Your logindata is invalid. Probably the session has expired and you have to login again.';
		break;
	case USER_STATUS::OIDC_ERROR:
		$err_msg = 'Some error with your account-validation occured, sorry!';
		break;
	case USER_STATUS::DATABASE_ERROR:
		$err_msg = 'Your tutor-status could not be checked, sorry! You may try again later.';
		break;
	case USER_STATUS::USER_NOT_CONFIRMED:
		$err_msg = 'At the moment, you do not have a lecturer account. If you are a lecturer, you can request your account being upgraded to a lecturer account by clicking the "I am a lecturer!" button.';
		break;
	case USER_STATUS::USER_IS_TUTOR:
		$err_msg = '';
		break;
}

/////////////// Start Output
	
switch($status) {
	case USER_STATUS::NO_SESSION:
{'fraction_non_alphanumeric': 0.1405319571258436, 'fraction_numerical': 0.010321556173084558, 'mean_word_length': 3.801778907242694, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5174902', 'n_tokens_mistral': 2781, 'n_tokens_neox': 2597, 'n_words': 718}