/** * @before _secure */ public function addFamily() { $this->JSONview(); $view = $this->getActionView(); if (RequestMethods::post("action") == "patient") { $email = RequestMethods::post("email"); $patient = null; if (strlen($email) > 4) { $patient = User::first(array("email = ?" => $email)); $m = "Email exists enter a different email"; } $phone = RequestMethods::post("phone", ""); if (strlen($phone) >= 10) { $patient = User::first(array("phone = ?" => $phone)); $m = "Phone already exists please choose a different one"; } if ($patient) { $view->set("success", false); $view->set("message", $m); return; } $patient = new User(array("name" => RequestMethods::post("name", ""), "email" => $email, "phone" => $phone, "password" => sha1($this->randomPassword()), "gender" => RequestMethods::post("gender", ""), "birthday" => RequestMethods::post("birthday", ""), "live" => 1)); $patient->save(); $family = new Family(array("user_id" => $this->user->id, "member_id" => $patient->id, "relation" => RequestMethods::post("relation"))); $family->save(); Location::saveRecord($patient); if ($email) { Mail::notify(array("template" => "notifyFamily", "subject" => "Getting Started on HealthLitmus.com", "user" => $patient, "patient" => $patient, "member" => $this->user, "family" => $family)); } Mail::notify(array("template" => "addFamily", "subject" => "New Beneficiary Added {$patient->name} on HealthLitmus.com", "user" => $this->user, "mail" => $email, "patient" => $patient, "family" => $family)); $fs = Shared\Services\Patient::findFamily($this->user); $view->set("patient", $patient); $view->set("families", $fs); $view->set("success", true); } //$this->redirect($_SERVER['HTTP_REFERER']); }
/** * @before _session */ public function gLogin() { $this->noview(); $session = Registry::get("session"); if (RequestMethods::post("action") == "gLogin" && isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { // process the registration $email = RequestMethods::post("email"); $user = User::first(array("email = ?" => $email, "live = ?" => true)); if (!$user) { $user = new User(array("name" => RequestMethods::post("name"), "email" => $email, "phone" => RequestMethods::post("phone", ""), "password" => sha1(rand(999999, 99999999)), "gender" => RequestMethods::post("gender", ""), "birthday" => RequestMethods::post("birthday", ""), "live" => true)); $user->save(); Mail::notify(array("template" => "patientRegister", "subject" => "Welcome to HealthLitmus.com", "user" => $user)); } $this->setUser($user); echo "Success"; } else { $this->redirect("/home"); } }