/** * Registers new principal and school for platform access * @return [type] [description] */ public function register() { $this->setSEO(array("title" => "Register School")); $view = $this->getActionView(); if (RequestMethods::post("action") == "register") { $user = new \User(array("name" => RequestMethods::post("name"), "email" => RequestMethods::post("email"), "phone" => RequestMethods::post("phone"), "username" => strtolower(implode("", explode(" ", RequestMethods::post("name")))), "password" => Markup::encrypt("password"), "admin" => 0)); $user->save(); $location = new Location(array("user_id" => $user->id, "address" => RequestMethods::post("address"), "city" => RequestMethods::post("city"), "latitude" => "", "longitude" => "")); $location->save(); $organization = new Organization(array("user_id" => $user->id, "name" => RequestMethods::post("sname"), "location_id" => $location->id, "phone" => RequestMethods::post("sphone"), "logo" => "")); $organization->save(); $view->set("success", true); } }
/** * Creates new Users with unique username * @return null|object */ protected function _createUser($opts) { $name = $opts["name"]; $email = $opts["email"]; $phone = $opts["phone"]; $last = \User::first(array(), array("id"), "created", "desc"); $id = (int) $last->id + 1; $prefix = strtolower(array_shift(explode(" ", $this->organization->name))); if (Markup::checkValue($email)) { $found = \User::first(array("email = ?" => $email), array("id")); if ($found) { throw new \Exception("Email already exists"); } } if (Markup::checkValue($phone)) { $found = \User::first(array("phone = ?" => $phone), array("id")); if ($found) { throw new \Exception("Phone number already exists"); } } if (empty(Markup::checkValue($name))) { return NULL; // throw new \Exception("Please provide a name"); } $user = new \User(array("name" => $name, "email" => $email, "phone" => $phone, "username" => $prefix . "_" . $id, "password" => Markup::encrypt("password"))); $user->save(); return $user; }