Ejemplo n.º 1
0
 function saveAccountAction()
 {
     @($first_name = DevblocksPlatform::importGPC($_REQUEST['first_name'], 'string', ''));
     @($last_name = DevblocksPlatform::importGPC($_REQUEST['last_name'], 'string', ''));
     @($change_password = DevblocksPlatform::importGPC($_REQUEST['change_password'], 'string', ''));
     @($change_password2 = DevblocksPlatform::importGPC($_REQUEST['change_password2'], 'string', ''));
     $tpl = DevblocksPlatform::getTemplateService();
     $umsession = UmPortalHelper::getSession();
     $active_user = $umsession->getProperty('sc_login', null);
     if (!empty($active_user)) {
         $fields = array(DAO_Address::FIRST_NAME => $first_name, DAO_Address::LAST_NAME => $last_name);
         DAO_Address::update($active_user->id, $fields);
         $tpl->assign('account_success', true);
         if (!empty($change_password)) {
             if (0 == strcmp($change_password, $change_password2)) {
                 DAO_AddressAuth::update($active_user->id, array(DAO_AddressAuth::PASS => md5($change_password)));
             } else {
                 $tpl->assign('account_error', "The passwords you entered did not match.");
             }
         }
     }
     DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'account')));
 }
Ejemplo n.º 2
0
 private function _sendConfirmation($email, $link)
 {
     $settings = CerberusSettings::getInstance();
     $from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM);
     $from_personal = $settings->get(CerberusSettings::DEFAULT_REPLY_PERSONAL);
     $url = DevblocksPlatform::getUrlService();
     try {
         $mail_service = DevblocksPlatform::getMailService();
         $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults());
         $code = CerberusApplication::generatePassword(8);
         if (!empty($email) && null != ($addy = DAO_Address::lookupAddress($email, false))) {
             $fields = array(DAO_AddressAuth::CONFIRM => $code);
             DAO_AddressAuth::update($addy->id, $fields);
         } else {
             return;
         }
         $message = $mail_service->createMessage();
         $message->setTo($email);
         $send_from = new Swift_Address($from, $from_personal);
         $message->setFrom($send_from);
         $message->setSubject("Account Confirmation Code");
         $message->setBody(sprintf("Below is your confirmation code.  Please copy and paste it into the confirmation form at:\r\n" . "%s\r\n" . "\r\n" . "Your confirmation code is: %s\r\n" . "\r\n" . "Thanks!\r\n", $link, $code));
         $message->headers->set('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')');
         $mailer->send($message, $email, $send_from);
     } catch (Exception $e) {
         return;
     }
 }
Ejemplo n.º 3
0
 function doImportAction()
 {
     $active_worker = CerberusApplication::getActiveWorker();
     if (!$active_worker->hasPriv('core.addybook.import')) {
         return;
     }
     @($pos = DevblocksPlatform::importGPC($_REQUEST['pos'], 'array', array()));
     @($field = DevblocksPlatform::importGPC($_REQUEST['field'], 'array', array()));
     @($sync_column = DevblocksPlatform::importGPC($_REQUEST['sync_column'], 'string', ''));
     @($include_first = DevblocksPlatform::importGPC($_REQUEST['include_first'], 'integer', 0));
     @($is_blank_unset = DevblocksPlatform::importGPC($_REQUEST['is_blank_unset'], 'integer', 0));
     @($replace_passwords = DevblocksPlatform::importGPC($_REQUEST['replace_passwords'], 'integer', 0));
     $visit = CerberusApplication::getVisit();
     $db = DevblocksPlatform::getDatabaseService();
     $csv_file = $visit->get('import.last.csv', '');
     $type = $visit->get('import.last.type', '');
     $fp = fopen($csv_file, "rt");
     if (!$fp) {
         return;
     }
     // [JAS]: Do we need to consume a first row of headings?
     if (!$include_first) {
         @fgetcsv($fp, 8192, ',', '"');
     }
     while (!feof($fp)) {
         $parts = fgetcsv($fp, 8192, ',', '"');
         if (empty($parts) || 1 == count($parts) && is_null($parts[0])) {
             continue;
         }
         $fields = array();
         $custom_fields = array();
         $sync_field = '';
         $sync_val = '';
         // Overrides
         $contact_password = '';
         foreach ($pos as $idx => $p) {
             $key = $field[$idx];
             $val = $parts[$idx];
             if (!empty($key)) {
                 // Organizations
                 if ($type == "orgs") {
                     switch ($key) {
                         // Multi-Line
                         case 'street':
                             @($val = isset($fields[$key]) ? $fields[$key] . ', ' . $val : $val);
                             break;
                             // Dates
                         // Dates
                         case 'created':
                             @($val = !is_numeric($val) ? strtotime($val) : $val);
                             break;
                     }
                     // Custom fields
                     if ('cf_' == substr($key, 0, 3)) {
                         $custom_fields[substr($key, 3)] = $val;
                     } else {
                         $fields[$key] = $val;
                     }
                     // Addresses
                 } elseif ($type == "addys") {
                     switch ($key) {
                         // Org (from string into id)
                         case 'contact_org_id':
                             if (null != ($org_id = DAO_ContactOrg::lookup($val, true))) {
                                 $val = $org_id;
                             } else {
                                 $val = 0;
                             }
                             break;
                         case 'password':
                             $key = null;
                             $contact_password = $val;
                             break;
                     }
                     // Custom fields
                     if ('cf_' == substr($key, 0, 3)) {
                         $custom_fields[substr($key, 3)] = $val;
                     } else {
                         $fields[$key] = $val;
                     }
                 }
                 if (!empty($key)) {
                     // [JAS]: Are we looking for matches in a certain field?
                     if ($sync_column == $key && !empty($val)) {
                         $sync_field = $key;
                         $sync_val = $val;
                     }
                 }
             }
         }
         if (!empty($fields)) {
             if ($type == "orgs") {
                 @($orgs = DAO_ContactOrg::getWhere(!empty($sync_field) && !empty($sync_val) ? sprintf('%s = %s', $sync_field, $db->qstr($sync_val)) : sprintf('name = %s', $db->qstr($fields['name']))));
                 if (isset($fields['name'])) {
                     if (empty($orgs)) {
                         $id = DAO_ContactOrg::create($fields);
                     } else {
                         $id = key($orgs);
                         DAO_ContactOrg::update($id, $fields);
                     }
                 }
             } elseif ($type == "addys") {
                 if (!empty($sync_field) && !empty($sync_val)) {
                     @($addys = DAO_Address::getWhere(sprintf('%s = %s', $sync_field, $db->qstr($sync_val))));
                 }
                 if (isset($fields['email'])) {
                     if (empty($addys)) {
                         $id = DAO_Address::create($fields);
                     } else {
                         $id = key($addys);
                         DAO_Address::update($id, $fields);
                     }
                     // Overrides
                     if (!empty($contact_password) && !empty($id)) {
                         if ($replace_passwords) {
                             // always replace
                             DAO_AddressAuth::update($id, array(DAO_AddressAuth::PASS => $contact_password));
                         } else {
                             // only replace if null
                             if (null == ($auth = DAO_AddressAuth::get($id))) {
                                 DAO_AddressAuth::update($id, array(DAO_AddressAuth::PASS => $contact_password));
                             }
                         }
                     }
                 }
             }
         }
         if (!empty($custom_fields) && !empty($id)) {
             // Format (typecast) and set the custom field types
             $source_ext_id = $type == "orgs" ? ChCustomFieldSource_Org::ID : ChCustomFieldSource_Address::ID;
             DAO_CustomFieldValue::formatAndSetFieldValues($source_ext_id, $id, $custom_fields, $is_blank_unset);
         }
     }
     @unlink($csv_file);
     // nuke the imported file
     $visit->set('import.last.csv', null);
     $visit->set('import.last.type', null);
     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('contacts', 'import')));
 }
Ejemplo n.º 4
0
 static function delete($ids)
 {
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     if (empty($ids)) {
         return;
     }
     $db = DevblocksPlatform::getDatabaseService();
     $address_ids = implode(',', $ids);
     // Addresses
     $sql = sprintf("DELETE QUICK FROM address WHERE id IN (%s)", $address_ids);
     $db->Execute($sql) or die(__CLASS__ . '(' . __LINE__ . ')' . ':' . $db->ErrorMsg());
     /* @var $rs ADORecordSet */
     // Auth logins
     DAO_AddressAuth::delete($ids);
     // Custom fields
     DAO_CustomFieldValue::deleteBySourceIds(ChCustomFieldSource_Address::ID, $ids);
 }
Ejemplo n.º 5
0
 function doRegisterConfirmAction()
 {
     @($email = DevblocksPlatform::importGPC($_REQUEST['email'], 'string', ''));
     @($code = trim(DevblocksPlatform::importGPC($_REQUEST['code'], 'string', '')));
     @($pass = DevblocksPlatform::importGPC($_REQUEST['pass'], 'string', ''));
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->assign('register_email', $email);
     $tpl->assign('register_code', $code);
     if (!empty($email) && !empty($pass) && !empty($code)) {
         if (null != ($addy = DAO_Address::lookupAddress($email, false)) && null != ($auth = DAO_AddressAuth::get($addy->id)) && !empty($auth) && !empty($auth->confirm) && 0 == strcasecmp($code, $auth->confirm)) {
             $fields = array(DAO_AddressAuth::PASS => md5($pass));
             DAO_AddressAuth::update($addy->id, $fields);
         } else {
             $tpl->assign('register_error', sprintf("The confirmation code you entered does not match our records.  Try again."));
             DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'register', 'confirm')));
             return;
         }
     } else {
         $tpl->assign('register_error', sprintf("You must enter a valid e-mail address, confirmation code and desired password to continue."));
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'register', 'confirm')));
         return;
     }
 }
Ejemplo n.º 6
0
 private function _handleImportContact($xml)
 {
     $settings = CerberusSettings::getInstance();
     $logger = DevblocksPlatform::getConsoleLog();
     $sFirstName = (string) $xml->first_name;
     $sLastName = (string) $xml->last_name;
     $sEmail = (string) $xml->email;
     $sPassword = (string) $xml->password;
     $sOrganization = (string) $xml->organization;
     // Dupe check org
     if (null != ($address = DAO_Address::lookupAddress($sEmail))) {
         $logger->info('[Importer] Avoiding creating duplicate contact #' . $address->id . ' (' . $sEmail . ')');
         // [TODO] Still associate with org if local blank?
         // [TODO] Still associate password if local blank?
         return true;
     }
     $fields = array(DAO_Address::FIRST_NAME => $sFirstName, DAO_Address::LAST_NAME => $sLastName, DAO_Address::EMAIL => $sEmail);
     $address_id = DAO_Address::create($fields);
     // Associate SC password
     if (!empty($sPassword) && $sPassword != md5('')) {
         DAO_AddressAuth::update($address_id, array(DAO_AddressAuth::ADDRESS_ID => $address_id, DAO_AddressAuth::CONFIRM => 1, DAO_AddressAuth::PASS => $sPassword));
     }
     // Associate with organization
     if (!empty($sOrganization)) {
         if (null != ($org_id = DAO_ContactOrg::lookup($sOrganization, true))) {
             DAO_Address::update($address_id, array(DAO_Address::CONTACT_ORG_ID => $org_id));
         }
     }
     $logger->info('[Importer] Imported contact #' . $address_id . ' (' . $sEmail . ')');
     return true;
 }
Ejemplo n.º 7
0
 function doLogin()
 {
     $umsession = UmPortalHelper::getSession();
     //		if(!$this->allow_logins)
     //			die();
     @($email = DevblocksPlatform::importGPC($_REQUEST['email']));
     @($pass = DevblocksPlatform::importGPC($_REQUEST['pass']));
     $valid = false;
     // [TODO] Test login combination using the appropriate adapter
     if (null != ($addy = DAO_Address::lookupAddress($email, false))) {
         $auth = DAO_AddressAuth::get($addy->id);
         if (!empty($auth->pass) && md5($pass) == $auth->pass) {
             $valid = true;
             $umsession->setProperty('sc_login', $addy);
         }
     }
     if (!$valid) {
         $umsession->setProperty('sc_login', null);
     }
     DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode())));
 }