From 1d344bdc70d61939f0a505960e87fd18ea8c8d54 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 14 Oct 2019 14:05:34 +0200 Subject: Refine old/test account merging logic --- modules/main.inc.php | 25 +++++++++++++------------ modules/register.inc.php | 11 ++++++----- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/modules/main.inc.php b/modules/main.inc.php index db62096..6119814 100644 --- a/modules/main.inc.php +++ b/modules/main.inc.php @@ -62,22 +62,23 @@ class Page_Main extends Page { $data = User::getData(); $data['organization'] = User::getOrganizationName(); - // Shoe testacc merge form if organization has test accounts - $res = Database::queryFirst('SELECT Count(*) as cnt FROM user WHERE organizationid = :oid', array( + // Show testacc merge form if organization has test accounts + $res = Database::queryFirst('SELECT Count(*) as cnt FROM user WHERE organizationid = :oid AND Length(password) <> 0', array( 'oid' => User::getOrganizationId() )); - if ($res !== false && $res['cnt'] > 0) { - $data['testacc'] = true; - $mail = trim(User::getMail()); - if (!empty($mail)) { - $existing = Database::queryFirst('SELECT userid FROM user WHERE email = :email LIMIT 1', array( - 'email' => $mail - )); - if ($existing !== false) { - $data['testlogin'] = $existing['userid']; - } + $mail = trim(User::getMail()); + if (!empty($mail)) { + $existing = Database::queryFirst('SELECT userid FROM user + WHERE email = :email AND lastname = :ln AND firstname = :fn LIMIT 1', array( + 'email' => $mail, + 'fn' => User::getFirstName(), + 'ln' => User::getLastName(), + )); + if ($existing !== false) { + $data['testlogin'] = $existing['userid']; } } + $data['testacc'] = ($res !== false && $res['cnt'] > 0) || !empty($existing); $data['suite'] = CONFIG_SUITE; $data['idm'] = CONFIG_IDM; Render::addTemplate('main/deploy', $data); diff --git a/modules/register.inc.php b/modules/register.inc.php index 19ccfcf..22b269d 100644 --- a/modules/register.inc.php +++ b/modules/register.inc.php @@ -23,7 +23,8 @@ class Page_Register extends Page Util::redirect('?do=Main'); } - if (Request::post('testlogin')) { + $anonymous = (Request::post('share') !== 'on'); + if (Request::post('testlogin') !== false) { // Check if one of firstname, lastname or email matches $user = Database::queryFirst('SELECT firstname, lastname, email, organizationid FROM user WHERE userid = :login LIMIT 1', array('login' => Request::post('testlogin'))); @@ -34,15 +35,15 @@ class Page_Register extends Page Util::redirect('?do=Main'); } if (User::getLastName() !== $user['lastname'] - && User::getFirstName() !== $user['firstname'] - && User::getMail() !== $user['email']) { + || User::getFirstName() !== $user['firstname'] + || User::getMail() !== $user['email']) { // No match by personal information Message::addError('Ihre Metadaten stimmen nicht mit dem Test-Account {{0}} überein. ' . ' Bitte wenden Sie sich an den {{1}}-Support, wenn dieser Test-Account Ihnen gehört.', Request::post('testlogin'), CONFIG_SUITE); Util::redirect('?do=Main'); } // Check if anonymous is requested, but user shared VMs with his testacc - if (Image::getImageCount(Request::post('testlogin')) > 0) { + if ($anonymous && Image::getImageCount(Request::post('testlogin')) > 0) { Message::addError('Sie haben mit Ihrem Test-Account Virtuelle Maschinen auf den Zentral-Server hochgeladen und können" . " sich daher nicht ohne Teilnahme am landesweiten VM-Austausch registrieren.'); Util::redirect('?do=Main'); @@ -59,7 +60,7 @@ class Page_Register extends Page } elseif (!User::hasFullName()) { Message::addError('Ihr Identity Provider hat keinen Namen zu Ihrem Account geliefert. Registrierung nicht möglich.'); // Put stuff in DB - } elseif (User::deploy(Request::post('share') !== 'on', Request::post('testlogin'))) { + } elseif (User::deploy($anonymous, Request::post('testlogin'))) { Message::addSuccess('Ihr Konto wurde freigeschaltet'); } else { Message::addError('Fehler beim Zusammenführen mit Ihrem Test-Account. Bitte wenden Sie sich an den Support.'); -- cgit v1.2.3-55-g7522