Update website
This commit is contained in:
parent
4413528994
commit
1d90fbf296
6865 changed files with 1091082 additions and 0 deletions
2
lib/.htaccess
Normal file
2
lib/.htaccess
Normal file
|
@ -0,0 +1,2 @@
|
|||
Order Deny, Allow
|
||||
Deny from all
|
87
lib/auth.php
Normal file
87
lib/auth.php
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
require_once dirname(__FILE__)."/config/config.php";
|
||||
|
||||
function check_auth() {
|
||||
global $oauth_id, $oauth_secret, $oauth_callback;
|
||||
|
||||
if (isset($_SESSION['allowed_admin']) && $_SESSION['allowed_admin'] == true) {
|
||||
if (isset($_GET['logout']) && $_GET['logout'] == '1') {
|
||||
unset($_SESSION['allowed_admin']);
|
||||
}
|
||||
else if (isset($_SESSION['origin_url'])) {
|
||||
header('Location: '.$_SESSION['origin_url']);
|
||||
unset($_SESSION['origin_url']);
|
||||
exit;
|
||||
}
|
||||
else return;
|
||||
}
|
||||
|
||||
$provider = new Stevenmaguire\OAuth2\Client\Provider\Bitbucket([
|
||||
'clientId' => $oauth_id,
|
||||
'clientSecret' => $oauth_secret,
|
||||
'redirectUri' => $oauth_callback
|
||||
]);
|
||||
|
||||
|
||||
if (!isset($_GET['code'])) {
|
||||
|
||||
$_SESSION['origin_url'] = $_SERVER['REQUEST_URI'];
|
||||
|
||||
if (isset($_GET['o'])) {
|
||||
$_SESSION['origin_url'] = urldecode($_GET['o']);
|
||||
}
|
||||
|
||||
// If we don't have an authorization code then get one
|
||||
$authUrl = $provider->getAuthorizationUrl();
|
||||
$_SESSION['oauth2state'] = $provider->getState();
|
||||
header('Location: '.$authUrl);
|
||||
exit;
|
||||
|
||||
// Check given state against previously stored one to mitigate CSRF attack
|
||||
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
|
||||
|
||||
unset($_SESSION['oauth2state']);
|
||||
exit('Invalid state');
|
||||
|
||||
} else {
|
||||
|
||||
// Try to get an access token (using the authorization code grant)
|
||||
$token = $provider->getAccessToken('authorization_code', [
|
||||
'code' => $_GET['code']
|
||||
]);
|
||||
$_SESSION["web-key"] = $token;
|
||||
|
||||
// Optional: Now you have a token you can look up a users profile data
|
||||
try {
|
||||
|
||||
// We got an access token, let's now get the user's details
|
||||
$user = $provider->getResourceOwner($token);
|
||||
|
||||
if ($user->getUsername() != "glavaux") {
|
||||
$_SESSION["allowed_admin"] = false;
|
||||
exit('Invalid user');
|
||||
}
|
||||
$_SESSION["allowed_admin"] = true;
|
||||
|
||||
// Use these details to create a new profile
|
||||
// printf('Hello %s!', $user->getUsername());
|
||||
if (isset($_SESSION['origin_url']) && !empty($_SESSION['origin_url'])) {
|
||||
header('Location: '.$_SESSION['origin_url']);
|
||||
unset($_SESSION['origin_url']);
|
||||
exit;
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
||||
// Failed to get user details
|
||||
exit('Oh dear...');
|
||||
}
|
||||
|
||||
// Use this to interact with an API on the users behalf
|
||||
// echo $token->getToken();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
check_auth();
|
22
lib/config.php.sample
Normal file
22
lib/config.php.sample
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
//ini_set('display_errors','1');
|
||||
//error_reporting(E_ALL);
|
||||
|
||||
$iap_debug = true;
|
||||
|
||||
$iap_root = "http://localhost:8001/";
|
||||
|
||||
$ADS_TOKEN = "";
|
||||
|
||||
$connectionParams = array(
|
||||
'dbname' => 'mydb',
|
||||
'user' => 'user',
|
||||
'password' => 'secret',
|
||||
'host' => 'localhost',
|
||||
'driver' => 'pdo_mysql',
|
||||
);
|
||||
|
||||
$oauth_id="";
|
||||
$oauth_secret="";
|
||||
$oauth_callback="";
|
231
lib/schema.php
Normal file
231
lib/schema.php
Normal file
|
@ -0,0 +1,231 @@
|
|||
<?php
|
||||
|
||||
require_once dirname(__FILE__).'/../vendor/autoload.php';
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
|
||||
class PersoSchema extends Schema
|
||||
{
|
||||
/**
|
||||
* @var Connection
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
private $options;
|
||||
|
||||
private $sm;
|
||||
|
||||
private $publiTable;
|
||||
|
||||
private $publiHistory;
|
||||
|
||||
private $currentTime;
|
||||
|
||||
private $confirmMessage;
|
||||
|
||||
/**
|
||||
* @param array $options the options could be use to make the table names configurable
|
||||
*/
|
||||
public function __construct(array $options = [], Connection $connection = null)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
$schemaConfig = null === $connection ? null : $connection->getSchemaManager()->createSchemaConfig();
|
||||
|
||||
parent::__construct([], [], $schemaConfig);
|
||||
|
||||
$this->options = $options;
|
||||
|
||||
$this->sm = $connection->getSchemaManager();
|
||||
|
||||
$this->addPublications();
|
||||
|
||||
$this->currentTime = new DateTimeImmutable();
|
||||
$this->addCitationHistory();
|
||||
$this->addConfirmMessage();
|
||||
}
|
||||
|
||||
public function migrate()
|
||||
{
|
||||
$oldSchema = $this->sm->createSchema();
|
||||
|
||||
$db_platform = $this->connection->getDatabasePlatform();
|
||||
foreach ($oldSchema->getMigrateToSql($this, $db_platform) as $sql) {
|
||||
$this->connection->executeStatement($sql);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function addPublications()
|
||||
{
|
||||
$publiTable = $this->createTable('publications');
|
||||
$publiTable->addColumn('id', 'integer', ['unsigned' => true, 'customSchemaOptions' => ['unique' => true]]);
|
||||
$publiTable->addColumn('arxiv', 'string', ['length' => 20, 'notnull' => false]);
|
||||
$publiTable->addColumn('owned', 'boolean');
|
||||
$publiTable->addColumn('doi', 'string', ['length' => 100, 'notnull' => false]);
|
||||
$publiTable->addColumn('ads', 'string', ['length' => 100]);
|
||||
$publiTable->addColumn('ads_docid', 'integer', ['unsigned' => true]);
|
||||
$publiTable->addColumn('title', 'string', ['length' => 200]);
|
||||
$publiTable->addColumn('authors', Types::JSON);
|
||||
$publiTable->addColumn('citation_count', Types::INTEGER, ['unsigned' => true]);
|
||||
$publiTable->addColumn('year', Types::INTEGER, ['unsigned' => true]);
|
||||
$publiTable->addColumn('date', Types::DATETIME_IMMUTABLE);
|
||||
$publiTable->addColumn('journal', Types::STRING, ['notnull' => false, 'length' => 256]);
|
||||
$publiTable->addColumn('page', Types::STRING, ['notnull' => false, 'length' => 24]);
|
||||
$publiTable->addColumn('volume', Types::STRING, ['notnull' => false, 'length' => 24]);
|
||||
$publiTable->setPrimaryKey(['id']);
|
||||
// $schema->createSequence("publi_table_seq");
|
||||
}
|
||||
|
||||
public function addConfirmMessage()
|
||||
{
|
||||
$confirmMessage = $this->createTable('confirm_message');
|
||||
$confirmMessage->addColumn('id', Types::INTEGER, ['unsigned' => true]);
|
||||
$confirmMessage->addColumn('token', Types::STRING, ['length' => 24, 'notnull' => true]);
|
||||
$confirmMessage->addColumn('sender_name', Types::STRING, ['length' => 80]);
|
||||
$confirmMessage->addColumn('sender_email', Types::STRING, ['length' => 80]);
|
||||
$confirmMessage->addColumn('body', Types::STRING, ['length' => 1000]);
|
||||
}
|
||||
|
||||
public function addCitationHistory()
|
||||
{
|
||||
$publiHistory = $this->createTable('citation_history');
|
||||
$publiHistory->addColumn('id', Types::INTEGER, ['unsigned' => true]);
|
||||
$publiHistory->addColumn('date', Types::DATETIME_IMMUTABLE);
|
||||
$publiHistory->addColumn('citation_count', Types::INTEGER, ['unsigned' => true]);
|
||||
}
|
||||
|
||||
public function insertPublication(array $doc, bool $update = false)
|
||||
{
|
||||
$data = [
|
||||
'id' => intval($doc['id']),
|
||||
'ads' => $doc['bibcode'],
|
||||
'title' => $doc['title'][0],
|
||||
'ads_docid' => intval($doc['id']),
|
||||
'authors' => $doc['author'],
|
||||
'citation_count' => intval($doc['citation_count']),
|
||||
'year' => intval($doc['year']),
|
||||
'date' => new DateTimeImmutable($doc['date']),
|
||||
'journal' => $doc['pub'] ?? null,
|
||||
'page' => $doc['page'][0] ?? null,
|
||||
'volume' => $doc['volume'] ?? null,
|
||||
];
|
||||
// echo "Inserting " . json_encode($doc);
|
||||
if (!array_key_exists('doi', $doc) || count($doc['doi']) == 0) {
|
||||
$doi = null;
|
||||
} else {
|
||||
$data['doi'] = $doc['doi'][0];
|
||||
}
|
||||
if (array_key_exists('identifier', $doc)) {
|
||||
foreach ($doc['identifier'] as $pubid) {
|
||||
if (str_starts_with($pubid, 'arXiv:')) {
|
||||
$data['arxiv'] = substr($pubid, 6);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$types = ['authors' => Types::JSON, 'date' => Types::DATETIME_IMMUTABLE];
|
||||
if ($update) {
|
||||
$this->connection->update(
|
||||
'publications',
|
||||
$data,
|
||||
['id' => $data['id']],
|
||||
$types
|
||||
);
|
||||
} else {
|
||||
$data['owned'] = true;
|
||||
$this->connection->insert(
|
||||
'publications',
|
||||
$data,
|
||||
$types
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function refreshHistory(array $doc)
|
||||
{
|
||||
$data = [
|
||||
'id' => intval($doc['id']),
|
||||
'date' => $this->currentTime,
|
||||
'citation_count' => intval($doc['citation_count']),
|
||||
];
|
||||
$types = ['date' => Types::DATETIME_IMMUTABLE];
|
||||
$this->connection->insert(
|
||||
'citation_history',
|
||||
$data,
|
||||
$types
|
||||
);
|
||||
}
|
||||
|
||||
public function submitMessage(string $name, string $email, string $message)
|
||||
{
|
||||
$data = [
|
||||
'sender_name' => $name,
|
||||
'sender_email' => $email,
|
||||
'message' => $message,
|
||||
'token' => $mytoken,
|
||||
];
|
||||
$this->connection->insert(
|
||||
'confirm_message',
|
||||
$data
|
||||
);
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
|
||||
try {
|
||||
// Server settings
|
||||
$mail->isSMTP(); // Send using SMTP
|
||||
$mail->Host = 'smtp.iap.fr'; // Set the SMTP server to send through
|
||||
$mail->Port = 587; // TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
|
||||
|
||||
// Recipients
|
||||
$mail->setFrom('@iap.fr', 'Web Mailer');
|
||||
$mail->addAddress($email, 'submitter'); // Add a recipient
|
||||
|
||||
// Content
|
||||
$mail->isHTML(false); // Set email format to HTML
|
||||
$mail->Subject = 'Guilhem website: confirm message';
|
||||
$mail->Body = $confirm_body;
|
||||
|
||||
$mail->send();
|
||||
$result_summary = 'Successfully sent';
|
||||
$result = 'Message has been sent';
|
||||
} catch (Exception $e) {
|
||||
$result_summary = 'Error sending message';
|
||||
$result = "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
|
||||
}
|
||||
}
|
||||
|
||||
public function confirmMessage(string $token)
|
||||
{
|
||||
// Create an instance; passing `true` enables exceptions
|
||||
$mail = new PHPMailer(true);
|
||||
$tpl = $m->loadTemplate('email_sent');
|
||||
|
||||
try {
|
||||
// Server settings
|
||||
$mail->isSMTP(); // Send using SMTP
|
||||
$mail->Host = 'smtp.iap.fr'; // Set the SMTP server to send through
|
||||
$mail->Port = 587; // TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
|
||||
|
||||
// Recipients
|
||||
$mail->setFrom('guilhem.lavaux@iap.fr', 'Web Mailer');
|
||||
$mail->addAddress('guilhem.lavaux@iap.fr', 'Guilhem Lavaux'); // Add a recipient
|
||||
$mail->addReplyTo($email, $name);
|
||||
|
||||
// Content
|
||||
$mail->isHTML(false); // Set email format to HTML
|
||||
$mail->Subject = 'Guilhem website: Message from '.$name;
|
||||
$mail->Body = $message;
|
||||
|
||||
$mail->send();
|
||||
$result_summary = 'Successfully sent';
|
||||
$result = 'Message has been sent';
|
||||
} catch (Exception $e) {
|
||||
$result_summary = 'Error sending message';
|
||||
$result = "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue