diff --git a/info.textgrid.middleware.tgauth.tgaccount/service/insertRequest.php b/info.textgrid.middleware.tgauth.tgaccount/service/insertRequest.php index 985b383dc76593540532583f09d1b425d2d6976d..352d80d0ba2d8b33936dc47f845d19c2b2101f3c 100644 --- a/info.textgrid.middleware.tgauth.tgaccount/service/insertRequest.php +++ b/info.textgrid.middleware.tgauth.tgaccount/service/insertRequest.php @@ -1,8 +1,11 @@ <?php -// tell client, he hit correct endpoint ... -header("X-ATEndpoint: YES"); -// should be www.textgrid.de -header("Access-Control-Allow-Origin: *"); + +/** + * Header + */ + +header('X-ATEndpoint: YES'); +header('Access-Control-Allow-Origin: *'); include '../include/config.inc.php'; include '../include/tgSqliteDB.class.php'; @@ -13,81 +16,84 @@ $db = new tgSqliteDB($conf); $ldap = new tgLdap($conf); $imap = new tgImap($conf); -// work around magic_quotes_gpc +// Work around magic_quotes_gpc + if (get_magic_quotes_gpc()) { - $data = stripslashes($_POST['data']); + $data = stripslashes($_POST['data']); } else { - $data = $_POST['data']; + $data = $_POST['data']; } /** * Validation */ + $in = json_decode($data, TRUE); -$out['status'] = 'validating'; +$out['status'] = 'Validating ...'; -// if no language selected default to english -if(!isset($in['lang'])) { - $in['lang'] = 'en'; +if($in['name'] == $in['surname']) { + $out['error']['surname'] = 'spamSuspicion'; } -// email already used? -> query ldap -if($ldap->emailExists($in['email'])) { - $out['error']['email'] = "registered"; -} - -// userid already used? -> query ldap if($ldap->uidExists($in['userid'])) { - $out['error']['userid'] = "userid_used"; + $out['error']['userid'] = 'uidUsed'; +} + +if(empty($in['email'])) { + $out['error']['email'] = 'emailMissing'; } -if(empty($in['email']) ) { - $out['error']['email'] = "empty"; +if($ldap->emailExists($in['email'])) { + $out['error']['email'] = 'emailUsed'; } if(isset($out['error'])) { - echo json_encode($out); - return; + echo json_encode($out); + return; } /** - * validation done, request -> db, mail to user and ... + * Insert request */ -$db->insertUserRequest($in); + +// If no language given, default to English -// send email -sendMails($conf, $imap, $db, $in); +if(!isset($in['lang'])) { + $in['lang'] = 'en'; +} + +$db->insertUserRequest($in); +/** + * Return data + */ + +echo json_encode(array('status' => 'done')); /** - * Here the data is returned + * Send e-mails */ -echo json_encode(array("status" => "done")); +function sendMails($conf, $imap, $db, $data) { + // User -function sendMails($conf, $imap, $db, $data) { - - /** - * notify user - */ - $templateID = ($data['lang'] == 'de') ? 6 : 5; - $mail = $db->getMailTemplate($templateID); - - $subject = 'Request for textgrid account'; - $imap->mail($data['email'], $mail['subject'], $mail['body']); - - /** - * notify textgrid-team - */ - $body = ""; - foreach($data as $key => $value) { - $body .= $key . ': ' . $value . "\n"; - } - $body .= "\nLink zum Backend : " . $conf['url'] . "\n"; - - $imap->mail($conf['mail']['cc'], 'New Request', $body); - -} + $templateID = ($data['lang'] == 'de') ? 6 : 5; + $mail = $db->getMailTemplate($templateID); + + $imap->mail($data['email'], $mail['subject'], $mail['body']); + + // TextGrid team + + $body = ''; + foreach($data as $key => $value) { + $body .= $key . ': ' . $value . "\n"; + } + $body .= "\nLink zum Backend: " . $conf['url']; + + $imap->mail($conf['mail']['cc'], 'New request', $body); +} + +sendMails($conf, $imap, $db, $in); ?> diff --git a/info.textgrid.middleware.tgauth.tgaccount/service/insertRequest2.php b/info.textgrid.middleware.tgauth.tgaccount/service/insertRequest2.php deleted file mode 100644 index 86b6d40193cb55007c00b5a0e63234007cef6f0e..0000000000000000000000000000000000000000 --- a/info.textgrid.middleware.tgauth.tgaccount/service/insertRequest2.php +++ /dev/null @@ -1,99 +0,0 @@ -<?php - -/** - * Header - */ - -header('X-ATEndpoint: YES'); -header('Access-Control-Allow-Origin: *'); - -include '../include/config.inc.php'; -include '../include/tgSqliteDB.class.php'; -include '../include/tgLdap.class.php'; -include '../include/tgImap.class.php'; - -$db = new tgSqliteDB($conf); -$ldap = new tgLdap($conf); -$imap = new tgImap($conf); - -// Work around magic_quotes_gpc - -if (get_magic_quotes_gpc()) { - $data = stripslashes($_POST['data']); -} else { - $data = $_POST['data']; -} - -/** - * Validation - */ - -$in = json_decode($data, TRUE); -$out['status'] = 'Validating ...'; - -if($in['name'] == $in['surname']) { - $out['error']['surname'] = 'spamSuspicion'; -} - -if($ldap->uidExists($in['userid'])) { - $out['error']['userid'] = 'uidUsed'; -} - -if(empty($in['email'])) { - $out['error']['email'] = 'emailMissing'; -} - -if($ldap->emailExists($in['email'])) { - $out['error']['email'] = 'emailUsed'; -} - -if(isset($out['error'])) { - echo json_encode($out); - return; -} - -/** - * Insert request - */ - -// If no language given, default to English - -if(!isset($in['lang'])) { - $in['lang'] = 'en'; -} - -$db->insertUserRequest($in); - -/** - * Send e-mails - */ - -function sendMails($conf, $imap, $db, $data) { - - // User - - $templateID = ($data['lang'] == 'de') ? 6 : 5; - $mail = $db->getMailTemplate($templateID); - - $imap->mail($data['email'], $mail['subject'], $mail['body']); - - // TextGrid team - - $body = ''; - foreach($data as $key => $value) { - $body .= $key . ': ' . $value . "\n"; - } - $body .= "\nLink zum Backend: " . $conf['url']; - - $imap->mail($conf['mail']['cc'], 'New request', $body); -} - -sendMails($conf, $imap, $db, $in); - -/** - * Return data - */ - -echo json_encode(array('status' => 'done')); - -?>