当前位置: 首页>>代码示例>>PHP>>正文


PHP MemberModel::findByPk方法代码示例

本文整理汇总了PHP中MemberModel::findByPk方法的典型用法代码示例。如果您正苦于以下问题:PHP MemberModel::findByPk方法的具体用法?PHP MemberModel::findByPk怎么用?PHP MemberModel::findByPk使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MemberModel的用法示例。


在下文中一共展示了MemberModel::findByPk方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onSubmitCallback

 protected function onSubmitCallback(\DataContainer $dc)
 {
     // HOOK: send insert ID and user data
     if (isset($GLOBALS['TL_HOOKS']['preRegistration']) && is_array($GLOBALS['TL_HOOKS']['preRegistration'])) {
         foreach ($GLOBALS['TL_HOOKS']['preRegistration'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($dc->activeRecord->id, $dc->activeRecord, $this->objModule);
         }
     }
     $objMember = \MemberModel::findByPk($dc->activeRecord->id);
     $objMember->login = $this->objModule->reg_allowLogin;
     $objMember->activation = md5(uniqid(mt_rand(), true));
     $objMember->dateAdded = $dc->activeRecord->tstamp;
     // Set default groups
     if (empty($objMember->groups)) {
         $objMember->groups = $this->objModule->reg_groups;
     }
     // Disable account
     $objMember->disable = 1;
     $objMember->save();
     if ($this->objModule->reg_activate_plus) {
         $this->formHybridSendConfirmationViaEmail = true;
     }
     // HOOK: send insert ID and user data
     if (isset($GLOBALS['TL_HOOKS']['createNewUser']) && is_array($GLOBALS['TL_HOOKS']['createNewUser'])) {
         foreach ($GLOBALS['TL_HOOKS']['createNewUser'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($objMember->id, $objMember->row(), $this->objModule);
         }
     }
     //		$this->setReset(false); // debug - stay on current page
 }
开发者ID:heimrichhannot,项目名称:contao-member_plus,代码行数:32,代码来源:MemberRegistrationPlusForm.php

示例2: sendPasswordLink

 /**
  * Send a lost password e-mail
  * @param object
  */
 protected function sendPasswordLink($objMember)
 {
     $objNotification = \NotificationCenter\Model\Notification::findByPk($this->nc_notification);
     if ($objNotification === null) {
         $this->log('The notification was not found ID ' . $this->nc_notification, __METHOD__, TL_ERROR);
         return;
     }
     $confirmationId = md5(uniqid(mt_rand(), true));
     // Store the confirmation ID
     $objMember = \MemberModel::findByPk($objMember->id);
     $objMember->activation = $confirmationId;
     $objMember->save();
     $arrTokens = array();
     // Add member tokens
     foreach ($objMember->row() as $k => $v) {
         $arrTokens['member_' . $k] = $v;
     }
     $arrTokens['recipient_email'] = $objMember->email;
     $arrTokens['domain'] = \Idna::decode(\Environment::get('host'));
     $arrTokens['link'] = \Idna::decode(\Environment::get('base')) . \Environment::get('request') . ($GLOBALS['TL_CONFIG']['disableAlias'] || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $confirmationId;
     $objNotification->send($arrTokens);
     $this->log('A new password has been requested for user ID ' . $objMember->id . ' (' . $objMember->email . ')', __METHOD__, TL_ACCESS);
     // Check whether there is a jumpTo page
     if (($objJumpTo = $this->objModel->getRelated('jumpTo')) !== null) {
         $this->jumpToOrReload($objJumpTo->row());
     }
     $this->reload();
 }
开发者ID:seaneble,项目名称:contao-notification_center,代码行数:32,代码来源:ModulePasswordNotificationCenter.php

示例3: getMember

 /**
  * Get the member avatar
  * @param integer
  * @param integer
  * @param integer
  * @return string
  */
 public static function getMember($intId, $intWidth = null, $intHeight = null)
 {
     $objMember = \MemberModel::findByPk($intId);
     // Use the default size
     if (!$intWidth || !$intHeight) {
         list($intWidth, $intHeight) = static::getMemberSize();
     }
     // Use the Gravatar
     if ($objMember->avatar_gravatar) {
         return static::getGravatar($objMember->email, $intWidth);
     }
     $strFile = static::find($intId, static::getMemberPath());
     // Use placeholder member has no avatar
     if ($strFile == '') {
         if (\Config::get('avatar_member_placeholder') == '') {
             return '';
         }
         $objFile = \FilesModel::findByUuid(\Config::get('avatar_member_placeholder'));
         if ($objFile === null || !is_file(TL_ROOT . '/' . $objFile->path)) {
             return '';
         }
         $strFile = $objFile->path;
     }
     return \Image::get($strFile, $intWidth, $intHeight);
 }
开发者ID:terminal42,项目名称:contao-avatar,代码行数:32,代码来源:Avatar.php

示例4: compile

 /**
  * Generate the module
  */
 protected function compile()
 {
     $this->import('FrontendUser', 'User');
     // Initialize the password widget
     $arrField = array('name' => 'password', 'inputType' => 'text', 'label' => $GLOBALS['TL_LANG']['MSC']['password'][0], 'eval' => array('hideInput' => true, 'mandatory' => true, 'required' => true, 'tableless' => $this->tableless));
     $objWidget = new \FormTextField(\FormTextField::getAttributesFromDca($arrField, $arrField['name']));
     $objWidget->rowClass = 'row_0 row_first even';
     // Validate widget
     if (\Input::post('FORM_SUBMIT') == 'tl_close_account') {
         $objWidget->validate();
         // Validate the password
         if (!$objWidget->hasErrors()) {
             // The password has been generated with crypt()
             if (\Encryption::test($this->User->password)) {
                 $blnAuthenticated = \Encryption::verify($objWidget->value, $this->User->password);
             } else {
                 list($strPassword, $strSalt) = explode(':', $this->User->password);
                 $blnAuthenticated = $strSalt == '' ? $strPassword === sha1($objWidget->value) : $strPassword === sha1($strSalt . $objWidget->value);
             }
             if (!$blnAuthenticated) {
                 $objWidget->value = '';
                 $objWidget->addError($GLOBALS['TL_LANG']['ERR']['invalidPass']);
             }
         }
         // Close account
         if (!$objWidget->hasErrors()) {
             // HOOK: send account ID
             if (isset($GLOBALS['TL_HOOKS']['closeAccount']) && is_array($GLOBALS['TL_HOOKS']['closeAccount'])) {
                 foreach ($GLOBALS['TL_HOOKS']['closeAccount'] as $callback) {
                     $this->import($callback[0]);
                     $this->{$callback}[0]->{$callback}[1]($this->User->id, $this->reg_close, $this);
                 }
             }
             $objMember = \MemberModel::findByPk($this->User->id);
             // Remove the account
             if ($this->reg_close == 'close_delete') {
                 $objMember->delete();
                 $this->log('User account ID ' . $this->User->id . ' (' . $this->User->email . ') has been deleted', __METHOD__, TL_ACCESS);
             } else {
                 $objMember->disable = 1;
                 $objMember->tstamp = time();
                 $objMember->save();
                 $this->log('User account ID ' . $this->User->id . ' (' . $this->User->email . ') has been deactivated', __METHOD__, TL_ACCESS);
             }
             $this->User->logout();
             // Check whether there is a jumpTo page
             if (($objJumpTo = $this->objModel->getRelated('jumpTo')) !== null) {
                 $this->jumpToOrReload($objJumpTo->row());
             }
             $this->reload();
         }
     }
     $this->Template->fields = $objWidget->parse();
     $this->Template->formId = 'tl_close_account';
     $this->Template->action = \Environment::get('indexFreeRequest');
     $this->Template->slabel = specialchars($GLOBALS['TL_LANG']['MSC']['closeAccount']);
     $this->Template->rowLast = 'row_1 row_last odd';
     $this->Template->tableless = $this->tableless;
 }
开发者ID:Jobu,项目名称:core,代码行数:62,代码来源:ModuleCloseAccount.php

示例5: compile

 /**
  * Generate the module
  */
 protected function compile()
 {
     // add miscellaneous vars to the template
     $this->addTemplateVars();
     // get href for the detail-page
     $objDetailPage = \PageModel::findWithDetails($this->detailPage);
     if ($objDetailPage === NULL) {
         $href = NULL;
     } else {
         $href = $this->generateFrontendUrl($objDetailPage->row(), \Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/member/%s', $objDetailPage->language);
     }
     $objMember = $this->Database->prepare('SELECT * FROM tl_member WHERE disable = ?')->execute(0);
     $arrRows = array();
     while ($row = $objMember->fetchAssoc()) {
         foreach ($row as $k => $v) {
             if ($k == 'id' || $k == 'tstamp' || $k == 'password' || $k == 'avatar') {
                 continue;
             }
             $row[$k] = $v;
         }
         // score and grade
         $row['score'] = $this->getScore($row['id']);
         $row['averageRating'] = $this->getAverageRating($row['id']);
         $row['ratingEnities'] = $this->getRatingEnities($row['id']);
         $row['gradeLabel'] = $this->getGrade($row['id'], 'label');
         $row['gradeIcon'] = $this->getGrade($row['id'], 'label');
         // link to detail page
         $row['hrefDetailPage'] = $href ? sprintf($href, $row['id']) : false;
         // get avatar of member
         $arrSize = deserialize($this->avatarSizeListing);
         $title = $row['firstname'] . ' ' . $row['lastname'];
         $row['avatar'] = $this->getAvatar($objMember->id, $arrSize, 'avatar', $title, 'avatar_thumb', $this);
         // Show only Members from a selected group
         if ($this->limitUsers) {
             $arrGroups = deserialize($this->listedGroups);
             $oMember = \MemberModel::findByPk($objMember->id);
             if ($oMember !== null) {
                 if (count(array_intersect(deserialize($oMember->groups), $arrGroups)) < 1) {
                     continue;
                 }
             }
         }
         $arrRows[] = $row;
     }
     // Sorting
     $arrSorting = array();
     if (!empty($this->sortingField1) && !empty($this->sortingDirection1)) {
         $arrSorting[$this->sortingField1] = constant($this->sortingDirection1);
     }
     if (!empty($this->sortingField2) && !empty($this->sortingDirection2)) {
         $arrSorting[$this->sortingField2] = constant($this->sortingDirection2);
     }
     if (!empty($this->sortingField3) && !empty($this->sortingDirection3)) {
         $arrSorting[$this->sortingField3] = constant($this->sortingDirection3);
     }
     $arrRows = sortArrayByFields($arrRows, $arrSorting);
     $this->Template->rows = count($arrRows) ? $arrRows : false;
 }
开发者ID:markocupic,项目名称:member_rating,代码行数:61,代码来源:MemberRatingList.php

示例6: getMemberContentLink

 public static function getMemberContentLink($intId)
 {
     if (($objMemberContentArchive = MemberContentArchiveModel::findByPk($intId)) !== null) {
         if (($objTag = MemberContentArchiveTagModel::findByPk($objMemberContentArchive->tag)) !== null && $objTag->jumpTo) {
             if (($objMember = \MemberModel::findByPk($objMemberContentArchive->mid)) !== null) {
                 return Url::generateFrontendUrl($objTag->jumpTo) . '/' . General::getAliasIfAvailable($objMember);
             }
         }
     }
 }
开发者ID:heimrichhannot,项目名称:contao-member_content_archives,代码行数:10,代码来源:MemberContentArchives.php

示例7: checkCredentialsHook

 /**
  * Check Credentials, ldap password != contao password
  * @param String - Input Username $username
  * @param String - Input Password $password
  * @param unknown $objMember
  */
 public function checkCredentialsHook($strUsername, $strPassword, $objMember)
 {
     // store randomized password, so contao will always trigger the checkCredentials HOOK
     $objMember1 = \MemberModel::findByPk($objMember->id);
     LdapMember::resetPassword($objMember1, $strUsername);
     if (LdapMember::authenticateLdapMember($strUsername, $strPassword)) {
         LdapMember::doUpdateMember($objMember1, $objMember1->ldapUid, $objMember1->email, $objMember1->firstname, $objMember1->lastname, deserialize($GLOBALS['TL_CONFIG']['ldap_groups'], true));
         return true;
     } else {
         return false;
     }
 }
开发者ID:heimrichhannot,项目名称:contao-ldap,代码行数:18,代码来源:Ldap.php

示例8: trackGATransaction

 /**
  * Actually execute the GoogleAnalytics tracking
  * @param Database_Result
  * @param IsotopeProductCollection $objOrder
  */
 protected function trackGATransaction($objConfig, $objOrder)
 {
     // Initilize GA Tracker
     $tracker = new \UnitedPrototype\GoogleAnalytics\Tracker($objConfig->ga_account, \Environment::get('base'));
     // Assemble Visitor information
     // (could also get unserialized from database)
     $visitor = new \UnitedPrototype\GoogleAnalytics\Visitor();
     $visitor->setIpAddress(\Environment::get('ip'));
     $visitor->setUserAgent(\Environment::get('httpUserAgent'));
     $transaction = new \UnitedPrototype\GoogleAnalytics\Transaction();
     $transaction->setOrderId($objOrder->document_number);
     $transaction->setAffiliation($objConfig->name);
     $transaction->setTotal($objOrder->getTotal());
     $transaction->setTax($objOrder->getTotal() - $objOrder->getTaxFreeTotal());
     //        $transaction->setShipping($objOrder->shippingTotal);
     $objAddress = $objOrder->getBillingAddress();
     $transaction->setCity($objAddress->city);
     if ($objAddress->subdivision) {
         $arrSub = explode("-", $objAddress->subdivision, 2);
         $transaction->setRegion($arrSub[1]);
     }
     $transaction->setCountry($objAddress->country);
     /** @var \Isotope\Model\ProductCollectionItem $objItem */
     foreach ($objOrder->getItems() as $objItem) {
         $item = new \UnitedPrototype\GoogleAnalytics\Item();
         if ($objItem->getSku()) {
             $item->setSku($objItem->getSku());
         } else {
             $item->setSku('product' . $objItem->product_id);
         }
         $item->setName($objItem->getName());
         $item->setPrice($objItem->getPrice());
         $item->setQuantity($objItem->quantity);
         $arrOptionValues = array();
         foreach ($objItem->getConfiguration() as $option) {
             $arrOptionValues[] = (string) $option;
         }
         if (!empty($arrOptionValues)) {
             $item->setVariation(implode(', ', $arrOptionValues));
         }
         $transaction->addItem($item);
     }
     // Track logged-in member as custom variable
     if ($objConfig->ga_member != '' && $objOrder->member > 0 && ($objMember = \MemberModel::findByPk($objOrder->member)) !== null) {
         $customVar = new \UnitedPrototype\GoogleAnalytics\CustomVariable(1, 'Member', $this->parseSimpleTokens($objConfig->ga_member, $objMember->row()), \UnitedPrototype\GoogleAnalytics\CustomVariable::SCOPE_VISITOR);
         $tracker->addCustomVariable($customVar);
     }
     // Assemble Session information
     // (could also get unserialized from PHP session)
     $session = new \UnitedPrototype\GoogleAnalytics\Session();
     $tracker->trackTransaction($transaction, $session, $visitor);
 }
开发者ID:ralfhartmann,项目名称:isotope_core,代码行数:57,代码来源:Analytics.php

示例9: recordUsername

 public function recordUsername($intId, &$arrData)
 {
     if (!strlen($arrData['username'])) {
         $arrData['username'] = $arrData['email'];
         \Input::setPost('username', $arrData['email']);
         \Database::getInstance()->prepare("UPDATE tl_member SET username=? WHERE id=?")->execute($arrData['email'], $intId);
         $memberModel = \MemberModel::findByPk($intId);
         // Fix the problem with versions (see #7)
         if (null !== $memberModel) {
             $memberModel->refresh();
         }
     }
 }
开发者ID:terminal42,项目名称:contao-mailusername,代码行数:13,代码来源:MailUsername.php

示例10: listReviews

 public function listReviews($arrRow)
 {
     $strReview = '<div>';
     if (($objMember = \MemberModel::findByPk($arrRow['jid'])) !== null) {
         $strReview .= $objMember->firstname . ' ' . $objMember->lastname;
     }
     if (($objSubmission = \HeimrichHannot\Competition\SubmissionModel::findByPk($arrRow['sid'])) !== null) {
         if ($objSubmission->companyTeamName) {
             $strReview .= ' <span style="color:#b3b3b3; padding-left:3px">[' . $objSubmission->companyTeamName . ']</span>';
         }
     }
     $strReview .= '</div>';
     return $strReview;
 }
开发者ID:heimrichhannot,项目名称:contao-competition,代码行数:14,代码来源:tl_competition_review.php

示例11: compile

 /**
  * Generate the module
  */
 protected function compile()
 {
     $this->import('FrontendUser', 'User');
     // Initialize the password widget
     $arrField = array('name' => 'password', 'inputType' => 'text', 'label' => $GLOBALS['TL_LANG']['MSC']['password'][0], 'eval' => array('hideInput' => true, 'mandatory' => true, 'required' => true, 'tableless' => $this->tableless));
     $objWidget = new \FormTextField($this->prepareForWidget($arrField, $arrField['name']));
     $objWidget->rowClass = 'row_0 row_first even';
     // Validate widget
     if (\Input::post('FORM_SUBMIT') == 'tl_close_account') {
         $objWidget->validate();
         // Validate password
         if (!$objWidget->hasErrors()) {
             list(, $strSalt) = explode(':', $this->User->password);
             if (!strlen($strSalt) || sha1($strSalt . $objWidget->value) . ':' . $strSalt != $this->User->password) {
                 $objWidget->value = '';
                 $objWidget->addError($GLOBALS['TL_LANG']['ERR']['invalidPass']);
             }
         }
         // Close account
         if (!$objWidget->hasErrors()) {
             // HOOK: send account ID
             if (isset($GLOBALS['TL_HOOKS']['closeAccount']) && is_array($GLOBALS['TL_HOOKS']['closeAccount'])) {
                 foreach ($GLOBALS['TL_HOOKS']['closeAccount'] as $callback) {
                     $this->import($callback[0]);
                     $this->{$callback}[0]->{$callback}[1]($this->User->id, $this->reg_close, $this);
                 }
             }
             $objMember = \MemberModel::findByPk($this->User->id);
             // Remove the account
             if ($this->reg_close == 'close_delete') {
                 $objMember->delete();
                 $this->log('User account ID ' . $this->User->id . ' (' . $this->User->email . ') has been deleted', 'ModuleCloseAccount compile()', TL_ACCESS);
             } else {
                 $objMember->disable = 1;
                 $objMember->save();
                 $this->log('User account ID ' . $this->User->id . ' (' . $this->User->email . ') has been deactivated', 'ModuleCloseAccount compile()', TL_ACCESS);
             }
             $this->User->logout();
             $this->jumpToOrReload($this->objModel->getRelated('jumpTo')->row());
         }
     }
     $this->Template->fields = $objWidget->parse();
     $this->Template->formId = 'tl_close_account';
     $this->Template->action = $this->getIndexFreeRequest();
     $this->Template->slabel = specialchars($GLOBALS['TL_LANG']['MSC']['closeAccount']);
     $this->Template->rowLast = 'row_1 row_last odd';
     $this->Template->tableless = $this->tableless;
 }
开发者ID:rikaix,项目名称:core,代码行数:51,代码来源:ModuleCloseAccount.php

示例12: toggleIcon

 /**
  * Return the "toggle visibility" button
  * @param array
  * @param string
  * @param string
  * @param string
  * @param string
  * @param string
  * @return string
  */
 public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
 {
     $objMember = \MemberModel::findByPk($row['id']);
     $href .= '&amp;id=' . $row['id'];
     $arrDB = \Database::getInstance()->prepare("SELECT * FROM tl_abo as a, tl_abo_order as o WHERE o.memberId = ? and o.aboId = a.id")->execute($row['id'])->fetchAssoc();
     if ($arrDB) {
         $icon = 'system/modules/abonnement/html/abo.png';
         $title = "Abo: " . $arrDB['title'] . '<br>';
     } else {
         $icon = 'system/modules/abonnement/html/abo_none.png';
         $title = 'Derzeit kein Abo laufen!<br>';
     }
     foreach (deserialize($objMember->groups, true) as $intGroupId) {
         $objGroup = MemberGroupModel::findByPk($intGroupId);
         $title .= "<br>" . $objGroup->name;
     }
     return '<a href="' . $this->addToUrl('do=member&' . $href) . '" title="' . specialchars($title) . '"' . $attributes . '>' . $this->generateImage($icon, $label) . '</a> ';
 }
开发者ID:thescrat,项目名称:abonnement,代码行数:28,代码来源:tl_member.php

示例13: setUsernameFromEmail

 public function setUsernameFromEmail(&$objDc)
 {
     if ($objDc instanceof \Contao\FrontendUser) {
         if (!$objDc->email) {
             return;
         }
         $objDc->username = $objDc->email;
         $objDc->save();
     } elseif ($objDc->activeRecord) {
         if (!$objDc->activeRecord->email) {
             return;
         }
         $objMember = \MemberModel::findByPk($objDc->activeRecord->id);
         $objMember->refresh();
         $objMember->username = $objDc->activeRecord->email;
         if (TL_MODE == 'BE') {
             $objDc->activeRecord->username = $objDc->activeRecord->email;
         }
         $objMember->save();
     }
 }
开发者ID:heimrichhannot,项目名称:contao-email2username,代码行数:21,代码来源:tl_member.php

示例14: sendPasswordLink

 /**
  * Send a lost password e-mail
  *
  * @param \MemberModel $objMember
  */
 protected function sendPasswordLink($objMember)
 {
     $objNotification = \NotificationCenter\Model\Notification::findByPk($this->nc_notification);
     if ($objNotification === null) {
         $this->log('The notification was not found ID ' . $this->nc_notification, __METHOD__, TL_ERROR);
         return;
     }
     $confirmationId = md5(uniqid(mt_rand(), true));
     // Store the confirmation ID
     $objMember = \MemberModel::findByPk($objMember->id);
     $objMember->activation = $confirmationId;
     $objMember->save();
     $arrTokens = array();
     // Add member tokens
     foreach ($objMember->row() as $k => $v) {
         if (\Validator::isBinaryUuid($v)) {
             $v = \StringUtil::binToUuid($v);
         }
         $arrTokens['member_' . $k] = specialchars($v);
     }
     // FIX: Add salutation token
     $arrTokens['salutation_user'] = NotificationCenterPlus::createSalutation($GLOBALS['TL_LANGUAGE'], $objMember);
     // ENDFIX
     $arrTokens['recipient_email'] = $objMember->email;
     $arrTokens['domain'] = \Idna::decode(\Environment::get('host'));
     $arrTokens['link'] = \Idna::decode(\Environment::get('base')) . \Environment::get('request') . ($GLOBALS['TL_CONFIG']['disableAlias'] || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $confirmationId;
     // FIX: Add custom change password jump to
     if (($objJumpTo = $this->objModel->getRelated('changePasswordJumpTo')) !== null) {
         $arrTokens['link'] = \Idna::decode(\Environment::get('base')) . \Controller::generateFrontendUrl($objJumpTo->row(), '?token=' . $confirmationId);
     }
     // ENDFIX
     $objNotification->send($arrTokens, $GLOBALS['TL_LANGUAGE']);
     $this->log('A new password has been requested for user ID ' . $objMember->id . ' (' . $objMember->email . ')', __METHOD__, TL_ACCESS);
     // Check whether there is a jumpTo page
     if (($objJumpTo = $this->objModel->getRelated('jumpTo')) !== null) {
         $this->jumpToOrReload($objJumpTo->row());
     }
     StatusMessage::addSuccess(sprintf($GLOBALS['TL_LANG']['notification_center_plus']['sendPasswordLink']['messageSuccess'], $arrTokens['recipient_email']), $this->objModel->id);
     $this->reload();
 }
开发者ID:heimrichhannot,项目名称:contao-notification_center_plus,代码行数:45,代码来源:ModulePasswordNotificationCenterPlus.php

示例15: compile

 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     $this->import('FrontendUser', 'User');
     $GLOBALS['TL_LANGUAGE'] = $objPage->language;
     \System::loadLanguageFile('tl_member');
     $this->loadDataContainer('tl_member');
     // Old password widget
     $arrFields['oldPassword'] = array('name' => 'oldpassword', 'label' => &$GLOBALS['TL_LANG']['MSC']['oldPassword'], 'inputType' => 'text', 'eval' => array('mandatory' => true, 'preserveTags' => true, 'hideInput' => true));
     // New password widget
     $arrFields['newPassword'] = $GLOBALS['TL_DCA']['tl_member']['fields']['password'];
     $arrFields['newPassword']['name'] = 'password';
     $arrFields['newPassword']['label'] =& $GLOBALS['TL_LANG']['MSC']['newPassword'];
     $row = 0;
     $strFields = '';
     $doNotSubmit = false;
     $objMember = \MemberModel::findByPk($this->User->id);
     $strTable = $objMember->getTable();
     // Initialize the versioning (see #8301)
     $objVersions = new \Versions($strTable, $objMember->id);
     $objVersions->setUsername($objMember->username);
     $objVersions->setUserId(0);
     $objVersions->setEditUrl('contao/main.php?do=member&act=edit&id=%s&rt=1');
     $objVersions->initialize();
     /** @var \FormTextField $objOldPassword */
     $objOldPassword = null;
     /** @var \FormPassword $objNewPassword */
     $objNewPassword = null;
     // Initialize the widgets
     foreach ($arrFields as $strKey => $arrField) {
         /** @var \Widget $strClass */
         $strClass = $GLOBALS['TL_FFL'][$arrField['inputType']];
         // Continue if the class is not defined
         if (!class_exists($strClass)) {
             continue;
         }
         $arrField['eval']['tableless'] = $this->tableless;
         $arrField['eval']['required'] = $arrField['eval']['mandatory'];
         /** @var \Widget $objWidget */
         $objWidget = new $strClass($strClass::getAttributesFromDca($arrField, $arrField['name']));
         $objWidget->storeValues = true;
         $objWidget->rowClass = 'row_' . $row . ($row == 0 ? ' row_first' : '') . ($row % 2 == 0 ? ' even' : ' odd');
         // Increase the row count if it is a password field
         if ($objWidget instanceof \FormPassword) {
             $objWidget->rowClassConfirm = 'row_' . ++$row . ($row % 2 == 0 ? ' even' : ' odd');
         }
         ++$row;
         // Store the widget objects
         $strVar = 'obj' . ucfirst($strKey);
         ${$strVar} = $objWidget;
         // Validate the widget
         if (\Input::post('FORM_SUBMIT') == 'tl_change_password') {
             $objWidget->validate();
             // Validate the old password
             if ($strKey == 'oldPassword') {
                 if (\Encryption::test($objMember->password)) {
                     $blnAuthenticated = \Encryption::verify($objWidget->value, $objMember->password);
                 } else {
                     list($strPassword, $strSalt) = explode(':', $objMember->password);
                     $blnAuthenticated = $strSalt == '' ? $strPassword === sha1($objWidget->value) : $strPassword === sha1($strSalt . $objWidget->value);
                 }
                 if (!$blnAuthenticated) {
                     $objWidget->value = '';
                     $objWidget->addError($GLOBALS['TL_LANG']['MSC']['oldPasswordWrong']);
                     sleep(2);
                     // Wait 2 seconds while brute forcing :)
                 }
             }
             if ($objWidget->hasErrors()) {
                 $doNotSubmit = true;
             }
         }
         $strFields .= $objWidget->parse();
     }
     $this->Template->fields = $strFields;
     $this->Template->hasError = $doNotSubmit;
     // Store the new password
     if (\Input::post('FORM_SUBMIT') == 'tl_change_password' && !$doNotSubmit) {
         $objMember->tstamp = time();
         $objMember->password = $objNewPassword->value;
         $objMember->save();
         // Create a new version
         if ($GLOBALS['TL_DCA'][$strTable]['config']['enableVersioning']) {
             $objVersions->create();
         }
         // HOOK: set new password callback
         if (isset($GLOBALS['TL_HOOKS']['setNewPassword']) && is_array($GLOBALS['TL_HOOKS']['setNewPassword'])) {
             foreach ($GLOBALS['TL_HOOKS']['setNewPassword'] as $callback) {
                 $this->import($callback[0]);
                 $this->{$callback[0]}->{$callback[1]}($objMember, $objNewPassword->value, $this);
             }
         }
         // Check whether there is a jumpTo page
         if (($objJumpTo = $this->objModel->getRelated('jumpTo')) !== null) {
             $this->jumpToOrReload($objJumpTo->row());
         }
//.........这里部分代码省略.........
开发者ID:eknoes,项目名称:core,代码行数:101,代码来源:ModuleChangePassword.php


注:本文中的MemberModel::findByPk方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。