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

Started autojoin implementation

parent 1d9aab8c
No related branches found
No related tags found
No related merge requests found
...@@ -79,4 +79,6 @@ interface UserDAO { ...@@ -79,4 +79,6 @@ interface UserDAO {
function isAdmin($userId): bool; function isAdmin($userId): bool;
function updateIdentity(Identity $identity): void; function updateIdentity(Identity $identity): void;
function findJoinableUsers($userId): array;
} }
...@@ -301,4 +301,31 @@ class MySQLUserDAO extends BaseMySQLDAO implements UserDAO { ...@@ -301,4 +301,31 @@ class MySQLUserDAO extends BaseMySQLDAO implements UserDAO {
$stmt->execute(); $stmt->execute();
} }
function findJoinableUsers($userId): array {
$dbh = $this->getDBHandler();
$query = "SELECT DISTINCT(i3.user_id)\n"
. "FROM user u\n"
. "JOIN identity i ON i.user_id = u.id\n"
. "JOIN identity i2 ON i.user_id = i2.user_id\n"
. "JOIN identity i3 ON i2.email = i3.email\n"
. "WHERE i.email IN (SELECT email FROM identity where user_id = :user_id)\n"
. "AND i3.user_id NOT IN (SELECT :user_id UNION\n"
. "SELECT user_id2 FROM keep_separated WHERE user_id1 = :user_id\n"
. "UNION\n"
. "SELECT user_id1 FROM keep_separated WHERE user_id2 = :user_id)";
$stmt = $dbh->prepare($query);
$stmt->bindParam(':user_id', $userId);
$stmt->execute();
$results = [];
foreach ($stmt->fetchAll() as $row) {
array_push($results, $row['user_id']);
}
return $results;
}
} }
...@@ -38,6 +38,7 @@ class SessionData { ...@@ -38,6 +38,7 @@ class SessionData {
private $oauth2RequestData; private $oauth2RequestData;
private $action; private $action;
private $loginIdentityType; private $loginIdentityType;
private $autojoin = false;
public function setUser(?User $user): void { public function setUser(?User $user): void {
$this->user = $user; $this->user = $user;
...@@ -57,6 +58,15 @@ class SessionData { ...@@ -57,6 +58,15 @@ class SessionData {
return $this->userToJoin; return $this->userToJoin;
} }
public function setAutojoin(bool $autojoin): void {
$this->autojoin = $autojoin;
$this->save();
}
public function isAutojoin(): bool {
return $this->autojoin;
}
public function setLoginIdentityType(string $loginIdentityType): void { public function setLoginIdentityType(string $loginIdentityType): void {
$this->loginIdentityType = $loginIdentityType; $this->loginIdentityType = $loginIdentityType;
$this->save(); $this->save();
......
...@@ -297,6 +297,7 @@ Flight::route('GET /confirm-join', function() { ...@@ -297,6 +297,7 @@ Flight::route('GET /confirm-join', function() {
die("User data not retrieved."); die("User data not retrieved.");
} else { } else {
Flight::render('confirm-join.php', array('title' => 'Confirm join', Flight::render('confirm-join.php', array('title' => 'Confirm join',
'autojoin' => $locator->getSession()->isAutojoin(),
'user' => $locator->getSession()->getUser(), 'user' => $locator->getSession()->getUser(),
'user_to_join' => $locator->getSession()->getUserToJoin(), 'user_to_join' => $locator->getSession()->getUserToJoin(),
'version' => $locator->getVersion(), 'version' => $locator->getVersion(),
......
...@@ -58,6 +58,15 @@ CREATE TABLE `identity` ( ...@@ -58,6 +58,15 @@ CREATE TABLE `identity` (
ALTER TABLE identity ADD CONSTRAINT eppn_unique UNIQUE(eppn); ALTER TABLE identity ADD CONSTRAINT eppn_unique UNIQUE(eppn);
ALTER TABLE identity ADD CONSTRAINT typed_id_unique UNIQUE(typed_id); ALTER TABLE identity ADD CONSTRAINT typed_id_unique UNIQUE(typed_id);
-- remember that a user decided to avoid a join
CREATE TABLE `keep_separated` (
`user_id1` bigint(20) NOT NULL,
`user_id2` bigint(20) NOT NULL,
PRIMARY KEY (`user_id1`, `user_id2`),
FOREIGN KEY (`user_id1`) REFERENCES `user`(`id`),
FOREIGN KEY (`user_id2`) REFERENCES `user`(`id`)
);
SET FOREIGN_KEY_CHECKS=0; SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE `user` ADD FOREIGN KEY (`primary_identity`) REFERENCES `identity`(`id`); ALTER TABLE `user` ADD FOREIGN KEY (`primary_identity`) REFERENCES `identity`(`id`);
SET FOREIGN_KEY_CHECKS=1; SET FOREIGN_KEY_CHECKS=1;
......
...@@ -4,7 +4,14 @@ include 'include/header.php'; ...@@ -4,7 +4,14 @@ include 'include/header.php';
<br/> <br/>
<div class="text-center"> <div class="text-center">
<?php if ($autojoin) { ?>
<h3>Multiple accounts detected</h3><br/>
<p>The system found multiple accounts associated with the same e-mail address. We suggest you to join them, so that
they will be seen as a single user. If you prefer to keep these accounts separated you can click on "Reject join" button.
</p>
<?php } else { ?>
<h3>Following identities will be joined:</h3><br/> <h3>Following identities will be joined:</h3><br/>
<?php } ?>
</div> </div>
<div class="row"> <div class="row">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment