Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Blacklist class and BlacklistedEmailInfo (API 1)
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace phpListRestapi; | ||
|
||
defined('PHPLISTINIT') || die; | ||
|
||
class Blacklist | ||
{ | ||
/** | ||
* Check if a email or user (by email) is in blacklist and the reason if exists. | ||
* @param string $email Email to check in blacklist | ||
*/ | ||
|
||
/** | ||
* Check if a email or user (by email) is in blacklist and the reason if exists. | ||
* | ||
* <p><strong>Parameters:</strong><br/> | ||
* [*email] {string} Email to check in blacklist<br/> | ||
* <p><strong>Returns:</strong><br/> | ||
* Type (whitelist, blacklist) and the reason if is in blacklisted. | ||
* </p> | ||
*/ | ||
public static function blacklistedEmailInfo($email=''){ | ||
if($email == ''){ | ||
$email = $_REQUEST['email']; | ||
} | ||
if ($email == '') { | ||
Response::outputErrorMessage('Email param is empty'); | ||
} | ||
$response = new Response(); | ||
|
||
$sql = "SELECT ". $GLOBALS['tables']['user_blacklist'] . ".email, added, `data` as reason FROM " | ||
. $GLOBALS['tables']['user_blacklist'] . " INNER JOIN ".$GLOBALS['tables']['user_blacklist_data'] | ||
. " ON ".$GLOBALS['tables']['user_blacklist'] . ".email=".$GLOBALS['tables']['user_blacklist_data'] .".email" | ||
." WHERE ".$GLOBALS['tables']['user_blacklist'].".email = :email" | ||
. " | ||
UNION | ||
( | ||
SELECT email, null, 'Blacklist by profile user' | ||
FROM " . $GLOBALS['tables']['user'] . " WHERE blacklisted=1 AND email = :email | ||
) | ||
LIMIT 1 | ||
" | ||
; | ||
try { | ||
$db = PDO::getConnection(); | ||
$stmt = $db->prepare($sql); | ||
$stmt->bindParam('email', $email, PDO::PARAM_STR); | ||
$stmt->execute(); | ||
$result = $stmt->fetch(PDO::FETCH_OBJ); // only first coincidence. | ||
if($result){ | ||
$response->setData('blacklist', $result); // type attribute == 'blacklist' | ||
} else { | ||
$result = array( | ||
'email' => $email | ||
); | ||
$response->setData('whitelist', $result); // type attribute == 'whitelist' | ||
} | ||
$db = null; | ||
$response->output(); | ||
} catch(\PDOException $e) { | ||
Response::outputError($e); | ||
} | ||
die(0); | ||
} | ||
|
||
|
||
} |