public function testCleartextPasswordsAreHashedWithDefaultAlgo()
 {
     $loader = new MemberCsvBulkLoader();
     $results = $loader->load($this->getCurrentRelativePath() . '/MemberCsvBulkLoaderTest_cleartextpws.csv');
     $member = $results->Created()->First();
     $memberID = $member->ID;
     DataObject::flush_and_destroy_cache();
     $member = DataObject::get_by_id('Member', $memberID);
     // TODO Direct getter doesn't work, wtf!
     $this->assertEquals(Security::config()->password_encryption_algorithm, $member->getField('PasswordEncryption'));
     $result = $member->checkPassword('mypassword');
     $this->assertTrue($result->valid());
 }
 public function doImport($data, $form)
 {
     $loader = new MemberCsvBulkLoader();
     // optionally set group relation
     if ($this->group) {
         $loader->setGroups(array($this->group));
     }
     // load file
     $result = $loader->load($data['CsvFile']['tmp_name']);
     // result message
     $msgArr = array();
     if ($result->CreatedCount()) {
         $msgArr[] = _t('MemberImportForm.ResultCreated', 'Created {count} members', array('count' => $result->CreatedCount()));
     }
     if ($result->UpdatedCount()) {
         $msgArr[] = _t('MemberImportForm.ResultUpdated', 'Updated {count} members', array('count' => $result->UpdatedCount()));
     }
     if ($result->DeletedCount()) {
         $msgArr[] = _t('MemberImportForm.ResultDeleted', 'Deleted %d members', array('count' => $result->DeletedCount()));
     }
     $msg = $msgArr ? implode(',', $msgArr) : _t('MemberImportForm.ResultNone', 'No changes');
     $this->sessionMessage($msg, 'good');
     $this->controller->redirectBack();
 }
 public function __construct($controller, $name, $fields = null, $actions = null, $validator = null)
 {
     if (!$fields) {
         $helpHtml = _t('ExcelMemberImportForm.Help1', '<p><a href="{link}">Download sample file</a></p>', array('link' => $controller->Link('downloadsample/Member')));
         $helpHtml .= _t('ExcelMemberImportForm.Help2', '<ul>' . '<li>Existing users are matched by their unique <em>Email</em> property, and updated with any new values from ' . 'the imported file.</li>' . '<li>Groups can be assigned by the <em>Groups</em> column. Groups are identified by their <em>Code</em> property, ' . 'multiple groups can be separated by comma. Existing group memberships are not cleared.</li>' . '</ul>');
         $importer = new MemberCsvBulkLoader();
         $importSpec = $importer->getImportSpec();
         $helpHtml = sprintf($helpHtml, implode(', ', array_keys($importSpec['fields'])));
         $extensions = array('csv', 'xls', 'xlsx', 'ods', 'txt');
         $fields = new FieldList(new LiteralField('Help', $helpHtml), $fileField = new FileField('File', _t('ExcelMemberImportForm.FileFieldLabel', 'File <small><br/>(allowed extensions: {extensions})</small>', array('extensions' => implode(', ', $extensions)))));
         $fileField->getValidator()->setAllowedExtensions(ExcelImportExport::getValidExtensions());
     }
     if (!$actions) {
         $action = new FormAction('doImport', _t('ExcelMemberImportForm.BtnImport', 'Import from file'));
         $action->addExtraClass('ss-ui-button');
         $actions = new FieldList($action);
     }
     if (!$validator) {
         $validator = new RequiredFields('File');
     }
     parent::__construct($controller, $name, $fields, $actions, $validator);
     $this->addExtraClass('cms');
     $this->addExtraClass('import-form');
 }
 public function processRecord($record, $columnMap, &$results, $preview = false)
 {
     $skip = false;
     $this->extend('preprocess', $record, $columnMap, $results, $preview, $skip);
     if ($skip) {
         return 0;
     }
     $id = parent::processRecord($record, $columnMap, $results, $preview);
     if ($member = Member::get()->byID($id)) {
         $this->extend('postprocess', $member, $record, $columnMap, $results, $preview);
         //callback for doing other custom stuff
         $member->write();
         $member->destroy();
         unset($member);
     }
     return $id;
 }