public function UpdateField($fieldName, $newValue, &$pkVal = NULL, $fieldType = NULL) { // if pk is null, update the pk to random string if ($pkVal === null) { parent::UpdateField('cms_id', 'newpage_' . rand(), $pkVal); } // if field is pk and newvalue is empty, return if ($fieldName == 'cms_id' && !$newValue) { return; } parent::UpdateField($fieldName, $newValue, $pkVal, $fieldType); }
public function UpdateField($fieldName, $newValue, &$pkVal = NULL, $fieldType = NULL) { if ($fieldName == 'username') { $newValue = trim($newValue); // does this email already exist? $r = database::query('SELECT * FROM `' . $this->tablename . '` WHERE `username` = ?', array($newValue)); if ($r->fetch()) { uNotices::AddNotice('This email is already registered to an account.', NOTICE_TYPE_ERROR); return FALSE; } if (preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i', $newValue)) { // email address has been updated - set email_confirm and email_confirm_code if ($pkVal === NULL) { parent::UpdateField('username', $newValue, $pkVal); } parent::UpdateField('email_confirm', $newValue, $pkVal); } else { parent::UpdateField('username', $newValue, $pkVal); } return TRUE; } if ($pkVal === NULL) { parent::UpdateField('username', 'unverified_' . uCrypt::GetRandom(75), $pkVal); } if ($fieldName == 'email_confirm_code' && $newValue === true) { // get old username $r = database::query('SELECT username, email_confirm FROM `' . $this->tablename . '` WHERE user_id = ?', array($pkVal)); if ($r && ($row = $r->fetch()) && $row['email_confirm']) { $old = $row['username']; $new = $row['email_confirm']; // set username to email_confirm parent::UpdateField('username', 'email_confirm', $pkVal, ftRAW); // clear email_confirm + code parent::UpdateField('email_confirm', '', $pkVal); parent::UpdateField('email_confirm_code', '', $pkVal); if ($old != $new) { uEvents::TriggerEvent('UsernameChanged', NULL, array($old, $new)); } } return; } parent::UpdateField($fieldName, $newValue, $pkVal, $fieldType); }