Skip to content

Commit

Permalink
allow scheduler login EM to use different fields types to validate us…
Browse files Browse the repository at this point in the history
…ers.
  • Loading branch information
ihabzee committed Jun 27, 2024
1 parent e68f038 commit 93eef8c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
45 changes: 29 additions & 16 deletions ChartLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ function redcap_survey_page_top(
$survey_hash,
$response_id = null,
$repeat_instance = 1
) {
)
{

$loginInstrument = $this->getProjectSetting('login-instrument');
$loginEventId = $this->getProjectSetting('login-instrument-event');
$loginEventId = $this->getProjectSetting('login-instrument-event');


// Handle a redirect to the main project
Expand All @@ -75,7 +76,8 @@ function redcap_survey_page_top(
}


private function scheduleLogin() {
private function scheduleLogin()
{
// Insert CSS (hide the submit button)
echo '<link rel="stylesheet" type="text/css" href="' .
$this->getUrl('asset/css/authentication.css', true, true) .
Expand Down Expand Up @@ -127,9 +129,9 @@ public function verifyCookie($name)
return false;
}

public function verifyUser($dob, $recordId)
public function verifyUser($value, $recordId)
{
$dob = \DateTime::createFromFormat("m-d-Y", $dob);
$dateValue = \DateTime::createFromFormat("m-d-Y", $value);
//$filter = "[newuniq] = '" . strtoupper($newuniq) . "' AND [zipcode_abs] = '" . $zipcode_abs . "'";
$param = array(
'project_id' => $this->getProjectId(),
Expand All @@ -139,28 +141,39 @@ public function verifyUser($dob, $recordId)
);
$data = REDCap::getData($param);
if ($this->getProjectSetting('input-fields') != '') {
$dates = json_decode($this->getProjectSetting('input-fields'), true);
$validation_fields = json_decode($this->getProjectSetting('input-fields'), true);
} else {
$dates = array('dob', 'zsfg_dob', 'birthdate');
$validation_fields = array('dob', 'zsfg_dob', 'birthdate');
}


$withdraw = $data[$recordId][$this->getProjectSetting('login-instrument-event')]['withdraw'];
if (empty($data) || $withdraw) {
return false;
} else {
foreach ($dates as $date) {
$d = ($data[$recordId][$this->getProjectSetting('login-instrument-event')][$date]);
if ($d != '') {
$d = \DateTime::createFromFormat("Y-m-d",
$data[$recordId][$this->getProjectSetting('login-instrument-event')][$date]);
if ($d->format('Y-m-d') == $dob->format('Y-m-d')) {
$this->setUserCookie('login',
$this->generateUniqueCodeHash($data[$recordId][$this->getProjectSetting('login-instrument-event')][$this->getProjectSetting('validation-field')]));
return $this->getSchedulerLink($recordId);
foreach ($validation_fields as $field) {
// if user is loggin in with date
if ($dateValue != null) {
$d = ($data[$recordId][$this->getProjectSetting('login-instrument-event')][$field]);
if ($d != '') {
$d = \DateTime::createFromFormat("Y-m-d",
$data[$recordId][$this->getProjectSetting('login-instrument-event')][$field]);
if ($d->format('Y-m-d') == $dateValue->format('Y-m-d')) {
$this->setUserCookie('login',
$this->generateUniqueCodeHash($data[$recordId][$this->getProjectSetting('login-instrument-event')][$this->getProjectSetting('validation-field')]));
return $this->getSchedulerLink($recordId);
}
}
}else{
$v = ($data[$recordId][$this->getProjectSetting('login-instrument-event')][$field]);
if ($v == $value) {
$this->setUserCookie('login',
$this->generateUniqueCodeHash($data[$recordId][$this->getProjectSetting('login-instrument-event')][$this->getProjectSetting('validation-field')]));
return $this->getSchedulerLink($recordId);
}
}


}
}
}
Expand Down
4 changes: 2 additions & 2 deletions ajax/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
/** @var ChartLogin $module */

try {
$dob = filter_var($_POST['dob'], FILTER_SANITIZE_STRING);
$recordId = filter_var($_POST['record_id'], FILTER_SANITIZE_STRING);
$dob = htmlspecialchars($_POST['verification_field']);
$recordId = htmlspecialchars($_POST['record_id']);
if (!$link = $module->verifyUser($dob, $recordId)) {
throw new \LogicException($module->getProjectSetting('failed-login-error-message') ?: "No user was found for provided information");
} else {
Expand Down
6 changes: 3 additions & 3 deletions asset/js/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ CHART = {
e.stopPropagation();
e.preventDefault();
e.stopImmediatePropagation();
var elem = $(document).find('input')[1];
var dob = $(elem).val();
var elem = $('input[name="verification_field"]');
var value = $(elem).val();
$.ajax({
url: CHART.endpoint,
data: {dob: dob, record_id: CHART.recordId},
data: {verification_field: value, record_id: CHART.recordId},
type: 'POST'
})
.done(function (response) {
Expand Down

0 comments on commit 93eef8c

Please sign in to comment.