/**
  * If the REMOTE_USER is set and is in the Member table, log that member in. If
  * not, and Config::inst()->get('AuthRemoteUserExtension', 'auto_create_user') is set, add that
  * Member to the configured group, and log the new user in. Otherwise, do nothing.
  */
 public function onAfterInit()
 {
     if (isset($_SERVER['REMOTE_USER'])) {
         $unique_identifier = $_SERVER['REMOTE_USER'];
     } elseif (isset($_SERVER['REDIRECT_REMOTE_USER'])) {
         $unique_identifier = $_SERVER['REDIRECT_REMOTE_USER'];
     }
     if (isset($unique_identifier)) {
         $unique_identifier_field = Member::config()->unique_identifier_field;
         $member = Member::get()->filter($unique_identifier_field, $unique_identifier)->first();
         if ($member) {
             $member->logIn();
             $this->owner->redirectBack();
         } elseif (Config::inst()->get('AuthRemoteUserExtension', 'auto_create_user') && strlen(Config::inst()->get('AuthRemoteUserExtension', 'auto_user_group'))) {
             $group = Group::get()->filter('Title', Config::inst()->get('AuthRemoteUserExtension', 'auto_user_group'))->first();
             if ($group) {
                 $member = new Member();
                 $member->{$unique_identifier_field} = $unique_identifier;
                 $member->write();
                 $member->Groups()->add($group);
                 $member->logIn();
             }
         }
     }
 }
 function StartSurvey($data, $form)
 {
     //Check for existing member email address
     if ($member = Member::get()->filter('Email', Convert::raw2sql($data['Email']))->first()) {
         //Set error message
         $form->AddErrorMessage('Email', "Sorry, that email address already exists. Please choose another or login with that email.", 'bad');
         //Set form data from submitted values
         Session::set("FormInfo.Form_DeploymentSurveyRegistrationForm.data", $data);
         //Return back to form
         return Controller::curr()->redirectBack();
     }
     //Otherwise create new member and log them in
     $Member = new Member();
     $form->saveInto($Member);
     $Member->write();
     //Find or create the 'user' group
     if (!($userGroup = Group::get()->filter('Code', 'users')->first())) {
         $userGroup = new Group();
         $userGroup->Code = "users";
         $userGroup->Title = "Users";
         $userGroup->Write();
         $Member->Groups()->add($userGroup);
     }
     //Add member to user group
     $Member->Groups()->add($userGroup);
     $BackURL = Controller::curr()->Link('AboutYou');
     return OpenStackIdCommon::loginMember($Member, $BackURL);
 }
 private function getMembers()
 {
     $filterString = '';
     $members = Member::get('Member', $filterString);
     $search = $this->getRequest()->getVar('search');
     if ($search) {
         $members = $members->filterAny(array('Surname:PartialMatch' => $search, 'Firstname:PartialMatch' => $search, 'Email:PartialMatch' => $search));
         //('SearchFields:fulltext', $search);
     }
     $sort = Convert::raw2sql($this->getRequest()->getVar('sort'));
     if ($sort) {
         if (strlen($sort) > 2) {
             $dir = substr($sort, 0, 1);
             $field = substr($sort, 1);
             if ($field == 'FirstName' || $field == 'LastVisited' || $field == 'Surname' || $field == 'Email') {
                 if ($dir == 'a') {
                     $members = $members->sort(Convert::raw2sql($field) . " ASC");
                 } else {
                     $members = $members->sort(Convert::raw2sql($field) . " DESC");
                 }
             } else {
                 die("Undefined field for sorting");
             }
         }
     }
     return new PaginatedList($members, $this->request);
 }
 function addmembertocartform_add($data, $form)
 {
     $member = Member::currentUser();
     if ($member && $member->IsShopAdmin()) {
         $order = ShoppingCart::current_order();
         $member = Member::get()->byID(intval($data["MemberID"]));
         if ($member) {
             if ($member->ID != $order->MemberID) {
                 $order->MemberID = $member->ID;
                 $order->BillingAddressID = 0;
                 $order->ShippingAddressID = 0;
                 $order->write();
                 $response = $member->getTitle() . " " . _t("AddToCartPage.ADDED", "customer has been added to order.");
                 $status = "good";
             } else {
                 $response = _t("AddToCartPage.NOCHANGE", "The order has not been changed.");
                 $status = "good";
             }
         } else {
             $response = _t("AddToCartPage.CUSTOMERNOTADDED", "Customer could not be added.");
             $status = "bad";
         }
         if (Director::is_ajax()) {
             return $response;
         } else {
             $form->setMessage($response, $status);
             $this->redirectBack();
         }
     }
 }
 /**
  * Template accessors
  * ----------------------------------*/
 public function TeamMembers()
 {
     $team = Member::get()->filterByCallback(function ($item) {
         return $item->inGroup('team-member');
     });
     return $team->count() ? $team : false;
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->removeByName('ProviderClass');
     $fields->removeByName('ProviderSettings');
     $fields->removeByName('Sent');
     $fields->removeByName('SentAt');
     $fields->removeByName('RecipientMembers');
     $fields->removeByName('RecipientGroups');
     $fields->removeByName('SendJobID');
     if ($this->Sent) {
         $fields->insertBefore(new LiteralField('SentAsMessage', sprintf('<p class="message">%s</p>', _t('Push.SENTAT', 'This notification was sent at {at}', array('at' => $this->obj('SentAt')->Nice())))), 'Title');
     }
     if ($this->Sent || !interface_exists('QueuedJob')) {
         $fields->removeByName('ScheduledAt');
     } else {
         $fields->dataFieldByName('ScheduledAt')->getDateField()->setConfig('showcalendar', true);
     }
     $fields->dataFieldByName('Content')->setDescription(_t('Push.USEDMAINBODY', '(Used as the main body of the notification)'));
     if ($this->ID) {
         $fields->addFieldsToTab('Root.Main', array(new CheckboxSetField('RecipientMembers', _t('Push.RECIPIENTMEMBERS', 'Recipient Members'), Member::get()->map()), new TreeMultiselectField('RecipientGroups', _t('Push.RECIPIENTGROUPS', 'Recipient Groups'), 'Group')));
     }
     $fields->addFieldsToTab('Root.Main', array(PushProviderField::create('Provider', _t('Push.PROVIDER', 'Provider'))));
     return $fields;
 }
 function doSave($data, $form)
 {
     if (isset($data['Password']) && is_array($data['Password'])) {
         $data['Password'] = $data['Password']['_Password'];
     }
     // We need to ensure that the unique field is never overwritten
     $uniqueField = Member::get_unique_identifier_field();
     if (isset($data[$uniqueField])) {
         $SQL_unique = Convert::raw2sql($data[$uniqueField]);
         $existingUniqueMember = Member::get()->filter(array($uniqueField => $SQL_unique))->first();
         if ($existingUniqueMember && $existingUniqueMember->exists()) {
             if (Member::currentUserID() != $existingUniqueMember->ID) {
                 die("current member does not match enrolled member.");
                 return false;
             }
         }
     }
     $member = Member::currentUser();
     if (!$member) {
         $member = new Member();
     }
     $member->update($data);
     $member->write();
     $arrayExtraFields = array();
     if (isset($data["SelectedOption"])) {
         $arrayExtraFields["SelectedOption"] = $data["SelectedOption"];
     }
     if (isset($data["BookingCode"])) {
         $arrayExtraFields["BookingCode"] = $data["BookingCode"];
     }
     $this->controller->addAttendee($member, $arrayExtraFields);
     $this->redirect($this->getController()->Link("thankyou"));
     return;
 }
 public function doEdit(array $data)
 {
     if ($Member = Member::get()->byID($data['ID'])) {
         $this->saveInto($Member);
         $Member->changePassword($data['Password']['_Password']);
         $Member->Changed = true;
         $Member->write();
         // find a group with ADMIN permission
         $adminGroup = Group::get()->where("Code='administrators'")->First();
         // Member noch als Administrator festlegen
         if (isset($data['Admin'])) {
             $adminGroup->Members()->add($Member);
         } else {
             $adminGroup->Members()->remove($Member);
         }
         // find a group with ADMIN permission
         $authorGroup = Group::get()->where("Code='content-authors'")->First();
         // Member noch als Administrator festlegen
         if (isset($data['Author'])) {
             $authorGroup->Members()->add($Member);
         } else {
             $authorGroup->Members()->remove($Member);
         }
     }
     $this->controller->redirect('administration/members');
 }
 public function doAdd(array $data)
 {
     if ($Member = Member::get()->filter(array("Email" => $data['Email']))->first()) {
         $this->addErrorMessage('Email', 'Die Emailadresse ist bereits vergeben.', 'bad');
         $this->controller->redirectBack();
         return false;
     }
     $Member = new Member();
     $this->saveInto($Member);
     $Member->write();
     // find a group with ADMIN permission
     $adminGroup = Group::get()->where("Code='administrators'")->First();
     // Member noch als Administrator festlegen
     if (isset($data['Admin'])) {
         $adminGroup->Members()->add($Member);
     } else {
         $adminGroup->Members()->remove($Member);
     }
     // find a group with ADMIN permission
     $authorGroup = Group::get()->where("Code='content-authors'")->First();
     // Member noch als Administrator festlegen
     if (isset($data['Author'])) {
         $authorGroup->Members()->add($Member);
     } else {
         $authorGroup->Members()->remove($Member);
     }
     $this->controller->redirect('administration/members');
 }
 public function getCMSFields()
 {
     $fields = new FieldList(new TabSet('Root'));
     $fields->addFieldToTab('Root.Main', new TextField('Title', $this->fieldLabel('Title')));
     $filter = '';
     $reqParent = isset($_REQUEST['ParentID']) ? (int) $_REQUEST['ParentID'] : 0;
     $attachTo = $this->ActionID ? $this->ActionID : $reqParent;
     if ($attachTo) {
         $action = DataObject::get_by_id('WorkflowAction', $attachTo);
         if ($action && $action->ID) {
             $filter = '"WorkflowDefID" = ' . (int) $action->WorkflowDefID;
         }
     }
     $actions = DataObject::get('WorkflowAction', $filter);
     $options = array();
     if ($actions) {
         $options = $actions->map();
     }
     $defaultAction = $action ? $action->ID : "";
     $typeOptions = array('Active' => _t('WorkflowTransition.Active', 'Active'), 'Passive' => _t('WorkflowTransition.Passive', 'Passive'));
     $fields->addFieldToTab('Root.Main', new DropdownField('ActionID', $this->fieldLabel('ActionID'), $options, $defaultAction));
     $fields->addFieldToTab('Root.Main', $nextActionDropdownField = new DropdownField('NextActionID', $this->fieldLabel('NextActionID'), $options));
     $nextActionDropdownField->setEmptyString(_t('WorkflowTransition.SELECTONE', '(Select one)'));
     $fields->addFieldToTab('Root.Main', new DropdownField('Type', _t('WorkflowTransition.TYPE', 'Type'), $typeOptions));
     $members = Member::get();
     $fields->findOrMakeTab('Root.RestrictToUsers', _t('WorkflowTransition.TabTitle', 'Restrict to users'));
     $fields->addFieldToTab('Root.RestrictToUsers', new CheckboxSetField('Users', _t('WorkflowDefinition.USERS', 'Restrict to Users'), $members));
     $fields->addFieldToTab('Root.RestrictToUsers', new TreeMultiselectField('Groups', _t('WorkflowDefinition.GROUPS', 'Restrict to Groups'), 'Group'));
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->insertBefore(new DropdownField('MemberID', 'Member', Member::get()->map('ID', "FirstName")), 'AttendingWholeEvent');
     $siteConfig = SiteConfig::current_site_config();
     $current = $siteConfig->getCurrentEventID();
     if ($this->ParentID < 1) {
         $event = Event::get()->byID($current);
     } else {
         $event = Event::get()->byID($this->ParentID);
     }
     $fields->insertAfter(HiddenField::create('ParentID', 'Event', $event->ID), 'ExtraDetail');
     $fields->removeByName('PublicFieldsRaw');
     $fields->removeByName('Sort');
     if ($this->PlayerGames()->Count() > 0) {
         $gridField = new GridField('PlayerGames', 'Games', $this->PlayerGames(), $config = GridFieldConfig_RelationEditor::create());
         $gridField->setModelClass('PlayerGame');
         $config->addComponent(new GridFieldOrderableRows());
         $config->removeComponentsByType('GridFieldPaginator');
         $config->removeComponentsByType('GridFieldPageCount');
         $config->addComponent(new GridFieldDeleteAction(false));
         $config->addComponent($export = new GridFieldExportButton('before'));
         $export->setExportColumns(singleton("PlayerGame")->getExportFields());
         $fields->addFieldToTab('Root.PlayerGames', $gridField);
     }
     return $fields;
 }
 public function getCMSFields()
 {
     $fields = new FieldList(new TabSet('Root'));
     $fields->addFieldToTab('Root.Main', new TextField('Title', _t('WorkflowAction.TITLE', 'Title')));
     $filter = '';
     $reqParent = isset($_REQUEST['ParentID']) ? (int) $_REQUEST['ParentID'] : 0;
     $attachTo = $this->ActionID ? $this->ActionID : $reqParent;
     if ($attachTo) {
         $action = DataObject::get_by_id('WorkflowAction', $attachTo);
         if ($action && $action->ID) {
             $filter = '"WorkflowDefID" = ' . (int) $action->WorkflowDefID;
         }
     }
     $actions = DataObject::get('WorkflowAction', $filter);
     $options = array();
     if ($actions) {
         $options = $actions->map();
     }
     $typeOptions = $this->dbObject('Type')->enumValues();
     $fields->addFieldToTab('Root.Main', new DropdownField('ActionID', _t('WorkflowTransition.ACTION', 'Action'), $options));
     $fields->addFieldToTab('Root.Main', new DropdownField('NextActionID', _t('WorkflowTransition.NEXT_ACTION', 'Next Action'), $options, null, null, _t('WorkflowTransition.SELECTONE', '(Select one)')));
     $fields->addFieldToTab('Root.Main', new DropdownField('Type', _t('WorkflowTransition.TYPE', 'Type'), $typeOptions));
     $members = Member::get();
     $fields->addFieldToTab('Root.RestrictToUsers', new CheckboxSetField('Users', _t('WorkflowDefinition.USERS', 'Restrict to Users'), $members));
     $fields->addFieldToTab('Root.RestrictToUsers', new TreeMultiselectField('Groups', _t('WorkflowDefinition.GROUPS', 'Restrict to Groups'), 'Group'));
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
Beispiel #13
0
 public function Register($data, Form $form)
 {
     if (!Member::currentUser()) {
         $member = new Member();
         // Debug::show($form);
         $form->saveInto($member);
         if (Group::get()->filter('Title', 'Subscribed')->count() == 0) {
             $group = Group::create();
             $group->Title = 'Subscribed';
             $group->write();
         } else {
             $group = Group::get()->filter('Title', 'Subscribed')->First();
         }
         if (Member::get()->filter('Email', $data['Email'])) {
             $form->addErrorMessage('Email', 'That email address is already in use. <a href="Security/login">login</a>', 'bad', true, true);
             //Controller::curr()->redirect('register');
         } else {
             //has to be called before setting group
             $member->write();
             if (!$member->inGroup($group)) {
                 $member->Groups()->add($group);
             }
         }
     }
     Controller::curr()->redirectBack();
 }
 /**
  * @param array $pull_request_data
  * @throws NonFoundationMemberException
  * @throws NotFoundEntityException
  * @throws NonSignedCLAFoundationMemberException
  */
 public function validatePullRequest(array $pull_request_data)
 {
     //get sender user
     if (isset($pull_request_data['user']) && ($sender = $pull_request_data['user'])) {
         $user_name = $sender['login'];
         //get user email from api
         // https://api.github.com/users/:user_name
         $client = new \Github\Client();
         $user = $client->api('user')->show($user_name);
         if ($user != null && isset($user['email']) && ($user_email = $user['email'])) {
             //check if exist on db
             $member = Member::get()->filter('Email', $user_email)->first();
             if (!$member) {
                 $this->rejectPullRequest($pull_request_data, self::NON_MEMBER_REJECT_REASON);
                 throw new NotFoundEntityException('Member', sprintf('user email %s does not exists!', $user_email));
             }
             if (!$member->isFoundationMember()) {
                 //reject pull request
                 $this->rejectPullRequest($pull_request_data, self::NON_FOUNDATION_MEMBER_REJECT_REASON);
                 throw new NonFoundationMemberException($user_email);
             }
             if (!$member->hasSignedCLA()) {
                 //reject pull request
                 $this->rejectPullRequest($pull_request_data, self::NON_SIGNED_CLA_REJECT_REASON);
                 throw new NonSignedCLAFoundationMemberException($user_email);
             }
         }
     }
 }
 /**
  * Show the member edit page
  *
  * @return string Returns the member edit page as HTML code.
  */
 public function memberEdit()
 {
     if ($Member = Member::get()->byID($this->request->param('ID'))) {
         $GLOBALS['MemberID'] = $Member->ID;
     }
     return $this->customise(new ArrayData(array("Title" => _t('AdminMemberEdit.TITLE', 'AdminMemberEdit.TITLE'), "Form" => $this->MemberEditForm(), "Member" => $Member)))->renderWith(array('Administration_memberedit', 'Administration', $this->stat('template_main'), $this->stat('template')));
 }
 public function parseOrderCustomer($orders, $transaction)
 {
     foreach ($orders->transactions->transaction as $order) {
         // if not a guest transaction in FoxyCart
         if (isset($order->customer_email) && $order->is_anonymous == 0) {
             // if Customer is existing member, associate with current order
             if (Member::get()->filter('Email', $order->customer_email)->First()) {
                 $customer = Member::get()->filter('Email', $order->customer_email)->First();
             } else {
                 // set PasswordEncryption to 'none' so imported, encrypted password is not encrypted again
                 Config::inst()->update('Security', 'password_encryption_algorithm', 'none');
                 // create new Member, set password info from FoxyCart
                 $customer = Member::create();
                 $customer->Customer_ID = (int) $order->customer_id;
                 $customer->FirstName = (string) $order->customer_first_name;
                 $customer->Surname = (string) $order->customer_last_name;
                 $customer->Email = (string) $order->customer_email;
                 $customer->Password = (string) $order->customer_password;
                 $customer->Salt = (string) $order->customer_password_salt;
                 $customer->PasswordEncryption = 'none';
                 // record member record
                 $customer->write();
             }
             // set Order MemberID
             $transaction->MemberID = $customer->ID;
         }
     }
 }
 public function getEditForm($id = null, $fields = null)
 {
     // TODO Duplicate record fetching (see parent implementation)
     if (!$id) {
         $id = $this->currentPageID();
     }
     $form = parent::getEditForm($id);
     // TODO Duplicate record fetching (see parent implementation)
     $record = $this->getRecord($id);
     if ($record && !$record->canView()) {
         return Security::permissionFailure($this);
     }
     $memberList = GridField::create('Members', false, Member::get(), $memberListConfig = GridFieldConfig_RecordEditor::create()->addComponent(new GridFieldButtonRow('after'))->addComponent(new GridFieldExportButton('buttons-after-left')))->addExtraClass("members_grid");
     if ($record && method_exists($record, 'getValidator')) {
         $validator = $record->getValidator();
     } else {
         $validator = Injector::inst()->get('Member')->getValidator();
     }
     $memberListConfig->getComponentByType('GridFieldDetailForm')->setValidator($validator);
     $groupList = GridField::create('Groups', false, Group::get(), GridFieldConfig_RecordEditor::create());
     $columns = $groupList->getConfig()->getComponentByType('GridFieldDataColumns');
     $columns->setDisplayFields(array('Breadcrumbs' => singleton('Group')->fieldLabel('Title')));
     $columns->setFieldFormatting(array('Breadcrumbs' => function ($val, $item) {
         return Convert::raw2xml($item->getBreadcrumbs(' > '));
     }));
     $fields = new FieldList($root = new TabSet('Root', $usersTab = new Tab('Users', _t('SecurityAdmin.Users', 'Users'), $memberList, new LiteralField('MembersCautionText', sprintf('<p class="caution-remove"><strong>%s</strong></p>', _t('SecurityAdmin.MemberListCaution', 'Caution: Removing members from this list will remove them from all groups and the' . ' database')))), $groupsTab = new Tab('Groups', singleton('Group')->i18n_plural_name(), $groupList)), new HiddenField('ID', false, 0));
     // Add import capabilities. Limit to admin since the import logic can affect assigned permissions
     if (Permission::check('ADMIN')) {
         $fields->addFieldsToTab('Root.Users', array(new HeaderField(_t('SecurityAdmin.IMPORTUSERS', 'Import users'), 3), new LiteralField('MemberImportFormIframe', sprintf('<iframe src="%s" id="MemberImportFormIframe" width="100%%" height="250px" frameBorder="0">' . '</iframe>', $this->Link('memberimport')))));
         $fields->addFieldsToTab('Root.Groups', array(new HeaderField(_t('SecurityAdmin.IMPORTGROUPS', 'Import groups'), 3), new LiteralField('GroupImportFormIframe', sprintf('<iframe src="%s" id="GroupImportFormIframe" width="100%%" height="250px" frameBorder="0">' . '</iframe>', $this->Link('groupimport')))));
     }
     // Tab nav in CMS is rendered through separate template
     $root->setTemplate('CMSTabSet');
     // Add roles editing interface
     if (Permission::check('APPLY_ROLES')) {
         $rolesField = GridField::create('Roles', false, PermissionRole::get(), GridFieldConfig_RecordEditor::create());
         $rolesTab = $fields->findOrMakeTab('Root.Roles', _t('SecurityAdmin.TABROLES', 'Roles'));
         $rolesTab->push($rolesField);
     }
     $actionParam = $this->getRequest()->param('Action');
     if ($actionParam == 'groups') {
         $groupsTab->addExtraClass('ui-state-active');
     } elseif ($actionParam == 'users') {
         $usersTab->addExtraClass('ui-state-active');
     } elseif ($actionParam == 'roles') {
         $rolesTab->addExtraClass('ui-state-active');
     }
     $actions = new FieldList();
     $form = Form::create($this, 'EditForm', $fields, $actions)->setHTMLID('Form_EditForm');
     $form->addExtraClass('cms-edit-form');
     $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
     // Tab nav in CMS is rendered through separate template
     if ($form->Fields()->hasTabset()) {
         $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
     }
     $form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses());
     $form->setAttribute('data-pjax-fragment', 'CurrentForm');
     $this->extend('updateEditForm', $form);
     return $form;
 }
 /**
  * Creates a user in the database
  * @param {stdClass} $data Data passed from ActionScript
  * @return {array} Returns a standard response array
  */
 public function createUser($data)
 {
     $response = CodeBank_ClientAPI::responseBase();
     try {
         if (Member::get()->filter('Email', Convert::raw2sql($data->username))->count() > 0) {
             $response['status'] = 'EROR';
             $response['message'] = _t('CodeBankAPI.EMAIL_EXISTS', '_An account with that email already exists');
             return $response;
         }
         //Create and write member
         $member = new Member();
         $member->FirstName = !empty($data->firstname) ? $data->firstname : $data->username;
         $member->Surname = !empty($data->surname) ? $data->surname : null;
         $member->Email = $data->username;
         $member->Password = $data->Password;
         $member->UseHeartbeat = 0;
         if (!$member->validate()) {
             $response['status'] = 'EROR';
             $response['message'] = _t('CodeBankAPI.PASSWORD_NOT_VALID', '_Password is not valid');
             return $response;
         }
         $member->write();
         $response['status'] = 'HELO';
         $response['message'] = "User added successfully";
     } catch (Exception $e) {
         $response['status'] = 'EROR';
         $response['message'] = _t('CodeBankAPI.SERVER_ERROR', '_Server error has occured, please try again later');
     }
     return $response;
 }
 public function connect()
 {
     if (!($member = Member::currentUser())) {
         /** @var stdClass $params */
         $params = $this->getAccessToken($this->request->getVar('code'));
         // member is not currently logged into SilverStripe. Look up
         // for a member with the UID which matches first.
         $member = Member::get()->filter(array("VkUID" => $params->user_id))->first();
         if (!$member) {
             // see if we have a match based on email. From a
             // security point of view, users have to confirm their
             // email address in facebook so doing a match up is fine
             $email = $params->email;
             if ($email) {
                 $member = Member::get()->filter(array('Email' => $email))->first();
             }
         }
         if (!$member) {
             $member = Injector::inst()->create('Member');
             $member->syncVkDetails($this->getUserInfo());
         }
     }
     $member->logIn(true);
     // redirect the user to the provided url, otherwise take them
     // back to the route of the website.
     if ($url = Session::get(VkControllerExtension::SESSION_REDIRECT_URL_FLAG)) {
         return $this->redirect($url);
     } else {
         return $this->redirect(Director::absoluteBaseUrl());
     }
 }
 /**
  * @covers GridFieldDataColumns::setDisplayFields
  * @covers GridFieldDataColumns::getDisplayFields
  */
 public function testGridFieldDisplayFieldsWithBadArguments()
 {
     $this->setExpectedException('InvalidArgumentException');
     $obj = new GridField('testfield', 'testfield', Member::get());
     $columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
     $columns->setDisplayFields(new stdClass());
 }
 function run($request)
 {
     $customerGroup = EcommerceRole::get_customer_group();
     if ($customerGroup) {
         $allCombos = DB::query("\n\t\t\t\tSELECT \"Group_Members\".\"ID\", \"Group_Members\".\"MemberID\", \"Group_Members\".\"GroupID\"\n\t\t\t\tFROM \"Group_Members\"\n\t\t\t\tWHERE \"Group_Members\".\"GroupID\" = " . $customerGroup->ID . ";");
         //make an array of all combos
         $alreadyAdded = array();
         $alreadyAdded[-1] = -1;
         if ($allCombos) {
             foreach ($allCombos as $combo) {
                 $alreadyAdded[$combo["MemberID"]] = $combo["MemberID"];
             }
         }
         $unlistedMembers = Member::get()->exclude(array("ID" => $alreadyAdded))->innerJoin("Order", "\"Order\".\"MemberID\" = \"Member\".\"ID\"");
         //add combos
         if ($unlistedMembers->count()) {
             $existingMembers = $customerGroup->Members();
             foreach ($unlistedMembers as $member) {
                 $existingMembers->add($member);
                 DB::alteration_message("Added member to customers: " . $member->Email, "created");
             }
         }
     } else {
         DB::alteration_message("NO customer group found", "deleted");
     }
 }
 /**
  * 
  * @param SS_HTTPRequest $request
  */
 public function run($request)
 {
     increase_time_limit_to();
     echo 'Pass ?refresh=1 to refresh your members<br/>';
     echo '<hr/>';
     $refresh = $request->getVar('refresh');
     if ($refresh) {
         DB::alteration_message("Resetting all members location");
         DB::query('UPDATE Member SET Latitude = 0, Longitude = 0');
     }
     $Members = Member::get()->filter(array('Latitude' => 0));
     foreach ($Members as $Member) {
         DB::alteration_message('Processing member #' . $Member->ID . ' - ' . $Member->getTitle());
         if (!$Member->Latitude) {
             if ($Member->canBeGeolocalized()) {
                 DB::alteration_message($Member->GeocodeText());
                 if (!$Member->CountryCode) {
                     DB::alteration_message("Warning ! This member has no country code", "error");
                 }
                 /* @var $res Geocoder\Model\Address */
                 $res = $Member->Geocode();
                 if ($res) {
                     DB::alteration_message('Geocode success on ' . $res->getLatitude() . ',' . $res->getLongitude() . ' : ' . $res->getStreetNumber() . ', ' . $res->getStreetName() . ' ' . $res->getPostalCode() . ' ' . $res->getLocality() . ' ' . $res->getCountry(), 'created');
                     $Member->write();
                 } else {
                     DB::alteration_message('Geocode error', 'error');
                 }
             } else {
                 DB::alteration_message('Cannot be geolocalized', 'error');
             }
         } else {
             DB::alteration_message('Already geolocalized', 'error');
         }
     }
 }
Beispiel #23
0
 public function doApprove()
 {
     $exist = Member::get()->filter(array('Email' => $this->Email))->first();
     if ($exist) {
         return false;
     }
     $member = new Member();
     $data = $this->toMap();
     unset($data['ID']);
     unset($data['ClassName']);
     unset($data['UnapprovedMember']);
     $member->update($data);
     $member->write();
     if ($this->MemberType === 'Organization') {
         $member->addToGroupByCode('organization');
         $organization = new Organization();
         $organization->AccountID = $member->ID;
         $organization->company_name = $this->OrganizationName;
         $organizationID = $organization->write();
         $member->OrganizationID = $organizationID;
         $member->write();
     } else {
         $member->addToGroupByCode('personal');
     }
     $this->setField('Approved', true);
     $this->write();
     return true;
 }
 /**
  * @param \SS_HTTPRequest $request
  * @return \SS_HTTPResponse
  */
 public function submit(\SS_HTTPRequest $request)
 {
     if ($request->httpMethod() !== 'POST') {
         return $this->getAPIResponse(['message' => 'Method not allowed, requires POST'], 405);
     }
     $this->checkSecurityToken();
     $deployment = \DNDeployment::get()->byId($request->postVar('id'));
     $errorResponse = $this->validateDeployment($deployment);
     if ($errorResponse instanceof \SS_HTTPResponse) {
         return $errorResponse;
     }
     $approver = \Member::get()->byId($request->postVar('approver_id'));
     if ($approver && $approver->exists()) {
         if (!self::can_approve($this->environment, $approver)) {
             return $this->getAPIResponse(['message' => 'The given approver does not have permissions to approve'], 403);
         }
         $deployment->ApproverID = $approver->ID;
     }
     // title and summary may have changed, ensure they are saved
     if ($request->postVar('title')) {
         $deployment->Title = $request->postVar('title');
     }
     if ($request->postVar('summary')) {
         $deployment->Summary = $request->postVar('summary');
     }
     try {
         $deployment->getMachine()->apply(\DNDeployment::TR_SUBMIT);
     } catch (\Exception $e) {
         return $this->getAPIResponse(['message' => $e->getMessage()], 400);
     }
     return $this->getAPIResponse(['message' => 'Deployment request has been submitted', 'deployment' => $this->formatter->getDeploymentData($deployment)], 200);
 }
 public function onBeforeWrite()
 {
     if ($this->owner->BaseClass == "Discussion" && $this->owner->ID == 0) {
         $discussion = Discussion::get()->byID($this->owner->ParentID);
         $discussion_author = $discussion->Author();
         $holder = $discussion->Parent();
         $author = Member::get()->byID($this->owner->AuthorID);
         // Get our default email from address
         if (DiscussionHolder::config()->send_emails_from) {
             $from = DiscussionHolder::config()->send_email_from;
         } else {
             $from = Email::config()->admin_email;
         }
         // Vars for the emails
         $vars = array("Title" => $discussion->Title, "Author" => $author, "Comment" => $this->owner->Comment, 'Link' => Controller::join_links($holder->Link("view"), $discussion->ID, "#comments-holder"));
         // Send email to discussion owner
         if ($discussion_author && $discussion_author->Email && $discussion_author->RecieveCommentEmails && $discussion_author->ID != $this->owner->AuthorID) {
             $subject = _t("Discussions.NewCreatedReplySubject", "{Nickname} replied to your discussion", null, array("Nickname" => $author->Nickname));
             $email = new Email($from, $discussion_author->Email, $subject);
             $email->setTemplate('NewCreatedReplyEmail');
             $email->populateTemplate($vars);
             $email->send();
         }
         // Send to anyone who liked this, if they want notifications
         foreach ($discussion->LikedBy() as $liked) {
             if ($liked->RecieveLikedReplyEmails && $liked->Email && $liked->ID != $author->ID) {
                 $subject = _t("Discussions.NewLikedReplySubject", "{Nickname} replied to your liked discussion", null, array("Nickname" => $author->Nickname));
                 $email = new Email($from, $liked->Email, $subject);
                 $email->setTemplate('NewLikedReplyEmail');
                 $email->populateTemplate($vars);
                 $email->send();
             }
         }
     }
 }
 /**
  * This page can only be seen by logged in users
  * This feature could be enhanced (e.g. only allowing for certain groups)
  * by subclassing this page
  * @param Member
  * @return boolean
  */
 public function canView($member = null)
 {
     $o = $this->owner;
     //strangely it seems that the member is passed as int sometimes?
     //these lines should fix that
     if (is_int($member)) {
         $member = Member::get()->filter('ID', $member)->first();
     }
     if (!$member) {
         $member = Member::currentUser();
     }
     if ($member) {
         if ($groups = $o->DictatedViewerGroups()) {
             //if specific viewer groups have been defined, we'll
             //only give access to thos groups
             return $member->inGroups($groups);
         } else {
             //if no specific viewer groups ahve been defined,
             //we'll give access to all logged in users
             return true;
         }
     } else {
         return false;
     }
 }
 /**
  * Performs the login, but will also create and sync the Member record on-the-fly, if not found.
  *
  * @param array $data
  * @param Form $form
  * @return bool|Member|void
  * @throws SS_HTTPResponse_Exception
  */
 public static function authenticate($data, Form $form = null)
 {
     $service = Injector::inst()->get('LDAPService');
     $result = $service->authenticate($data['Username'], $data['Password']);
     $success = $result['success'] === true;
     if (!$success) {
         if ($form) {
             $form->sessionMessage($result['message'], 'bad');
         }
         return;
     }
     $data = $service->getUserByUsername($result['identity']);
     if (!$data) {
         if ($form) {
             $form->sessionMessage(_t('LDAPAuthenticator.PROBLEMFINDINGDATA', 'There was a problem retrieving your user data'), 'bad');
         }
         return;
     }
     // LDAPMemberExtension::memberLoggedIn() will update any other AD attributes mapped to Member fields
     $member = Member::get()->filter('GUID', $data['objectguid'])->limit(1)->first();
     if (!($member && $member->exists())) {
         $member = new Member();
         $member->GUID = $data['objectguid'];
         $member->write();
     }
     Session::clear('BackURL');
     return $member;
 }
 /**
  * Attempt to find and authenticate member if possible from the given data.
  *
  * @param array $data
  * @param Form $form
  * @param bool &$success Success flag
  * @return Member Found member, regardless of successful login
  * @see MemberAuthenticator::authenticate_member()
  */
 protected static function authenticate_member($data, $form, &$success)
 {
     // Default success to false
     $success = false;
     // Attempt to identify by temporary ID
     $member = null;
     $email = null;
     if (!empty($data['tempid'])) {
         // Find user by tempid, in case they are re-validating an existing session
         $member = Member::member_from_tempid($data['tempid']);
         if ($member) {
             $email = $member->Email;
         }
     }
     // Otherwise, get email from posted value instead
     if (!$member && !empty($data['Email'])) {
         $email = $data['Email'];
     }
     // Check default login (see Security::setDefaultAdmin()) the standard way and the "extension"-way :-)
     $asDefaultAdmin = $email === Security::default_admin_username();
     if ($asDefaultAdmin || isset($GLOBALS['_DEFAULT_ADMINS']) && array_key_exists($email, $GLOBALS['_DEFAULT_ADMINS'])) {
         // If logging is as default admin, ensure record is setup correctly
         $member = Member::default_admin();
         $success = Security::check_default_admin($email, $data['Password']);
         // If not already true check if one of the extra admins match
         if (!$success) {
             $success = $GLOBALS['_DEFAULT_ADMINS'][$email] == $data['Password'];
         }
         if ($success) {
             return $member;
         }
     }
     // Attempt to identify user by email
     if (!$member && $email) {
         // Find user by email
         $member = Member::get()->filter(Member::config()->unique_identifier_field, $email)->first();
     }
     // Validate against member if possible
     if ($member && !$asDefaultAdmin) {
         $result = $member->checkPassword($data['Password']);
         $success = $result->valid();
     } else {
         $result = new ValidationResult(false, _t('Member.ERRORWRONGCRED'));
     }
     // Emit failure to member and form (if available)
     if (!$success) {
         if ($member) {
             $member->registerFailedLogin();
         }
         if ($form) {
             $form->sessionMessage($result->message(), 'bad');
         }
     } else {
         if ($member) {
             $member->registerSuccessfulLogin();
         }
     }
     return $member;
 }
 /**
  * @param string $email_verification_token
  * @return Member|null
  */
 public function getByEmailVerificationToken($email_verification_token)
 {
     $member = Member::get()->filter('EmailVerifiedTokenHash', MemberDecorator::HashConfirmationToken($email_verification_token))->first();
     if (!is_null($member)) {
         UnitOfWork::getInstance()->scheduleForUpdate($member);
     }
     return $member;
 }
 /** 
  * Action to emulate a specific user
  * @param $request = HTTPRequest
  * @return redirect
  **/
 public function emulateuser($request)
 {
     Requirements::clear();
     Requirements::css(DEVTOOLS_DIR . '/css/dev-tools.css');
     // not enabled, or not allowed >> get out
     if (!$this->CanEmulateUser()) {
         echo 'You cannot do that';
         die;
     }
     // get URL parameters
     $params = $this->owner->getRequest()->params();
     // URL attribute?
     if (!isset($params['ID'])) {
         $members = Member::get();
         $membersList = array();
         foreach ($members as $member) {
             $membersList[$member->ID] = $member;
         }
         $membersList = ArrayList::create($membersList);
         $membersList = PaginatedList::create($membersList, $this->owner->getRequest());
         $membersList->setPageLength(20);
         return $this->owner->customise(array('Users' => $membersList))->renderWith('EmulateUserPage');
     }
     $member = Member::get()->byID($params['ID']);
     if (!isset($member->ID)) {
         echo 'Could not find user by #' . $params['ID'];
         die;
     }
     $member->logIn();
     return $this->owner->redirect($this->owner->Link());
 }