_server/user.php
/**
 * @param $userRole // Optional. Beside checking for login, also returns if user has this role.
 *
 * checks if User is logged in and/or has given userlevel
 * Returning codes:
 * 2 = Userfile missing
 * 1 = success
 * 0 = nope
 * 3 = yes, but inactive
 * 4 = yes, but has not given user role
 *
 */
@param $userRole // Optional. Beside checking for login, also returns if user has this role.
@param $userRole // Optional . Beside checking for login also returns if user has this role .
function userCheckLogin($userRole = false) {
	global $conf;
	if (!file_exists($conf["dir"]["data"]."/users.json")) {
		$return["status"] = "fail";
		$return["code"] = 2;
		$return["string"] = "Userfile is missing";
	} elseif ($_SESSION["ohv"]["login"] == 1) {
		$userFile = $conf["dir"]["data"]."/users.json";
		$file = new sharedFile($userFile);
		$json = $file->read();
		$userdb = json_decode($json,true);
		$tmpUserID = $_SESSION["ohv"]["user"]["id"];
		$_SESSION["ohv"]["user"] = $userdb["user"][$tmpUserID];
		$_SESSION["ohv"]["user"]["id"] = $tmpUserID;
		$file->close();
		$return["status"] = "success";
		$return["code"] = 1;
		$return["string"] = "user logged in";
		$return["session_lifetime"] = $conf["server"]["session_lifetime"];
		if ($_SESSION["ohv"]["user"]["active"] == 0) {
			$return["status"] = "success";
			$return["code"] = 3;
			$return["string"] = "User is logged in but not active";
		}
		if ($userRole && ($_SESSION["ohv"]["user"]["role"] != $userRole)) {
			$return["status"] = "success";
			$return["code"] = 4;
			$return["string"] = "User is logged in but does not have the required user role";
		}
		$return["response"] = $_SESSION["ohv"]["user"];
		unset($return["response"]["passwd"]);
	} else {
		$return["status"] = "fail";
		$return["code"] = 0;
		$return["string"] = "User not logged in";
	}
	return $return;
}
function userCheckLogin ( $ userRole = false ) { global $ conf ; if ( ! file_exists ( $ conf [ " dir " ] [ " data " ] . " /users.json " ) ) { $ return [ " status " ] = " fail " ; $ return [ " code " ] = 2 ; $ return [ " string " ] = " Userfile is missing " ; } elseif ( $ _SESSION [ " ohv " ] [ " login " ] == 1 ) { $ userFile = $ conf [ " dir " ] [ " data " ] . " /users.json " ; $ file = new sharedFile ( $ userFile ) ; $ json = $ file -> read ( ) ; $ userdb = json_decode ( $ json , true ) ; $ tmpUserID = $ _SESSION [ " ohv " ] [ " user " ] [ " id " ] ; $ _SESSION [ " ohv " ] [ " user " ] = $ userdb [ " user " ] [ $ tmpUserID ] ; $ _SESSION [ " ohv " ] [ " user " ] [ " id " ] = $ tmpUserID ; $ file -> close ( ) ; $ return [ " status " ] = " success " ; $ return [ " code " ] = 1 ; $ return [ " string " ] = " user logged in " ; $ return [ " session_lifetime " ] = $ conf [ " server " ] [ " session_lifetime " ] ; if ( $ _SESSION [ " ohv " ] [ " user " ] [ " active " ] == 0 ) { $ return [ " status " ] = " success " ; $ return [ " code " ] = 3 ; $ return [ " string " ] = " User is logged in but not active " ; } if ( $ userRole && ( $ _SESSION [ " ohv " ] [ " user " ] [ " role " ] != $ userRole ) ) { $ return [ " status " ] = " success " ; $ return [ " code " ] = 4 ; $ return [ " string " ] = " User is logged in but does not have the required user role " ; } $ return [ " response " ] = $ _SESSION [ " ohv " ] [ " user " ] ; unset ( $ return [ " response " ] [ " passwd " ] ) ; } else { $ return [ " status " ] = " fail " ; $ return [ " code " ] = 0 ; $ return [ " string " ] = " User not logged in " ; } return $ return ; }
@param $userRole // Optional.
@param $userRole // Optional .
//Update own data to check if user is still admin or other things have changed