73 lines
2.2 KiB
PHP
73 lines
2.2 KiB
PHP
<?php
|
|
|
|
class PreorderselfserviceApicontroller extends mfBaseApicontroller {
|
|
|
|
public function init() {
|
|
$this->addRoute("/preorderselfservice/preorder", "getPreorder", "GET");
|
|
}
|
|
|
|
protected function authenticated() {
|
|
if($this->me->username != "preorder-selfservice-gui-api") {
|
|
return \mfResponse::Forbidden();
|
|
}
|
|
}
|
|
|
|
private function authUser() {
|
|
return true;
|
|
//return false;
|
|
}
|
|
protected function getPreorder() {
|
|
if(!$this->authUser()) {
|
|
return mfResponse::Forbidden(["status" => "403", "message" => "User authentication failed"]);
|
|
}
|
|
|
|
$auth_email = trim($this->get["auth_email"]);
|
|
$auth_phone = trim($this->get["auth_phone"]);
|
|
|
|
$search = [];
|
|
if($auth_email) {
|
|
$search = ["email" => $auth_email];
|
|
} elseif($auth_phone) {
|
|
$phone_search = [];
|
|
$auth_phone = preg_replace('/[^0-9]+/', '', $auth_phone);
|
|
$phone_search[] = $auth_phone;
|
|
|
|
if(substr($auth_phone, 0, 2) == "43") {
|
|
$phone_search[] = "+$auth_phone";
|
|
$auth_phone = preg_replace('/^43/', '0', $auth_phone);
|
|
$phone_search[] = $auth_phone;
|
|
}
|
|
|
|
if(substr($auth_phone, 0, 1) != "0") {
|
|
$phone_search[] = "0$auth_phone";
|
|
}
|
|
$search = ["phone" => $phone_search];
|
|
}
|
|
|
|
if(!count($search)) {
|
|
return mfResponse::BadRequest(["message" => "auth method missing"]);
|
|
}
|
|
|
|
$preorders = PreorderModel::searchActive($search);
|
|
|
|
$result = [];
|
|
|
|
foreach($preorders as $preorder) {
|
|
if(!$preorder->adb_hausnummer || !$preorder->adb_wohneinheit) continue;
|
|
|
|
//$hausnummer = $preorder->adb_hausnummer;
|
|
//$wohneinheit = $preorder->adb_wohneinheit;
|
|
|
|
$item = [];
|
|
|
|
$item["preorder"] = $preorder->getApiArray(["full_home", "full_address"]);
|
|
//$item["building"] = $hausnummer->getApiArray();
|
|
//$item["unit"] = $wohneinheit->getApiArray();
|
|
|
|
$result[] = $item;
|
|
}
|
|
|
|
return mfResponse::Ok($result);
|
|
}
|
|
|
|
} |