Skip to content

Commit

Permalink
use configuration for login details, and give nice error when not set
Browse files Browse the repository at this point in the history
  • Loading branch information
michield committed Mar 1, 2013
1 parent 63097bb commit b965c4e
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions plugins/restapi_test/main.php
Expand Up @@ -12,6 +12,15 @@

$url = apiUrl( $website );

$login = getConfig('restapi_test_login');
$password = getConfig('restapi_test_password');

if (empty($login)) {
print Error(s('Please configure the login details in the settings page'));
return;
}


?>

<html>
Expand All @@ -24,21 +33,8 @@
//Get the loginname and password!
$id = $_SESSION["logindetails"]["id"];

$dbhost = $GLOBALS['database_host'];
$dbuser = $GLOBALS['database_user'];
$dbpass = $GLOBALS['database_password'];
$dbname = $GLOBALS['database_name'];
$db = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$sql = "SELECT * FROM " . $GLOBALS['table_prefix'] . "admin WHERE id=:id;";
$stmt = $db->prepare($sql);
$stmt->execute( array( ':id' => $id ) );
$result = $stmt->fetchAll(PDO::FETCH_OBJ);
$admin = $result[0];

$api = new phpList_RESTAPI_Helper( $url );
$result = $api->login( $admin->loginname, $admin->password );
$result = $api->login( $login, $password );
if ($result->status != 'success'){
echo $result->data->message;
return;
Expand Down Expand Up @@ -371,4 +367,4 @@ function apiUrl( $website ){

}

?>
?>

0 comments on commit b965c4e

Please sign in to comment.