_server/user.php
/**
 * @param $name
 * @param $mail
 * @param $passwd
 * @return mixed

 * Returning codes:
 * 0 = success
 * 1 = Mail or Password arent given or Mail is not a valid address
 * 2 = User already registered
 * 3 = Registration success but user needs to be activated

 */


Returning codes:
0 = success
1 = Mail or Password arent given or Mail is not a valid address
2 = User already registered
3 = Registration success but user needs to be activated
Returning codes : 0 = success 1 = Mail or Password arent given or Mail is not a valid address 2 = User already registered 3 = Registration success but user needs to be activated
function userRegister($name, $mail, $passwd) {
	global $conf;
	$tmpFirstUser = false;
	$json = file_get_contents($conf["dir"]["data"]."/config.json");
	$configDB = json_decode($json, true);
	$userFile = $conf["dir"]["data"]."/users.json";
	if (!$mail || !$passwd || (!filter_var($mail, FILTER_VALIDATE_EMAIL)) || !$name) {
		$return["status"] = "fail";
		$return["code"] = 1;
		$return["string"] = "Fill out all fields";
		return $return;
	}
	if (!file_exists($userFile)) {
		$tmp["user-increment"] = 0;
		$tmp["user"] = array();
		$tmpFirstUser = true;
		file_put_contents($userFile, json_encode($tmp, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
	}
	$file = new sharedFile($userFile);
	$json = $file->read();
	$user = json_decode($json,true);
	foreach ($user["user"] as $k=>$v) {
		if ($v["mail"] == strtolower($_REQUEST["mail"])) {
			$return["status"] = "fail";
			$return["code"] = 2;
			$return["string"] = "Already registered";
			$file->close();
			return $return;
		}
	}
	$user["user-increment"]++;
	$user["user"][$user["user-increment"]]["name"] = $name;
	$user["user"][$user["user-increment"]]["mail"] = strtolower($mail);
	$user["user"][$user["user-increment"]]["registrationDate"] =  time();
	$user["user"][$user["user-increment"]]["passwd"] = hash("sha256",$passwd.$user["user"][$user["user-increment"]]["registrationDate"]);
	$user["user"][$user["user-increment"]]["role"] = (($tmpFirstUser) ? "admin" : $configDB["defaultUserRole"]);
	$user["user"][$user["user-increment"]]["active"] = ($configDB["userNeedsConfirmation"]) ? 0 : 1;
	$user["user"][$user["user-increment"]]["lastLogin"] = "";
	$user["user"][$user["user-increment"]]["color"] = getUserColors()["freeColors"][0];
	$file->writeClose(json_encode($user, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
	$return["status"] = "success";
	$return["code"] = ($user["user"][$user["user-increment"]]["active"] == 1) ? 0 : 3;
	$return["string"] = "Registration succeeded";
	return $return;
}
function userRegister ( $ name , $ mail , $ passwd ) { global $ conf ; $ tmpFirstUser = false ; $ json = file_get_contents ( $ conf [ " dir " ] [ " data " ] . " /config.json " ) ; $ configDB = json_decode ( $ json , true ) ; $ userFile = $ conf [ " dir " ] [ " data " ] . " /users.json " ; if ( ! $ mail || ! $ passwd || ( ! filter_var ( $ mail , FILTER_VALIDATE_EMAIL ) ) || ! $ name ) { $ return [ " status " ] = " fail " ; $ return [ " code " ] = 1 ; $ return [ " string " ] = " Fill out all fields " ; return $ return ; } if ( ! file_exists ( $ userFile ) ) { $ tmp [ " user-increment " ] = 0 ; $ tmp [ " user " ] = array ( ) ; $ tmpFirstUser = true ; file_put_contents ( $ userFile , json_encode ( $ tmp , JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ) ) ; } $ file = new sharedFile ( $ userFile ) ; $ json = $ file -> read ( ) ; $ user = json_decode ( $ json , true ) ; foreach ( $ user [ " user " ] as $ k => $ v ) { if ( $ v [ " mail " ] == strtolower ( $ _REQUEST [ " mail " ] ) ) { $ return [ " status " ] = " fail " ; $ return [ " code " ] = 2 ; $ return [ " string " ] = " Already registered " ; $ file -> close ( ) ; return $ return ; } } $ user [ " user-increment " ] ++ ; $ user [ " user " ] [ $ user [ " user-increment " ] ] [ " name " ] = $ name ; $ user [ " user " ] [ $ user [ " user-increment " ] ] [ " mail " ] = strtolower ( $ mail ) ; $ user [ " user " ] [ $ user [ " user-increment " ] ] [ " registrationDate " ] = time ( ) ; $ user [ " user " ] [ $ user [ " user-increment " ] ] [ " passwd " ] = hash ( " sha256 " , $ passwd . $ user [ " user " ] [ $ user [ " user-increment " ] ] [ " registrationDate " ] ) ; $ user [ " user " ] [ $ user [ " user-increment " ] ] [ " role " ] = ( ( $ tmpFirstUser ) ? " admin " : $ configDB [ " defaultUserRole " ] ) ; $ user [ " user " ] [ $ user [ " user-increment " ] ] [ " active " ] = ( $ configDB [ " userNeedsConfirmation " ] ) ? 0 : 1 ; $ user [ " user " ] [ $ user [ " user-increment " ] ] [ " lastLogin " ] = " " ; $ user [ " user " ] [ $ user [ " user-increment " ] ] [ " color " ] = getUserColors ( ) [ " freeColors " ] [ 0 ] ; $ file -> writeClose ( json_encode ( $ user , JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ) ) ; $ return [ " status " ] = " success " ; $ return [ " code " ] = ( $ user [ " user " ] [ $ user [ " user-increment " ] ] [ " active " ] == 1 ) ? 0 : 3 ; $ return [ " string " ] = " Registration succeeded " ; return $ return ; }
@param $name
 @param $mail
 @param $passwd
 @return mixed
@param $name @param $mail @param $passwd @return mixed