public function addEntity($data) { Log::debug('Adding new user for tenant ' + $this->tenantid, 5); // before save: salt & hash password and perform user-specific validation // ensure email not already in use $query = "select count(*) from user where email=" . Database::queryString($data->{"email"}) . ";"; $result = Database::executeQuery($query); while ($arr = mysqli_fetch_row($result)) { if ($arr[0] > 0) { throw new Exception("That email address is already in use. Please select another."); } } $pass = Utility::generateHash($data->{"password"}); $data->{"password"} = $pass; $newid = parent::addEntity($data); // by default, a newly created user gets assigned to the current tenant $query = "call addTenantUserRole(" . Database::queryNumber($newid) . "," . Database::queryNumber($this->tenantid) . "," . Database::queryString('standard') . ");"; Database::executeQuery($query); return $newid; }
public function addEntity($data) { // override on new save to set default metadata Log::debug('saving media ', 5); if (!key_exists('metadata', $data)) { // no object at all, so create $data->{'metadata'} = new stdClass(); } $arr = $data->{'metadata'}; if (!key_exists("caption", $arr)) { $arr->{'caption'} = ''; } if (!key_exists("credit", $arr)) { $arr->{'credit'} = ''; } $data->{'metadata'} = $arr; return parent::addEntity($data); }
public function addEntity($data) { // need to have special handling depending upon role of user // how inefficient is it to spin up a new user object here? Calling service will already have done just that? // contributor role users can only add into the pending state (for review by admin) $user = new User($this->userid, $this->tenantid); if ($user->hasRole('contributor', $this->tenantid)) { $data->{"status"} = 'Pending'; } return parent::addEntity($data); }