Пример #1
0
 /**
  * Handle error/exception occurence around DB operations
  *
  * @param string $message - description of the error
  * @param PDOException $e - exception object
  * @param bool $fatal     - should this error shutdown the script?
  * @param bool $sendEmail - should Email about error should be send?
  */
 protected function error($message, PDOException $e = null, $fatal = false, $sendEmail = true)
 {
     $email_text = "+++ PDO Error +++ ";
     $email_text .= "\n+++ Debug: " . $message;
     if (!is_null($e)) {
         $email_text .= "\n+++ Ex_Code: " . $e->getCode();
         $email_text .= "\n+++ Ex_Msg: " . $e->getMessage();
     } else {
         //there is no Exception - generate one to get the trace
         $e = new PDOException();
     }
     $email_text .= "\n+++ Ex_Trace:\n" . $e->getTraceAsString();
     //get short version of the trace
     $traceStr = '';
     foreach ($e->getTrace() as $trace) {
         $traceStr .= ' | ' . $trace['file'] . '::' . $trace['line'];
     }
     //send email to RT
     if ($sendEmail) {
         EmailSender::adminOnErrorMessage($email_text, OcSpamDomain::DB_ERRORS);
     }
     if ($this->debug) {
         d($email_text);
     }
     if ($fatal) {
         // TODO: How to better handle error - print some nice error page
         // this is fatal error - stop the script
         trigger_error("OcPdo Error:\n {$message}. Trace: " . $traceStr, E_USER_ERROR);
         exit;
     } else {
         // non-fatal error: only print warning
         trigger_error("OcPdo Error: {$message}. Trace: " . $traceStr, E_USER_WARNING);
     }
 }
Пример #2
0
 public function removeLog(GeoCacheLog $log, $request = null)
 {
     $result = false;
     if ($log === false) {
         $this->errors[] = 'No such log';
         return false;
     }
     if ($log->getNode() != OcConfig::instance()->getOcNodeId()) {
         $this->errors[] = 'Wrong Node';
         return false;
     }
     $loggedUser = \lib\Objects\ApplicationContainer::Instance()->getLoggedUser();
     if ($loggedUser === false) {
         $this->errors[] = 'User is not looged-in';
         return false;
     }
     if ($log->getUser()->getUserId() === $loggedUser->getUserId() || $log->getGeoCache()->getOwner()->getUserId() == $loggedUser->getUserId() || $loggedUser->getIsAdmin()) {
         if ($log->getUser()->getUserId() !== $loggedUser->getUserId()) {
             EmailSender::sendRemoveLogNotification(__DIR__ . '/../../tpl/stdstyle/email/removed_log.email.html', $log, $loggedUser);
         }
         $updateQuery = "UPDATE `cache_logs` SET deleted = 1, `del_by_user_id` = :1 , `last_modified`=NOW(), `last_deleted`=NOW() WHERE `cache_logs`.`id`=:2 LIMIT 1";
         $db = OcDb::instance();
         $db->multiVariableQuery($updateQuery, $loggedUser->getUserId(), $log->getId());
         $log->getUser()->recalculateAndUpdateStats();
         if ($log->getType() == GeoCacheLog::LOGTYPE_MOVED) {
             $this->handleMobileGeocachesAfterLogDelete($log);
         }
         if ($log->getType() == GeoCacheLog::LOGTYPE_FOUNDIT || $log->getType() == GeoCacheLog::LOGTYPE_ATTENDED) {
             $this->cacheScoreHandlingAfterRemoveLog($log);
         }
         //call eventhandler
         require_once __DIR__ . '/../eventhandler.inc.php';
         event_remove_log($log->getGeoCache()->getCacheId(), $loggedUser->getUserId());
         $this->updateGeocacheAfterLogRemove($log, $db);
         $result = true;
     } else {
         $this->errors[] = 'User has no privileages to delete this log';
     }
     return $result;
 }
Пример #3
0
    $code = isset($_REQUEST['code']) ? $_REQUEST['code'] : '';
    tpl_set_var('error_message', '');
    tpl_set_var('success_message', '');
    tpl_set_var('login_url', '');
    if (isset($code) && isset($user)) {
        //TO DO: maybe validate uuid here..
        $rs = XDb::xSql("SELECT `user_id` `id`, `activation_code` `code`, `email`, `username`\n                    FROM `user` WHERE `uuid`= ? ", $user);
        if ($r = XDb::xFetchArray($rs)) {
            if ($r['code'] != '') {
                if ($r['code'] == $code && $code != '') {
                    XDb::xFreeResults($rs);
                    // ok, we can activate this account
                    XDb::xSql("UPDATE `user` SET `is_active_flag`=1, `activation_code`='' WHERE `user_id`= ? ", $r['id']);
                    tpl_set_var('success_message', tr('activation_success'));
                    tpl_set_var('login_url', '<a href="login.php">' . tr('goto_login') . '</a><br />');
                    EmailSender::sendPostActivationMail(__DIR__ . '/tpl/stdstyle/email/post_activation.email.html', $r['username'], $r['email']);
                } else {
                    tpl_set_var('error_message', tr('activation_error1'));
                }
            } else {
                tpl_set_var('error_message', tr('activation_error2'));
            }
        } else {
            tpl_set_var('error_message', tr('activation_error1'));
        }
        XDb::xFreeResults($rs);
    } else {
        tpl_set_var('error_message', tr('activation_error1'));
    }
}
//make the template and send it out
Пример #4
0
     }
 }
 if ($all_ok) {
     //send email
     //generate random password
     $activationcode = mb_strtoupper(mb_substr(md5(uniqid('')), 0, 13));
     $country_name = tr($country);
     $uuid = create_uuid();
     if (strtotime("2008-11-01 00:00:00") <= strtotime(date("Y-m-d h:i:s"))) {
         $rules_conf_req = 1;
     } else {
         $rules_conf_req = 0;
     }
     //insert the user
     XDb::xSql("INSERT INTO `user` ( `user_id`, `username`, `password`, `email`, `latitude`,\n                                          `longitude`, `last_modified`, `login_faults`, `login_id`, `is_active_flag`,\n                                          `was_loggedin`, `country`, `date_created`,\n                                          `uuid`, `activation_code`, `node`, `rules_confirmed` )\n                    VALUES ('', ?, ?, ?, NULL, NULL, NOW(), '0', '0', '0', '0', ?, NOW(), ?, ?, ?, ?)", $username, hash('sha512', md5($password)), $email, $country, $uuid, $activationcode, $oc_nodeid, $rules_conf_req);
     EmailSender::sendActivationMessage(__DIR__ . '/tpl/stdstyle/email/user_activation.email.html', $username, $country, $activationcode, $email, $uuid);
     //display confirmationpage
     $tplname = 'register_confirm';
     tpl_set_var('country', htmlspecialchars($country_name, ENT_COMPAT, 'UTF-8'));
 } else {
     //set error strings
     if ($email_not_ok) {
         tpl_set_var('email_message', $error_email_not_ok);
     }
     if ($username_not_ok) {
         tpl_set_var('username_message', $error_username_not_ok);
     }
     if ($email_exists) {
         tpl_set_var('email_message', $error_email_exists);
     }
     if ($username_exists) {