".\PHP_EOL;
$lines = preg_split(
'/\r\n|\n|\r/'
,trim( file_get_contents( $UserFile ) )
);
$theMail="";
foreach( $lines as $line ) {
if ( empty( $line ) ) continue;
//echo "search:$line
";
list( $anHash ,$anMail ) = explode( ':' ,$line);
if ( $anHash == $mailId ) {
$theMail = $anMail;
break;
}
}
}
return $theMail;
}
// \darkauth\db\DwAccount::getHashMailFor( $mail );
public function getHashMailFor( string $mail ) : string {
$UserFile = \darkauth\db\DwAccount::getUserIdFilePath();
if ( is_file( $UserFile ) ) {
//echo "search:$passFile
".\PHP_EOL;
$lines = preg_split(
'/\r\n|\n|\r/'
,trim( file_get_contents( $UserFile ) )
);
$theHash="";
foreach( $lines as $line ) {
if ( empty( $line ) ) continue;
//echo "search:$line
";
list( $anHash ,$anMail ) = explode( ':' ,$line);
if ( $anMail == $mail ) {
$theHash = $anHash;
break;
}
}
}
return $theHash;
}
// \darkauth\db\DwAccount::removeAccountFromMail( $mail );
function removeAccountFromMail( string $mail ) : void {
$UserFile = \darkauth\db\DwAccount::getUserIdFilePath();
$PassFile = \darkauth\db\DwAccount::getUserPassFilePath();
if ( is_file( $UserFile ) && is_file( $PassFile ) ) {
$lines = preg_split( '/\r\n|\n|\r/' ,trim( file_get_contents( $UserFile ) ) );
$newUserFileContent = "";
foreach( $lines as $line ) {
if ( empty( $line ) ) continue;
list( $anHash ,$anMail ) = explode( ':' ,$line);
if ( $anMail == $mail )
continue;
else
$newUserFileContent.=$line.\PHP_EOL;
}
file_put_contents( $UserFile ,$newUserFileContent );
$lines = preg_split( '/\r\n|\n|\r/' ,trim( file_get_contents( $PassFile ) ) );
$newPassFileContent="";
foreach( $lines as $line ) {
if ( empty( $line ) ) continue;
//echo "search:$line
";
list( $anMail ,$anUser, $anPass ,$anPresent ) = explode( ':' ,$line);
if ( $anMail == $mail )
continue;
else
$newPassFileContent.=$line.\PHP_EOL;
}
file_put_contents( $PassFile ,$newPassFileContent );
}
}
// \darkauth\db\DwAccount::addAccount( $uuid ,$mail ,$apacheUser ,$apachePass ,$userPresent );
function addAccount(
string $uuid
,string $mail
,string $apacheUser
,string $apachePass
,string $userPresent
) : void {
$UserFile = \darkauth\db\DwAccount::getUserIdFilePath();
$PassFile = \darkauth\db\DwAccount::getUserPassFilePath();
$ownerMail = \darkauth\db\DwAccount::getMailSender();
$resource = \fopen( $UserFile ,'a' );
$toWrite=implode( ':' ,array( $uuid ,$mail ) ).\PHP_EOL;
if ( \fwrite( $resource, $toWrite, strlen( $toWrite ) ) ) {
echo "Passe 1/2 du compte enregistrer.
".\PHP_EOL;
} else
echo "Désolé, l'enregistrement a échoué, contactez-nous.
".\PHP_EOL;
\fflush($resource);
\fclose($resource);
$resource = \fopen( $PassFile ,'a' );
$toWrite=implode( ':' ,array( $mail,$apacheUser ,$apachePass,$userPresent ) ).\PHP_EOL;
if ( fwrite( $resource, $toWrite, strlen( $toWrite ) ) ) {
echo "Passe 2/2 du compte enregistrer.
".\PHP_EOL;
} else
echo "Désolé, l'enregistrement a échoué, contactez-nous.
".\PHP_EOL;
\fflush($resource);
\fclose($resource);
}
// \darkauth\db\DwAccount::getUserFor( $mail );
static function getUserFor( string $mail ) : ?array {
$passFile = \darkauth\db\DwAccount::getUserPassFilePath();
$theUser=null;
if ( ! is_file( $passFile ) ) {
if ( $mail == \darkauth\db\DwAccount::getMailSender() )
$theUser = array( $mail ,"anEmptyPass" ,"Administrateur Du Site" );
} else {
//echo "search:$passFile
".\PHP_EOL;
$lines = preg_split( '/\r\n|\n|\r/' ,trim( file_get_contents( $passFile ) ) );
foreach( $lines as $line ) {
if ( empty( $line ) ) continue;
//echo "search:$line
";
list($anMail ,$anUser, $anPass ,$anPresent ) = explode( ':' ,$line);
if ( $anMail == $mail ) {
$theUser = array( $anUser ,$anPass ,$anPresent );
break;
}
}
}
return $theUser;
}
// \darkauth\db\DwAccount::getUserFor( $passFile ,$user );
function searchUserInPasswd( string $passFile ,string $user ) : bool {
$found=false;
if ( is_file( $passFile ) ) {
//echo "search:$passFile
".\PHP_EOL;
$lines = preg_split( '/\r\n|\n|\r/' ,trim( file_get_contents( $passFile ) ) );
foreach( $lines as $line ) {
if ( empty( $line ) ) continue;
//echo "search:$line
";
list($anUser, $anHash) = explode( ':' ,$line);
//echo "search:$anUser
";
if ( $user == $anUser ) {
$found=true;
break;
}
}
}
return $found;
}
}
?>