/** * Logs an Error, should be in Config, but that doesn't extend permissions * @param string $error The error stacktrace * @throws \Exception */ public function logError($error) { if (!is_string($error)) { throw $this->throwException(2003); } $error = strip_tags($error); Log::addToLog('-------------------------------------------'); Log::addToLog(date('r') . ':'); Log::addToLog($error); Log::addToLog('-------------------------------------------'); $mailer = new Mailer(); $message = 'An error occurred at ' . date('r') . ' on ' . SITENAME . "\r\nThe stacktrace is:\r\n" . $error; $mailer->sendPlainMail(SYSMAIL, SYSMAIL, 'Bright Error', $message); }
/** * Creates a user<br/> * @param OUserObject $user The user to create * @param boolean $sendMail Indicates whether an email with his credentials should be send to the newly created user * @param string $password When $sendMail is true, you have to pass the non-hashed password to this method in order to include it in the e-mail * @return array An array of all the users * @throws \Exception */ private function _createUser($user, $sendMail = false, $password = '') { $email = Connection::getInstance()->escape_string($user->email); $result = $this->conn->getRow("SELECT count(userId) as ids \n\t\t\t\t\t\t\t\t\tFROM user \n\t\t\t\t\t\t\t\t\tWHERE email = '{$email}' and (deleted IS NULL OR YEAR(deleted) = 0)"); if ($result->ids > 0) { throw $this->throwException(8002); } $this->_hashPassword($user->password, $user->email); $activationCode = md5(time() . $user->password); $activated = $user->activated ? 1 : 0; $user->itemType = (int) $user->itemType; $insert = $this->conn->insertRow('INSERT INTO user (`label`, `itemType`, `email`, `password`, `registrationdate`, `modificationdate`, `activationcode`, `activated`) ' . "VALUES ('" . Connection::getInstance()->escape_string($user->label) . "',\n\t\t\t\t\t\t\t\t\t\t\t{$user->itemType},\n\t\t\t\t\t\t\t\t\t\t\t'{$email}',\n\t\t\t\t\t\t\t\t\t\t\t'" . Connection::getInstance()->escape_string($user->password) . "',\n\t\t\t\t\t\t\t\t\t\t\tNOW(),\n\t\t\t\t\t\t\t\t\t\t\t" . time() . ",\n\t\t\t\t\t\t\t\t\t\t\t'{$activationCode}',\n\t\t\t\t\t\t\t\t\t\t\t{$activated})"); if ($insert > 0) { $user->userId = $insert; if ($sendMail) { ob_start(); include 'registration.txt'; $content = ob_get_contents(); ob_end_clean(); $content = str_replace('###sitename###', SITENAME, $content); $content = str_replace('###baseurl###', BASEURL, $content); $content = str_replace('###email###', $user->email, $content); $content = str_replace('###password###', $password, $content); $ma = new Mailer(); $ma->sendPlainMail(MAILINGFROM, $user->email, 'Your account for ' . SITENAME . ' is ready', $content); } return $user->userId; } throw $this->throwException(UserException::INSERT_ERROR); }