Skip to content
Snippets Groups Projects
Commit c10ecd68 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Implemented user search in Join Request modal

parent 9762c6ef
No related branches found
No related tags found
No related merge requests found
Showing with 611 additions and 60 deletions
<?php
/* ----------------------------------------------------------------------------
* INAF - National Institute for Astrophysics
* IRA - Radioastronomical Institute - Bologna
* OATS - Astronomical Observatory - Trieste
* ----------------------------------------------------------------------------
*
* Copyright (C) 2016 Istituto Nazionale di Astrofisica
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License Version 3 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
namespace RAP;
class CallbackHandler {
/**
* returns null if the callback URL is not listed in configuration file.
*/
public static function getCallbackTitle($callbackURL) {
if ($callbackURL === null) {
return "Account Management";
}
global $CALLBACKS;
foreach ($CALLBACKS as $callback) {
if ($callback['url'] === $callbackURL) {
return $callback['title'];
}
}
throw new \Exception("Unauthorized callback URL");
}
public static function manageLoginRedirect($user) {
global $BASE_PATH, $session;
if (isset($session->callback) && $session->callback !== null) {
// External login using token
$token = Util::createNewToken();
DAO::get()->insertTokenData($token, $user->id);
header('Location: ' . $session->callback . '?token=' . $token);
} else {
// Login in session
$session->user = $user;
$session->save();
// Return to index
header('Location: ' . $BASE_PATH);
}
}
}
...@@ -28,11 +28,11 @@ abstract class DAO { ...@@ -28,11 +28,11 @@ abstract class DAO {
public abstract function getDBHandler(); public abstract function getDBHandler();
public abstract function insertTokenData($token, $data); public abstract function createLoginToken($token, $userId);
public abstract function findTokenData($token); public abstract function findLoginToken($token);
public abstract function deleteToken($token); public abstract function deleteLoginToken($token);
/** /**
* Return the new identity ID. * Return the new identity ID.
...@@ -54,8 +54,12 @@ abstract class DAO { ...@@ -54,8 +54,12 @@ abstract class DAO {
*/ */
public abstract function findUserByIdentity($type, $identifier, $dbIdentifier); public abstract function findUserByIdentity($type, $identifier, $dbIdentifier);
public abstract function searchUser($searchText);
public abstract function addEmailToUser($email, $userId); public abstract function addEmailToUser($email, $userId);
public abstract function createJoinRequest($token, $applicantUserId, $targetUserId);
public $config; public $config;
public function __construct($config) { public function __construct($config) {
...@@ -63,12 +67,13 @@ abstract class DAO { ...@@ -63,12 +67,13 @@ abstract class DAO {
} }
public static function get() { public static function get() {
$config = parse_ini_file(ROOT . '/config.ini', true); global $DATABASE;
switch ($config['dbtype']) {
switch ($DATABASE['dbtype']) {
case 'MySQL': case 'MySQL':
return new MySQLDAO($config); return new MySQLDAO($DATABASE);
default: default:
throw new \Exception($config['dbtype'] . ' not supported yet'); throw new \Exception($DATABASE['dbtype'] . ' not supported yet');
} }
} }
......
...@@ -43,7 +43,7 @@ class Identity { ...@@ -43,7 +43,7 @@ class Identity {
/** /**
* One of the types specified above. Mandatory field. * One of the types specified above. Mandatory field.
*/ */
private $type; public $type;
/** /**
* Data related to specific account type (shibboleth persistent id, facebook id, etc, ...). Mandatory field. * Data related to specific account type (shibboleth persistent id, facebook id, etc, ...). Mandatory field.
...@@ -101,8 +101,4 @@ class Identity { ...@@ -101,8 +101,4 @@ class Identity {
$this->type = $userType; $this->type = $userType;
} }
public function getType() {
return $this->type;
}
} }
...@@ -33,16 +33,16 @@ class MySQLDAO extends DAO { ...@@ -33,16 +33,16 @@ class MySQLDAO extends DAO {
return new PDO($connectionString, $this->config['username'], $this->config['password']); return new PDO($connectionString, $this->config['username'], $this->config['password']);
} }
public function insertTokenData($token, $data) { public function createLoginToken($token, $userId) {
global $log; global $log;
$dbh = $this->getDBHandler(); $dbh = $this->getDBHandler();
$stmt = $dbh->prepare("INSERT INTO token (token, data) VALUES(:token, :data)"); $stmt = $dbh->prepare("INSERT INTO login_token (token, data) VALUES(:token, :data)");
$params = array( $params = array(
':token' => $token, ':token' => $token,
':data' => $data ':data' => $userId
); );
if ($stmt->execute($params)) { if ($stmt->execute($params)) {
...@@ -53,11 +53,11 @@ class MySQLDAO extends DAO { ...@@ -53,11 +53,11 @@ class MySQLDAO extends DAO {
} }
} }
public function findTokenData($token) { public function findLoginToken($token) {
$dbh = $this->getDBHandler(); $dbh = $this->getDBHandler();
$stmt = $dbh->prepare("SELECT data FROM token WHERE token = :token AND CURRENT_TIMESTAMP < TIMESTAMPADD(MINUTE,1,creation_time)"); $stmt = $dbh->prepare("SELECT data FROM login_token WHERE token = :token AND CURRENT_TIMESTAMP < TIMESTAMPADD(MINUTE,1,creation_time)");
$stmt->bindParam(':token', $token); $stmt->bindParam(':token', $token);
$stmt->execute(); $stmt->execute();
...@@ -69,11 +69,11 @@ class MySQLDAO extends DAO { ...@@ -69,11 +69,11 @@ class MySQLDAO extends DAO {
return null; return null;
} }
public function deleteToken($token) { public function deleteLoginToken($token) {
$dbh = $this->getDBHandler(); $dbh = $this->getDBHandler();
$stmt = $dbh->prepare("DELETE FROM token WHERE token = :token"); $stmt = $dbh->prepare("DELETE FROM login_token WHERE token = :token");
$stmt->bindParam(':token', $token); $stmt->bindParam(':token', $token);
$stmt->execute(); $stmt->execute();
} }
...@@ -86,7 +86,7 @@ class MySQLDAO extends DAO { ...@@ -86,7 +86,7 @@ class MySQLDAO extends DAO {
. " VALUES(:user_id, :type, :email, :name, :surname, :institution, :username, :local_db_id, :typed_id, :eppn)"); . " VALUES(:user_id, :type, :email, :name, :surname, :institution, :username, :local_db_id, :typed_id, :eppn)");
$stmt->bindParam(':user_id', $userId); $stmt->bindParam(':user_id', $userId);
$stmt->bindParam(':type', $identity->getType()); $stmt->bindParam(':type', $identity->type);
$stmt->bindParam(':email', $identity->email); $stmt->bindParam(':email', $identity->email);
$stmt->bindParam(':name', $identity->name); $stmt->bindParam(':name', $identity->name);
$stmt->bindParam(':surname', $identity->surname); $stmt->bindParam(':surname', $identity->surname);
...@@ -111,6 +111,23 @@ class MySQLDAO extends DAO { ...@@ -111,6 +111,23 @@ class MySQLDAO extends DAO {
return $dbh->lastInsertId(); return $dbh->lastInsertId();
} }
private function getIdentityByRow($row) {
$identity = new Identity($row['type']);
$identity->id = $row['id'];
$identity->typedId = $row['typed_id'];
$identity->email = $row['email'];
$identity->localDBId = $row['local_db_id'];
$identity->name = $row['name'];
$identity->surname = $row['surname'];
$identity->institution = $row['institution'];
$identity->username = $row['username'];
$identity->eppn = $row['eppn'];
return $identity;
}
public function findUserById($userId) { public function findUserById($userId) {
$dbh = $this->getDBHandler(); $dbh = $this->getDBHandler();
...@@ -121,20 +138,16 @@ class MySQLDAO extends DAO { ...@@ -121,20 +138,16 @@ class MySQLDAO extends DAO {
$stmt->bindParam(':user_id', $userId); $stmt->bindParam(':user_id', $userId);
$stmt->execute(); $stmt->execute();
$result = $stmt->fetchAll();
if (count($result) === 0) {
return null;
}
$user = new User(); $user = new User();
$user->id = $userId; $user->id = $userId;
foreach ($stmt->fetchAll() as $row) { foreach ($result as $row) {
$identity = new Identity($row['type']); $identity = $this->getIdentityByRow($row);
$identity->id = $row['id'];
$identity->typedId = $row['typed_id'];
$identity->email = $row['email'];
$identity->localDBId = $row['local_db_id'];
$identity->name = $row['name'];
$identity->surname = $row['surname'];
$identity->institution = $row['institution'];
$identity->username = $row['username'];
$identity->eppn = $row['eppn'];
$user->addIdentity($identity); $user->addIdentity($identity);
} }
...@@ -152,15 +165,25 @@ class MySQLDAO extends DAO { ...@@ -152,15 +165,25 @@ class MySQLDAO extends DAO {
$dbh = $this->getDBHandler(); $dbh = $this->getDBHandler();
$stmt = $dbh->prepare("SELECT user_id FROM identity WHERE type = :type AND typed_id = :typed_id AND local_db_id = :local_db_id"); $query = "SELECT user_id FROM identity WHERE type = :type AND typed_id = :typed_id";
if (isset($dbIdentifier) && $dbIdentifier !== null) {
$query .= " AND local_db_id = :local_db_id";
}
$stmt = $dbh->prepare($query);
$stmt->bindParam(':type', $type); $stmt->bindParam(':type', $type);
$stmt->bindParam(':typed_id', $identifier); $stmt->bindParam(':typed_id', $identifier);
if (isset($dbIdentifier) && $dbIdentifier !== null) {
$stmt->bindParam(':local_db_id', $dbIdentifier); $stmt->bindParam(':local_db_id', $dbIdentifier);
}
$stmt->execute(); $stmt->execute();
$result = $stmt->fetchAll(); $result = $stmt->fetchAll();
global $log;
$log->debug("count = " . count($result));
if (count($result) === 0) { if (count($result) === 0) {
return null; return null;
} }
...@@ -172,6 +195,55 @@ class MySQLDAO extends DAO { ...@@ -172,6 +195,55 @@ class MySQLDAO extends DAO {
return $this->findUserById($userId); return $this->findUserById($userId);
} }
public function searchUser($searchText) {
$dbh = $this->getDBHandler();
// TODO: Add additional email search...
$query = "SELECT `user_id`, `id`, `type`, `typed_id`, `email`, `local_db_id`, `name`, `surname`, `institution`, `username`, `eppn`"
. " FROM identity WHERE `email` LIKE :email OR `name` LIKE :name OR `surname` LIKE :surname";
$stmt = $dbh->prepare($query);
$searchParam = $searchText . '%';
$stmt->bindParam(':email', $searchParam);
$stmt->bindParam(':name', $searchParam);
$stmt->bindParam(':surname', $searchParam);
$stmt->execute();
$userMap = array();
//global $log;
//$log->debug('In searchUser');
foreach ($stmt->fetchAll() as $row) {
//$log->debug($row['user_id']);
$identity = $this->getIdentityByRow($row);
//$log->debug(json_encode($identity));
$userId = $row['user_id'];
if (array_key_exists($userId, $userMap)) {
$user = $userMap[$userId];
} else {
$user = new User();
$user->id = $userId;
$userMap[$userId] = $user;
}
array_push($user->identities, $identity);
}
$users = [];
foreach ($userMap as $userId => $user) {
array_push($users, $user);
}
return $users;
}
public function addEmailToUser($email, $userId) { public function addEmailToUser($email, $userId) {
$dbh = $this->getDBHandler(); $dbh = $this->getDBHandler();
...@@ -183,4 +255,18 @@ class MySQLDAO extends DAO { ...@@ -183,4 +255,18 @@ class MySQLDAO extends DAO {
$stmt->execute(); $stmt->execute();
} }
public function createJoinRequest($token, $applicantUserId, $targetUserId) {
$dbh = $this->getDBHandler();
$stmt = $dbh->prepare("INSERT INTO `join_request`(`token`, `applicant_user_id`, `target_user_id`)"
. " VALUES(:token, :applicant_user_id, :target_user_id)");
$stmt->bindParam(':token', $token);
$stmt->bindParam(':applicant_user_id', $applicantUserId);
$stmt->bindParam(':target_user_id', $targetUserId);
$stmt->execute();
}
} }
...@@ -26,8 +26,10 @@ namespace RAP; ...@@ -26,8 +26,10 @@ namespace RAP;
class SessionData { class SessionData {
public $callback; private $callbackURL;
private $callbackTitle;
public $user; public $user;
public $userSearchResults;
public function save() { public function save() {
$_SESSION['SessionData'] = $this; $_SESSION['SessionData'] = $this;
...@@ -41,4 +43,34 @@ class SessionData { ...@@ -41,4 +43,34 @@ class SessionData {
} }
return $_SESSION['SessionData']; return $_SESSION['SessionData'];
} }
public function setCallbackURL($callbackURL) {
$this->callbackURL = $callbackURL;
$this->callbackTitle = CallbackHandler::getCallbackTitle($callbackURL);
$this->save();
}
public function getCallbackURL() {
return $this->callbackURL;
}
public function getCallbackTitle() {
return $this->callbackTitle;
}
public function searchUser($searchText) {
$users = DAO::get()->searchUser($searchText);
$this->userSearchResults = [];
foreach ($users as $user) {
// this search shouldn't contains the user itself
if ($user->id !== $this->user->id) {
$searchResult = UserSearchResult::buildFromUser($user);
array_push($this->userSearchResults, $searchResult);
}
}
$this->save();
}
} }
...@@ -29,6 +29,7 @@ class TokenHandler { ...@@ -29,6 +29,7 @@ class TokenHandler {
public static function createNewToken($data) { public static function createNewToken($data) {
$token = bin2hex(openssl_random_pseudo_bytes(16)); // http://stackoverflow.com/a/18890309/771431 $token = bin2hex(openssl_random_pseudo_bytes(16)); // http://stackoverflow.com/a/18890309/771431
DAO::get()->insertTokenData($token, $data); DAO::get()->insertTokenData($token, $data);
return $token;
} }
public static function deleteToken($token) { public static function deleteToken($token) {
......
<?php
/* ----------------------------------------------------------------------------
* INAF - National Institute for Astrophysics
* IRA - Radioastronomical Institute - Bologna
* OATS - Astronomical Observatory - Trieste
* ----------------------------------------------------------------------------
*
* Copyright (C) 2016 Istituto Nazionale di Astrofisica
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License Version 3 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
namespace RAP;
class UserSearchResult {
private $userId;
public $userDisplayText;
public static function buildFromUser(User $user) {
$usr = new UserSearchResult();
$usr->userId = $user->id;
$nameAndSurname = null;
$email = null;
$identityTypes = [];
foreach ($user->identities as $identity) {
array_push($identityTypes, $identity->type);
if ($nameAndSurname === null && $identity->name !== null && $identity->surname !== null) {
$nameAndSurname = $identity->name . ' ' . $identity->surname;
}
if ($email === null) {
$email = $identity->email;
}
}
// Building display text string
$displayText = "";
if ($nameAndSurname !== null) {
$displayText .= $nameAndSurname;
} else {
$displayText .= $email;
}
$displayText .= ' (';
$firstIdentity = true;
foreach ($identityTypes as $type) {
if (!$firstIdentity) {
$displayText .= '+';
}
$displayText .= $type;
$firstIdentity = false;
}
$displayText .= ')';
$usr->userDisplayText = $displayText;
return $usr;
}
public function getUserId() {
return $this->userId;
}
}
<?php
/* ----------------------------------------------------------------------------
* INAF - National Institute for Astrophysics
* IRA - Radioastronomical Institute - Bologna
* OATS - Astronomical Observatory - Trieste
* ----------------------------------------------------------------------------
*
* Copyright (C) 2016 Istituto Nazionale di Astrofisica
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License Version 3 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
namespace RAP;
/**
* Utility class
*/
class Util {
public static function createNewToken() {
// Credits: http://stackoverflow.com/a/18890309/771431
return bin2hex(openssl_random_pseudo_bytes(16));
}
}
;connection_string = mysql:host=localhost;dbname=rap"
dbtype = MySQL
hostname = localhost
port = 3306
username = rap
password = ***REMOVED***
dbname = rap
...@@ -31,20 +31,44 @@ $BASE_PATH = $PROTOCOL . $_SERVER['HTTP_HOST'] . $CONTEXT_ROOT; ...@@ -31,20 +31,44 @@ $BASE_PATH = $PROTOCOL . $_SERVER['HTTP_HOST'] . $CONTEXT_ROOT;
$LOG_PATH = ROOT . "/logs/rap-service.log"; $LOG_PATH = ROOT . "/logs/rap-service.log";
$LOG_LEVEL = Monolog\Logger::DEBUG; $LOG_LEVEL = Monolog\Logger::DEBUG;
$PDO = array( $CALLBACKS = [
"connection_string" => "mysql:host=localhost;dbname=rap", array(
"user" => "rap", 'url' => 'http://localhost:8087/grouper',
"password" => "***REMOVED***" 'title' => 'Login to Grouper'
)
];
$DATABASE = array(
'dbtype' => 'MySQL',
'hostname' => 'localhost',
'port' => 3306,
'username' => 'rap',
'password' => '***REMOVED***',
'dbname' => 'rap'
); );
$Google = array( $AUTHENTICATION_METHODS = array(
'eduGAIN' => array(),
'Google' => array(
'id' => "***REMOVED***.apps.googleusercontent.com", 'id' => "***REMOVED***.apps.googleusercontent.com",
'secret' => "***REMOVED***", 'secret' => "***REMOVED***",
'callback' => $BASE_PATH . "/oauth2/google_token.php"); 'callback' => $BASE_PATH . "/oauth2/google_token.php"),
'Facebook' => array(
$Facebook = array(
'id' => "***REMOVED***", 'id' => "***REMOVED***",
'secret' => "***REMOVED***", 'secret' => "***REMOVED***",
'version' => "v2.2", 'version' => "v2.2",
'callback' => $BASE_PATH . "/oauth2/facebook_token.php"); 'callback' => $BASE_PATH . "/oauth2/facebook_token.php"),
'LinkedIn' => array(),
'X.509' => array(),
'Direct' => array(
array(
'name' => 'IA2',
'label' => '',
'logo' => 'ia2-logo-60x60.png',
'description' => 'Use the IA2 logo if you have an IA2 account (provided by IA2 or self-registered)',
'type' => 'ldap',
'ldap_user_scope' => 'ou=custom_users,dc=oats,dc=inaf,dc=it',
'ldap_user_id_field' => 'uid'
)
)
);
/* Chosen v1.7.0 | (c) 2011-2017 by Harvest | MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md */
.chosen-container{position:relative;display:inline-block;vertical-align:middle;font-size:13px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.chosen-container *{box-sizing:border-box}.chosen-container .chosen-drop{position:absolute;top:100%;z-index:1010;width:100%;border:1px solid #aaa;border-top:0;background:#fff;box-shadow:0 4px 5px rgba(0,0,0,.15);clip:rect(0,0,0,0)}.chosen-container.chosen-with-drop .chosen-drop{clip:auto}.chosen-container a{cursor:pointer}.chosen-container .search-choice .group-name,.chosen-container .chosen-single .group-name{margin-right:4px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font-weight:400;color:#999}.chosen-container .search-choice .group-name:after,.chosen-container .chosen-single .group-name:after{content:":";padding-left:2px;vertical-align:top}.chosen-container-single .chosen-single{position:relative;display:block;overflow:hidden;padding:0 0 0 8px;height:25px;border:1px solid #aaa;border-radius:5px;background-color:#fff;background:linear-gradient(#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background-clip:padding-box;box-shadow:0 0 3px #fff inset,0 1px 1px rgba(0,0,0,.1);color:#444;text-decoration:none;white-space:nowrap;line-height:24px}.chosen-container-single .chosen-default{color:#999}.chosen-container-single .chosen-single span{display:block;overflow:hidden;margin-right:26px;text-overflow:ellipsis;white-space:nowrap}.chosen-container-single .chosen-single-with-deselect span{margin-right:38px}.chosen-container-single .chosen-single abbr{position:absolute;top:6px;right:26px;display:block;width:12px;height:12px;background:url(chosen-sprite.png) -42px 1px no-repeat;font-size:1px}.chosen-container-single .chosen-single abbr:hover{background-position:-42px -10px}.chosen-container-single.chosen-disabled .chosen-single abbr:hover{background-position:-42px -10px}.chosen-container-single .chosen-single div{position:absolute;top:0;right:0;display:block;width:18px;height:100%}.chosen-container-single .chosen-single div b{display:block;width:100%;height:100%;background:url(chosen-sprite.png) no-repeat 0 2px}.chosen-container-single .chosen-search{position:relative;z-index:1010;margin:0;padding:3px 4px;white-space:nowrap}.chosen-container-single .chosen-search input[type=text]{margin:1px 0;padding:4px 20px 4px 5px;width:100%;height:auto;outline:0;border:1px solid #aaa;background:url(chosen-sprite.png) no-repeat 100% -20px;font-size:1em;font-family:sans-serif;line-height:normal;border-radius:0}.chosen-container-single .chosen-drop{margin-top:-1px;border-radius:0 0 4px 4px;background-clip:padding-box}.chosen-container-single.chosen-container-single-nosearch .chosen-search{position:absolute;clip:rect(0,0,0,0)}.chosen-container .chosen-results{color:#444;position:relative;overflow-x:hidden;overflow-y:auto;margin:0 4px 4px 0;padding:0 0 0 4px;max-height:240px;-webkit-overflow-scrolling:touch}.chosen-container .chosen-results li{display:none;margin:0;padding:5px 6px;list-style:none;line-height:15px;word-wrap:break-word;-webkit-touch-callout:none}.chosen-container .chosen-results li.active-result{display:list-item;cursor:pointer}.chosen-container .chosen-results li.disabled-result{display:list-item;color:#ccc;cursor:default}.chosen-container .chosen-results li.highlighted{background-color:#3875d7;background-image:linear-gradient(#3875d7 20%,#2a62bc 90%);color:#fff}.chosen-container .chosen-results li.no-results{color:#777;display:list-item;background:#f4f4f4}.chosen-container .chosen-results li.group-result{display:list-item;font-weight:700;cursor:default}.chosen-container .chosen-results li.group-option{padding-left:15px}.chosen-container .chosen-results li em{font-style:normal;text-decoration:underline}.chosen-container-multi .chosen-choices{position:relative;overflow:hidden;margin:0;padding:0 5px;width:100%;height:auto;border:1px solid #aaa;background-color:#fff;background-image:linear-gradient(#eee 1%,#fff 15%);cursor:text}.chosen-container-multi .chosen-choices li{float:left;list-style:none}.chosen-container-multi .chosen-choices li.search-field{margin:0;padding:0;white-space:nowrap}.chosen-container-multi .chosen-choices li.search-field input[type=text]{margin:1px 0;padding:0;height:25px;outline:0;border:0!important;background:transparent!important;box-shadow:none;color:#999;font-size:100%;font-family:sans-serif;line-height:normal;border-radius:0;width:25px}.chosen-container-multi .chosen-choices li.search-choice{position:relative;margin:3px 5px 3px 0;padding:3px 20px 3px 5px;border:1px solid #aaa;max-width:100%;border-radius:3px;background-color:#eee;background-image:linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-size:100% 19px;background-repeat:repeat-x;background-clip:padding-box;box-shadow:0 0 2px #fff inset,0 1px 0 rgba(0,0,0,.05);color:#333;line-height:13px;cursor:default}.chosen-container-multi .chosen-choices li.search-choice span{word-wrap:break-word}.chosen-container-multi .chosen-choices li.search-choice .search-choice-close{position:absolute;top:4px;right:3px;display:block;width:12px;height:12px;background:url(chosen-sprite.png) -42px 1px no-repeat;font-size:1px}.chosen-container-multi .chosen-choices li.search-choice .search-choice-close:hover{background-position:-42px -10px}.chosen-container-multi .chosen-choices li.search-choice-disabled{padding-right:5px;border:1px solid #ccc;background-color:#e4e4e4;background-image:linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);color:#666}.chosen-container-multi .chosen-choices li.search-choice-focus{background:#d4d4d4}.chosen-container-multi .chosen-choices li.search-choice-focus .search-choice-close{background-position:-42px -10px}.chosen-container-multi .chosen-results{margin:0;padding:0}.chosen-container-multi .chosen-drop .result-selected{display:list-item;color:#ccc;cursor:default}.chosen-container-active .chosen-single{border:1px solid #5897fb;box-shadow:0 0 5px rgba(0,0,0,.3)}.chosen-container-active.chosen-with-drop .chosen-single{border:1px solid #aaa;border-bottom-right-radius:0;border-bottom-left-radius:0;background-image:linear-gradient(#eee 20%,#fff 80%);box-shadow:0 1px 0 #fff inset}.chosen-container-active.chosen-with-drop .chosen-single div{border-left:0;background:transparent}.chosen-container-active.chosen-with-drop .chosen-single div b{background-position:-18px 2px}.chosen-container-active .chosen-choices{border:1px solid #5897fb;box-shadow:0 0 5px rgba(0,0,0,.3)}.chosen-container-active .chosen-choices li.search-field input[type=text]{color:#222!important}.chosen-disabled{opacity:.5!important;cursor:default}.chosen-disabled .chosen-single{cursor:default}.chosen-disabled .chosen-choices .search-choice .search-choice-close{cursor:default}.chosen-rtl{text-align:right}.chosen-rtl .chosen-single{overflow:visible;padding:0 8px 0 0}.chosen-rtl .chosen-single span{margin-right:0;margin-left:26px;direction:rtl}.chosen-rtl .chosen-single-with-deselect span{margin-left:38px}.chosen-rtl .chosen-single div{right:auto;left:3px}.chosen-rtl .chosen-single abbr{right:auto;left:26px}.chosen-rtl .chosen-choices li{float:right}.chosen-rtl .chosen-choices li.search-field input[type=text]{direction:rtl}.chosen-rtl .chosen-choices li.search-choice{margin:3px 5px 3px 0;padding:3px 5px 3px 19px}.chosen-rtl .chosen-choices li.search-choice .search-choice-close{right:auto;left:4px}.chosen-rtl.chosen-container-single .chosen-results{margin:0 0 4px 4px;padding:0 4px 0 0}.chosen-rtl .chosen-results li.group-option{padding-right:15px;padding-left:0}.chosen-rtl.chosen-container-active.chosen-with-drop .chosen-single div{border-right:0}.chosen-rtl .chosen-search input[type=text]{padding:4px 5px 4px 20px;background:url(chosen-sprite.png) no-repeat -30px -20px;direction:rtl}.chosen-rtl.chosen-container-single .chosen-single div b{background-position:6px 2px}.chosen-rtl.chosen-container-single.chosen-with-drop .chosen-single div b{background-position:-12px 2px}@media only screen and (-webkit-min-device-pixel-ratio:1.5),only screen and (min-resolution:144dpi),only screen and (min-resolution:1.5dppx){.chosen-rtl .chosen-search input[type=text],.chosen-container-single .chosen-single abbr,.chosen-container-single .chosen-single div b,.chosen-container-single .chosen-search input[type=text],.chosen-container-multi .chosen-choices .search-choice .search-choice-close,.chosen-container .chosen-results-scroll-down span,.chosen-container .chosen-results-scroll-up span{background-image:url(chosen-sprite@2x.png)!important;background-size:52px 37px!important;background-repeat:no-repeat!important}}
\ No newline at end of file
body {
background-color: #eee;
padding-bottom: 150px;
}
@keyframes pulse {
from {
transform: scale(1, 1);
}
to {
transform: scale(1.07, 1.07);
}
}
.home-box {
float: left;
width: 240px;
height: 165px;
padding: 2px;
margin: 10px;
border-radius: 15px;
border: 1px solid #ccc;
background-color: #fff;
padding: 4px 8px 8px 8px;
box-shadow: 0 1px 2px rgba(0,0,0,.1);
}
.home-box .img-wrapper {
width: 100%;
height: 80px;
text-align: center;
display: table;
}
.home-box .img-wrapper a {
display: table-cell;
vertical-align: middle;
}
.home-box .img-wrapper a:hover {
animation-duration: 0.2s;
animation-fill-mode: both;
animation-name: pulse;
animation-timing-function: ease-in;
}
#main-header {
background-image: url('../img/rap-background.jpg');
background-position: center;
background-repeat: repeat-x;
height: 90px;
position: relative;
border-bottom: 1px #9c9c9c solid;
margin-bottom: 20px;
box-shadow: 0 1px 2px rgba(0,0,0,.1);
text-shadow: 0 2px 3px rgba(0,0,0,.6);
}
.credits {
position: absolute;
top: 66px;
bottom: 0;
right: 11px;
left: 0;
text-align: right;
font-size: 12px;
color: #fff;
}
.page-title-wrapper {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
.page-title-wrapper h1 {
color: #fff;
font-weight: bold;
font-size: 42px;
}
#main-footer-wrapper {
position: fixed;
bottom: 0;
right: 0;
left: 0;
background-color: #eee;
}
#main-footer {
color: #666;
border-top: 1px #d4d4d4 solid;
background-color: #f8f8f8;
padding: 5px 0;
}
#footer-credits {
font-size: 13px;
color: #666;
margin-bottom: 8px
}
.callback-title {
margin-top: 0;
font-weight: bold;
color: #24388e;
text-shadow: 0 2px 3px rgba(0,0,0,.35);
}
.panel {
box-shadow: 0 1px 2px rgba(0,0,0,.1);
}
.panel-default {
border-color: #ccc
}
.panel-default > .panel-heading {
background-image: linear-gradient(to bottom,#f5f5f5 0,#ccc 100%);
}
img/ia2-logo-60x60.png

1.79 KiB

img/logo-ia2-small.png

1.41 KiB

img/rap-background.jpg

102 KiB

</div> </div>
<footer id="main-footer-wrapper" class="text-center">
<p id="footer-credits">This software has been adapted by the IA2 team from the Remote Authentication Portal written by Franco Tinarelli at INAF-IRA.</p>
<div id="main-footer">
Powered by
<img src="img/logo-ia2-small.png" alt="logo IA2" />
<a href="http://www.ia2.inaf.it/" target="blank_">IA2</a>
</div>
</footer>
</body> </body>
</html> </html>
<?php
/**
* Front Controller using http://flightphp.com/
* In all these calls user session must exist, so we have to start it at the
* beginning using the startSession() function.
*/
//
function setCallback() {
global $session;
$callback = Flight::request()->data['callback'];
$session->setCallbackURL(isset($callback) ? $callback : null);
}
Flight::route('/', function() {
startSession();
setCallback();
global $session, $AUTHENTICATION_METHODS;
Flight::render('index.php', array('title' => 'RAP',
'session' => $session, 'auth' => $AUTHENTICATION_METHODS));
});
Flight::route('GET /logout', function() {
startSession();
session_destroy();
Flight::redirect('/');
});
Flight::route('/google', function() {
startSession();
Flight::redirect('/oauth2/google_token.php');
});
Flight::route('/facebook', function() {
startSession();
Flight::redirect('/oauth2/facebook_login.php');
});
<?php
/**
* REST backend for JavaScript code.
*/
//
function checkSession() {
startSession();
global $session;
if ($session->user === null) {
http_response_code(401);
die("You must be registered to perform this action");
}
}
Flight::route('GET /user', function() {
checkSession();
global $session;
$searchText = Flight::request()->query['search'];
$session->searchUser($searchText);
$jsRes = [];
foreach ($session->userSearchResults as $searchResult) {
array_push($jsRes, $searchResult->userDisplayText);
}
echo json_encode($jsRes);
});
Flight::route('POST /join', function() {
checkSession();
global $session;
$selectedUserIndex = Flight::request()->data['selectedUserIndex'];
$targetUserId = $session->userSearchResults[$selectedUserIndex]->getUserId();
$token = RAP\Util::createNewToken();
RAP\DAO::get()->createJoinRequest($token, $session->user->id, $targetUserId);
echo "";
});
...@@ -7,6 +7,16 @@ ...@@ -7,6 +7,16 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous" /> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link rel="stylesheet" href="css/style.css" />
<script src="js/script.js"></script>
</head> </head>
<body> <body>
<header id="main-header">
<div class="credits">
Image Credits & Copyright: Colombari/E.Recurt
</div>
<div class="page-title-wrapper">
<h1 class="text-center">Remote Authentication Portal</h1>
</div>
</header>
<div class="container"> <div class="container">
...@@ -40,5 +40,8 @@ include ROOT . '/config.php'; ...@@ -40,5 +40,8 @@ include ROOT . '/config.php';
$log = new Monolog\Logger('mainLogger'); $log = new Monolog\Logger('mainLogger');
$log->pushHandler(new Monolog\Handler\StreamHandler($LOG_PATH, $LOG_LEVEL)); $log->pushHandler(new Monolog\Handler\StreamHandler($LOG_PATH, $LOG_LEVEL));
function startSession() {
session_start(); session_start();
global $session;
$session = RAP\SessionData::get(); $session = RAP\SessionData::get();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment