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

Added identity update at login

parent 5febae64
No related branches found
No related tags found
No related merge requests found
...@@ -77,4 +77,6 @@ interface UserDAO { ...@@ -77,4 +77,6 @@ interface UserDAO {
function joinUsers($userId1, $userId2); function joinUsers($userId1, $userId2);
function isAdmin($userId): bool; function isAdmin($userId): bool;
function updateIdentity(Identity $identity): void;
} }
...@@ -159,17 +159,20 @@ class MySQLUserDAO extends BaseMySQLDAO implements UserDAO { ...@@ -159,17 +159,20 @@ class MySQLUserDAO extends BaseMySQLDAO implements UserDAO {
. " WHERE i.user_id IN" . " WHERE i.user_id IN"
. " (SELECT user_id FROM identity" . " (SELECT user_id FROM identity"
. " WHERE `email` LIKE :email OR `email` LIKE :emailPart" . " WHERE `email` LIKE :email OR `email` LIKE :emailPart"
. " OR `eppn` = :eppn" . " OR `eppn` LIKE :eppn"
. " OR `name` LIKE :name OR `surname` LIKE :surname" . " OR `name` LIKE :name OR `surname` LIKE :surname"
. " OR CONCAT(`name`,' ',`surname`) LIKE :namesurname)"; . " OR CONCAT(`name`,' ',`surname`) LIKE :namesurname)";
$stmt = $dbh->prepare($query); $stmt = $dbh->prepare($query);
$searchParam = $searchText . '%'; $searchParam = $searchText . '%';
if (count_chars($searchText) > 4) {
$searchParam = '%' . $searchParam;
}
$emailPartSearchParam = '%.' . $searchText . '%'; $emailPartSearchParam = '%.' . $searchText . '%';
$stmt->bindParam(':email', $searchParam); $stmt->bindParam(':email', $searchParam);
$stmt->bindParam(':emailPart', $emailPartSearchParam); $stmt->bindParam(':emailPart', $emailPartSearchParam);
$stmt->bindParam(':eppn', $searchText); $stmt->bindParam(':eppn', $searchParam);
$stmt->bindParam(':name', $searchParam); $stmt->bindParam(':name', $searchParam);
$stmt->bindParam(':surname', $searchParam); $stmt->bindParam(':surname', $searchParam);
$stmt->bindParam(':namesurname', $searchParam); $stmt->bindParam(':namesurname', $searchParam);
...@@ -281,4 +284,21 @@ class MySQLUserDAO extends BaseMySQLDAO implements UserDAO { ...@@ -281,4 +284,21 @@ class MySQLUserDAO extends BaseMySQLDAO implements UserDAO {
return count($result) === 1; return count($result) === 1;
} }
function updateIdentity(Identity $identity): void {
$dbh = $this->getDBHandler();
$query = "UPDATE identity SET email = :email, name = :name, surname = :surname, institution = :institution"
. " WHERE id = :id";
$stmt = $dbh->prepare($query);
$stmt->bindParam(':email', $identity->email);
$stmt->bindParam(':name', $identity->name);
$stmt->bindParam(':surname', $identity->surname);
$stmt->bindParam(':institution', $identity->institution);
$stmt->bindParam(':id', $identity->id);
$stmt->execute();
}
} }
...@@ -18,6 +18,8 @@ class LoginHandler { ...@@ -18,6 +18,8 @@ class LoginHandler {
if ($user === null) { if ($user === null) {
return $this->handleNewIdentity($typedId, $fillIdentityData); return $this->handleNewIdentity($typedId, $fillIdentityData);
} else {
$this->updateUser($user, $typedId, $fillIdentityData);
} }
return $this->getAfterLoginRedirect($user); return $this->getAfterLoginRedirect($user);
...@@ -68,6 +70,12 @@ class LoginHandler { ...@@ -68,6 +70,12 @@ class LoginHandler {
return $this->locator->getBasePath() . '/tou-check'; return $this->locator->getBasePath() . '/tou-check';
} }
private function updateUser(User $user, string $typedId, \Closure $fillIdentityData): void {
$identity = $user->getIdentityByTypedId($typedId);
$fillIdentityData($identity);
$this->locator->getUserDAO()->updateIdentity($identity);
}
public function getAfterLoginRedirect(User $user): string { public function getAfterLoginRedirect(User $user): string {
$session = $this->locator->getSession(); $session = $this->locator->getSession();
......
...@@ -42,6 +42,15 @@ class User { ...@@ -42,6 +42,15 @@ class User {
array_push($this->identities, $identity); array_push($this->identities, $identity);
} }
public function getIdentityByTypedId(string $typedId): Identity {
foreach ($this->identities as $identity) {
if ($identity->typedId === $typedId) {
return $identity;
}
}
throw new \Exception("Identity not found for typed id " . $typedId);
}
public function getPrimaryEmail() { public function getPrimaryEmail() {
foreach ($this->identities as $identity) { foreach ($this->identities as $identity) {
if ($identity->primary) { if ($identity->primary) {
......
<?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.
*/
$CONTEXT_ROOT = "/rap-ia2";
$VERSION = "1.0.2";
$PROTOCOL = stripos($_SERVER['SERVER_PROTOCOL'], 'https') ? 'https://' : 'http://';
$BASE_PATH = $PROTOCOL . $_SERVER['HTTP_HOST'] . $CONTEXT_ROOT;
$LOG_PATH = ROOT . "/logs/rap-service.log";
$AUDIT_LOG_PATH = ROOT . "/logs/rap-audit.log";
$LOG_LEVEL = Monolog\Logger::DEBUG;
$CALLBACKS = [
array(
'url' => 'http://localhost:8087/grouper',
'title' => 'Login to Grouper',
'logo' => 'grouper.png'
),
array(
'url' => 'http://localhost/rap-ia2/',
'title' => 'Account Management',
'logo' => 'account-manager.png'
)
];
$DATABASE = array(
'dbtype' => 'MySQL',
'hostname' => 'localhost',
'port' => 3306,
'username' => 'XXXXXX',
'password' => 'XXXXXX',
'dbname' => 'rap'
);
$AUTHENTICATION_METHODS = array(
'eduGAIN' => array(),
'Google' => array(
'id' => "XXXXXX",
'secret' => "XXXXXX",
'callback' => $BASE_PATH . "/auth/social/google_token.php"),
'Facebook' => array(
'id' => "XXXXXX",
'secret' => "XXXXXX",
'version' => "v3.0",
'callback' => $BASE_PATH . "/auth/social/facebook_token.php"),
'LinkedIn' => array(
'id' => 'XXXXXX',
'secret' => 'XXXXXX',
'callback' => $BASE_PATH . '/auth/social/linkedin_token.php'
),
'X.509' => array(),
'DirectIdP' => array(
'url' => 'https://sso.ia2.inaf.it/Shibboleth.sso/Login?entityID=https://sso.ia2.inaf.it/idp/shibboleth&target=https://sso.ia2.inaf.it/rap-ia2/auth/saml2/aai.php',
'logo' => 'img/ia2-logo-60x60.png',
'logo_alt' => 'IA2 logo',
'description' => 'Use the IA2 Logo to Login if you have an account provided by IA2 or self registered'
)
);
$GROUPER = array(
'wsURL' => 'http://hostname/grouper-ws/',
'user' => 'XXXXXX',
'password' => 'XXXXXX'
);
...@@ -28,8 +28,13 @@ include './include/front-controller.php'; ...@@ -28,8 +28,13 @@ include './include/front-controller.php';
include './include/gui-backend.php'; include './include/gui-backend.php';
include './include/rest-web-service.php'; include './include/rest-web-service.php';
Flight::set('flight.log_errors', true);
// Error handling // Error handling
Flight::map('error', function($ex) { Flight::map('error', function($ex) {
if ($ex instanceof \Exception) {
error_log($ex->getTraceAsString());
}
if ($ex instanceof \RAP\BadRequestException) { if ($ex instanceof \RAP\BadRequestException) {
http_response_code(400); http_response_code(400);
echo "Bad request: " . $ex->message; echo "Bad request: " . $ex->message;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment