Файловый менеджер - Редактировать - /home/digilove/public_html/41423/profile.php.tar
Назад
home/digilove/public_html/components/com_marketplace/models/profile.php 0000644 00000041764 15232603241 0022561 0 ustar 00 <?php /** * Marketplace - Component Marketplace * ****************************************************************** * * PHP version 7.0 * * @category Component * @package Joomla * @author WebKul software private limited <support@webkul.com> * @copyright 2010 WebKul software private limited * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL * @version GIT:5.2 * @filesource http://store.webkul.com * @link Technical Support: webkul.uvdesk.com * ****************************************************************** */ // no direct access defined('_JEXEC') or die('Restricted access'); jimport('joomla.application.component.model'); VmConfig::loadConfig(); if (!class_exists('MarketplaceModelProfile')) { /** * MarketplaceModelProfile class * * @category Component * @package Joomla * @author WebKul software private limited <support@webkul.com> * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL * @link Technical Support: webkul.uvdesk.com */ class MarketplaceModelProfile extends JModelLegacy { var $_data = null; /** * __construct function */ function __construct() { parent::__construct(); } /** * GetCountryId function * * @param [type] $id var * * @return void */ function getCountryId($id) { $db = $this->_db; $query=$db->getQuery(true); $query->select($db->quoteName("virtuemart_country_id")) ->from($db->quoteName("#__virtuemart_userinfos")) ->where($db->quoteName("virtuemart_user_id")."=".$db->quote($id)); $db->setQuery($query); try{ $db->setQuery($query); return $db->loadResult(); } catch (Exception $e){ JFactory::getApplication()->enqueueMessage( JText::_('Wrong SQL Query'), 'error' ); return false; } } /** * GetSellerCountry function * * @param [type] $id var * * @return void */ function getSellerCountry($id) { $db = $this->_db; $query=$db->getQuery(true); $query->select($db->quoteName("country_2_code")) ->from($db->quoteName("#__virtuemart_countries")) ->where( $db->quoteName("virtuemart_country_id")."=".$db->quote($id) ); $db->setQuery($query); try{ $db->setQuery($query); return $db->loadResult(); } catch (Exception $e){ JFactory::getApplication()->enqueueMessage( JText::_('Wrong SQL Query'), 'error' ); return false; } } /** * _buildQuery function * * @return void */ function _buildQuery() { $db = $this->_db; $user = JFactory::getUser(); $userid = $user->get('id'); $query=$db->getQuery(true); $query->select('a.*,b.email') ->from($db->quoteName('#__marketplace_sellerprofile', 'a')) ->join( 'LEFT', $db->quoteName('#__users', 'b') . ' ON (' . $db->quoteName('a.seller_id') . ' = ' . $db->quoteName('b.id') . ')' ) ->where($db->quoteName('seller_id')."=".$userid) ->group($db->quoteName('b.id')); return $query; } /** * GetData function * * @return void */ function getData() { // Lets load the data if it doesn't already exist if (empty($this->_data)) { $query = $this->_buildQuery(); try{ $this->_data = $this->_getList($query); } catch (Exception $e){ JFactory::getApplication()->enqueueMessage( JText::_('Wrong SQL Query'), 'error' ); return false; } } return $this->_data; } /** * GetPaymentInfo function * * @return void */ function getPaymentInfo() { $db=$this->_db; $query=$db->getQuery(true); $query->select( $db->quoteName( 'p.virtuemart_paymentmethod_id', 'virtuemart_paymentmethod_id' ) ) ->select($db->quoteName('p.payment_element', 'payment_element')) ->select($db->quoteName('g.payment_name', 'payment_name')) ->from($db->quoteName('#__virtuemart_paymentmethods', 'p')) ->join( 'INNER', $db->quoteName( '#__virtuemart_paymentmethods_'.VmConfig::$vmlang, 'g' ) ." ON ".$db->quoteName('g.virtuemart_paymentmethod_id') ."=".$db->quoteName('p.virtuemart_paymentmethod_id') ) ->where($db->quoteName('p.published')."=1"); try { $db->setQuery($query); return $db->loadObjectList(); } catch (RuntimeException $e) { JFactory::getApplication()->enqueueMessage( JText::_('Wrong SQL Query'), 'error' ); return false; } } /** * GetPaymentMethodId function * * @return void */ function getPaymentMethodId() { $db = JFactory::getDBO(); $q=$db->getQuery(true); $q->select('*') ->from($db->quotename('#__virtuemart_paymentmethods')) ->where( $db->quotename('payment_element'). "=".$db->quote('stripeconnect') ); $db->setQuery($q); try{ $res=$db->loadObject(); } catch(Exception $e){ JFactory::getApplication()->enqueueMessage( 'SOL_ERROR', 'error' ); } if ($res) { $id_f=$res->virtuemart_paymentmethod_id; $params_f=$res->payment_params; $object=array(); if ($params_f) { $params_f=explode("|", $params_f); foreach ($params_f as $key => $value) { if (strlen($value)>0) { $val=explode("=", $value); $val[1]=str_replace('"', '', $val[1]); $object[$val[0]]=$val[1]; } } return $object; } else { return false; } } else { return false; } } /** * Store_stripe_data function * * @param [type] $data var * @param [type] $secret var * @param [type] $public var * @param [type] $client_id var * @param [type] $state var * * @return void */ function storeStripeData( $data, $secret, $public, $client_id, $state ) { $stripe_seller_id=JFactory::getUser()->id; $db=JFactory::getDBO(); $q=$db->getQuery(true); $q->select($db->quoteName('stripe_user_id')) ->from($db->quoteName('#__marketplace_stripe_connected_seller')) ->where($db->quoteName('seller_id')."=".$stripe_seller_id); $db->setQuery($q); try{ $res=$db->loadResult(); } catch(Exception $e){ JFactory::getApplication()->redirect( 'index.php?option=com_marketplace&view=profile', $e->getMessage(), 'error' ); } if ($res) { $q=$db->getQuery(true); if ($state=='insert') { $fields = array( $db->quoteName('stripe_user_id'). '='.$db->quote($data['stripe_user_id']), $db->quoteName('stripe_secret'). '='.$db->quote($data['access_token']), $db->quoteName('stripe_public'). '='.$db->quote($data['stripe_publishable_key']), $db->quoteName('stripe_refresh'). '='.$db->quote($data['refresh_token']), $db->quoteName('livemode'). '='.$db->quote($data['livemode']), $db->quoteName('state').'= 1' ); $conditions = array( $db->quoteName('seller_id') . ' = '.$stripe_seller_id ); $q->update( $db->quoteName('#__marketplace_stripe_connected_seller') ) ->set($fields) ->where($conditions); } else { $fields = array($db->quoteName('state') . ' = 0'); $conditions = array( $db->quoteName('seller_id') . ' = '.$stripe_seller_id ); $q->update( $db->quoteName('#__marketplace_stripe_connected_seller') ) ->set($fields) ->where($conditions); } } else { $q=$db->getQuery(true); if ($state=='insert') { $columns=array( 'seller_id', 'stripe_user_id', 'stripe_secret', 'stripe_public', 'stripe_refresh', 'livemode', 'state' ); $values=array( $db->quote($stripe_seller_id), $db->quote($data['stripe_user_id']), $db->quote($data['access_token']), $db->quote($data['stripe_publishable_key']), $db->quote($data['refresh_token']), $db->quote($data['livemode']), 1 ); $q->insert( $db->quoteName('#__marketplace_stripe_connected_seller') ) ->columns($db->quoteName($columns)) ->values(implode(',', $values)); } else { $fields = array($db->quoteName('state') . ' = 0'); $conditions = array( $db->quoteName('seller_id') . ' = '.$stripe_seller_id ); $q->update( $db->quoteName('#__marketplace_stripe_connected_seller') ) ->set($fields) ->where($conditions); } } $db->setQuery($q); try{ $db->execute(); } catch(Exception $e){ JFactory::getApplication()->redirect( 'index.php?option=com_marketplace&view=profile', $e->getMessage(), 'error' ); } } /** * GetStripeData function * * @param [type] $seller_id var * * @return void */ function getStripeData($seller_id=null) { if ($seller_id==null) { $seller_id=JFactory::getUser()->id; } $db=JFactory::getDBO(); $q=$db->getQuery(true); $q->select($db->quoteName('stripe_user_id')) ->from($db->quoteName('#__marketplace_stripe_connected_seller')) ->where($db->quoteName('seller_id')."=".$db->quote($seller_id)) ->where($db->quoteName('state')."= 1"); $db->setQuery($q); try{ $rs=$db->loadResult(); } catch(Exception $e){ Factory::getApplication()->redirect( 'index.php?option=com_marketplace&view=profile', $e->getMessage(), 'error' ); } if ($rs) { return $rs; } } /** * GetRemitaSeller function * * @param [type] $seller_id var * * @return void */ function getRemitaSeller($seller_id=null) { if ($seller_id==null) { $seller_id=JFactory::getUser()->id; } $db=JFactory::getDbo(); $query=$db->getQuery(true); $query->select("*") ->from( $db->quoteName('#__marketplace_remitapayment_connectedseller') ) ->where($db->quoteName('sellerid')." = ".$db->quote($seller_id)); $db->setQuery($query); try{ return $db->loadObject(); }catch(Exception $e){ return false; } } /** * SaveRemitaDetails function * * @param [type] $name var * @param [type] $account var * @param [type] $code var * @param [type] $sellerid var * * @return void */ function saveRemitaDetails($name,$account,$code,$sellerid=null) { if ($sellerid==null) { $sellerid=JFactory::getUser()->id; } $db=JFactory::getDbo(); $app=JFactory::getApplication(); $query=$db->getQuery(true); $query->select($db->quoteName('id')) ->from( $db->quoteName('#__marketplace_remitapayment_connectedseller') ) ->where($db->quoteName('sellerid')."=".$db->quote($sellerid)); $db->setQuery($query); try{ $result=$db->loadResult(); } catch(Exception $e){ $app->enqueueMessage( $e->getMessage(), 'error' ); } /*code to update existing entry*/ if ($result) { $query=$db->getQuery(true); $query->UPDATE( $db->quoteName('#__marketplace_remitapayment_connectedseller') ) ->SET($db->quoteName('name')."=".$db->quote($name)) ->SET($db->quoteName('account')."=".$db->quote($account)) ->SET($db->quoteName('bankcode')."=".$db->quote($code)) ->where($db->quoteName('sellerid')."=".$db->quote($sellerid)); $db->setQuery($query); try{ $db->execute(); } catch(Exception $e){ JFactory::getApplication()->enqueueMessage( $e->getMessage(), 'error' ); return false; } } else { /*code to insert new entry*/ $query = $db->getQuery(true); $columns = array( 'sellerid', 'name', 'account', 'bankcode', 'published' ); $values = array( $db->quote($sellerid), $db->quote($name), $db->quote($account), $db->quote($code), $db->quote(1) ); $query->insert( $db->quoteName('#__marketplace_remitapayment_connectedseller') ) ->columns($db->quoteName($columns)) ->values(implode(',', $values)); $db->setQuery($query); try{ $db->execute(); } catch(Exception $e){ $app->enqueueMessage( $e->getMessage(), 'error' ); return false; } } } } } home/digilove/public_html/plugins/user/profile/profile.php 0000644 00000032073 15234547407 0020070 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage User.profile * * @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Date\Date; use Joomla\CMS\Factory; use Joomla\CMS\Form\Form; use Joomla\CMS\Form\FormHelper; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\String\PunycodeHelper; use Joomla\Utilities\ArrayHelper; /** * An example custom profile plugin. * * @since 1.6 */ class PlgUserProfile extends JPlugin { /** * Date of birth. * * @var string * @since 3.1 */ private $date = ''; /** * Load the language file on instantiation. * * @var boolean * @since 3.1 */ protected $autoloadLanguage = true; /** * Constructor * * @param object &$subject The object to observe * @param array $config An array that holds the plugin configuration * * @since 1.5 */ public function __construct(& $subject, $config) { parent::__construct($subject, $config); FormHelper::addFieldPath(__DIR__ . '/field'); } /** * Runs on content preparation * * @param string $context The context for the data * @param object $data An object containing the data for the form. * * @return boolean * * @since 1.6 */ public function onContentPrepareData($context, $data) { // Check we are manipulating a valid form. if (!in_array($context, array('com_users.profile', 'com_users.user', 'com_users.registration', 'com_admin.profile'))) { return true; } if (is_object($data)) { $userId = isset($data->id) ? $data->id : 0; if (!isset($data->profile) && $userId > 0) { // Load the profile data from the database. $db = Factory::getDbo(); $db->setQuery( 'SELECT profile_key, profile_value FROM #__user_profiles' . ' WHERE user_id = ' . (int) $userId . " AND profile_key LIKE 'profile.%'" . ' ORDER BY ordering' ); try { $results = $db->loadRowList(); } catch (RuntimeException $e) { $this->_subject->setError($e->getMessage()); return false; } // Merge the profile data. $data->profile = array(); foreach ($results as $v) { $k = str_replace('profile.', '', $v[0]); $data->profile[$k] = json_decode($v[1], true); if ($data->profile[$k] === null) { $data->profile[$k] = $v[1]; } } } if (!HTMLHelper::isRegistered('users.url')) { HTMLHelper::register('users.url', array(__CLASS__, 'url')); } if (!HTMLHelper::isRegistered('users.calendar')) { HTMLHelper::register('users.calendar', array(__CLASS__, 'calendar')); } if (!HTMLHelper::isRegistered('users.tos')) { HTMLHelper::register('users.tos', array(__CLASS__, 'tos')); } if (!HTMLHelper::isRegistered('users.dob')) { HTMLHelper::register('users.dob', array(__CLASS__, 'dob')); } } return true; } /** * Returns an anchor tag generated from a given value * * @param string $value URL to use * * @return mixed|string */ public static function url($value) { if (empty($value)) { return HTMLHelper::_('users.value', $value); } else { // Convert website URL to utf8 for display $value = PunycodeHelper::urlToUTF8(htmlspecialchars($value)); if (strpos($value, 'http') === 0) { return '<a href="' . $value . '">' . $value . '</a>'; } else { return '<a href="http://' . $value . '">' . $value . '</a>'; } } } /** * Returns html markup showing a date picker * * @param string $value valid date string * * @return mixed */ public static function calendar($value) { if (empty($value)) { return HTMLHelper::_('users.value', $value); } else { return HTMLHelper::_('date', $value, null, null); } } /** * Returns the date of birth formatted and calculated using server timezone. * * @param string $value valid date string * * @return mixed */ public static function dob($value) { if (!$value) { return ''; } return HTMLHelper::_('date', $value, Text::_('DATE_FORMAT_LC1'), false); } /** * Return the translated strings yes or no depending on the value * * @param boolean $value input value * * @return string */ public static function tos($value) { if ($value) { return Text::_('JYES'); } else { return Text::_('JNO'); } } /** * Adds additional fields to the user editing form * * @param Form $form The form to be altered. * @param mixed $data The associated data for the form. * * @return boolean * * @since 1.6 */ public function onContentPrepareForm(Form $form, $data) { // Check we are manipulating a valid form. $name = $form->getName(); if (!in_array($name, array('com_admin.profile', 'com_users.user', 'com_users.profile', 'com_users.registration'))) { return true; } // Add the registration fields to the form. Form::addFormPath(__DIR__ . '/profiles'); $form->loadFile('profile'); $fields = array( 'address1', 'address2', 'city', 'region', 'country', 'postal_code', 'phone', 'website', 'favoritebook', 'aboutme', 'dob', 'tos', ); // Change fields description when displayed in frontend or backend profile editing $app = Factory::getApplication(); if ($app->isClient('site') || $name === 'com_users.user' || $name === 'com_admin.profile') { $form->setFieldAttribute('address1', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile'); $form->setFieldAttribute('address2', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile'); $form->setFieldAttribute('city', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile'); $form->setFieldAttribute('region', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile'); $form->setFieldAttribute('country', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile'); $form->setFieldAttribute('postal_code', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile'); $form->setFieldAttribute('phone', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile'); $form->setFieldAttribute('website', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile'); $form->setFieldAttribute('favoritebook', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile'); $form->setFieldAttribute('aboutme', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile'); $form->setFieldAttribute('dob', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile'); $form->setFieldAttribute('tos', 'description', 'PLG_USER_PROFILE_FIELD_TOS_DESC_SITE', 'profile'); } $tosArticle = $this->params->get('register_tos_article'); $tosEnabled = $this->params->get('register-require_tos', 0); // We need to be in the registration form and field needs to be enabled if ($name !== 'com_users.registration' || !$tosEnabled) { // We only want the TOS in the registration form $form->removeField('tos', 'profile'); } else { // Push the TOS article ID into the TOS field. $form->setFieldAttribute('tos', 'article', $tosArticle, 'profile'); } foreach ($fields as $field) { // Case using the users manager in admin if ($name === 'com_users.user') { // Toggle whether the field is required. if ($this->params->get('profile-require_' . $field, 1) > 0) { $form->setFieldAttribute($field, 'required', ($this->params->get('profile-require_' . $field) == 2) ? 'required' : '', 'profile'); } // Remove the field if it is disabled in registration and profile elseif ($this->params->get('register-require_' . $field, 1) == 0 && $this->params->get('profile-require_' . $field, 1) == 0) { $form->removeField($field, 'profile'); } } // Case registration elseif ($name === 'com_users.registration') { // Toggle whether the field is required. if ($this->params->get('register-require_' . $field, 1) > 0) { $form->setFieldAttribute($field, 'required', ($this->params->get('register-require_' . $field) == 2) ? 'required' : '', 'profile'); } else { $form->removeField($field, 'profile'); } } // Case profile in site or admin elseif ($name === 'com_users.profile' || $name === 'com_admin.profile') { // Toggle whether the field is required. if ($this->params->get('profile-require_' . $field, 1) > 0) { $form->setFieldAttribute($field, 'required', ($this->params->get('profile-require_' . $field) == 2) ? 'required' : '', 'profile'); } else { $form->removeField($field, 'profile'); } } } // Drop the profile form entirely if there aren't any fields to display. $remainingfields = $form->getGroup('profile'); if (!count($remainingfields)) { $form->removeGroup('profile'); } return true; } /** * Method is called before user data is stored in the database * * @param array $user Holds the old user data. * @param boolean $isnew True if a new user is stored. * @param array $data Holds the new user data. * * @return boolean * * @since 3.1 * @throws InvalidArgumentException on invalid date. */ public function onUserBeforeSave($user, $isnew, $data) { // Check that the date is valid. if (!empty($data['profile']['dob'])) { try { $date = new Date($data['profile']['dob']); $this->date = $date->format('Y-m-d H:i:s'); } catch (Exception $e) { // Throw an exception if date is not valid. throw new InvalidArgumentException(Text::_('PLG_USER_PROFILE_ERROR_INVALID_DOB')); } if (Date::getInstance('now') < $date) { // Throw an exception if dob is greater than now. throw new InvalidArgumentException(Text::_('PLG_USER_PROFILE_ERROR_INVALID_DOB_FUTURE_DATE')); } } // Check that the tos is checked if required ie only in registration from frontend. $task = Factory::getApplication()->input->getCmd('task'); $option = Factory::getApplication()->input->getCmd('option'); $tosArticle = $this->params->get('register_tos_article'); $tosEnabled = ($this->params->get('register-require_tos', 0) == 2); // Check that the tos is checked. if ($task === 'register' && $tosEnabled && $tosArticle && $option === 'com_users' && !$data['profile']['tos']) { throw new InvalidArgumentException(Text::_('PLG_USER_PROFILE_FIELD_TOS_DESC_SITE')); } return true; } /** * Saves user profile data * * @param array $data entered user data * @param boolean $isNew true if this is a new user * @param boolean $result true if saving the user worked * @param string $error error message * * @return boolean */ public function onUserAfterSave($data, $isNew, $result, $error) { $userId = ArrayHelper::getValue($data, 'id', 0, 'int'); if ($userId && $result && isset($data['profile']) && count($data['profile'])) { try { $db = Factory::getDbo(); // Sanitize the date if (!empty($data['profile']['dob'])) { $data['profile']['dob'] = $this->date; } $keys = array_keys($data['profile']); foreach ($keys as &$key) { $key = 'profile.' . $key; $key = $db->quote($key); } $query = $db->getQuery(true) ->delete($db->quoteName('#__user_profiles')) ->where($db->quoteName('user_id') . ' = ' . (int) $userId) ->where($db->quoteName('profile_key') . ' IN (' . implode(',', $keys) . ')'); $db->setQuery($query); $db->execute(); $query = $db->getQuery(true) ->select($db->quoteName('ordering')) ->from($db->quoteName('#__user_profiles')) ->where($db->quoteName('user_id') . ' = ' . (int) $userId); $db->setQuery($query); $usedOrdering = $db->loadColumn(); $tuples = array(); $order = 1; foreach ($data['profile'] as $k => $v) { while (in_array($order, $usedOrdering)) { $order++; } $tuples[] = '(' . $userId . ', ' . $db->quote('profile.' . $k) . ', ' . $db->quote(json_encode($v)) . ', ' . ($order++) . ')'; } $db->setQuery('INSERT INTO #__user_profiles VALUES ' . implode(', ', $tuples)); $db->execute(); } catch (RuntimeException $e) { $this->_subject->setError($e->getMessage()); return false; } } return true; } /** * Remove all user profile information for the given user ID * * Method is called after user data is deleted from the database * * @param array $user Holds the user data * @param boolean $success True if user was successfully stored in the database * @param string $msg Message * * @return boolean */ public function onUserAfterDelete($user, $success, $msg) { if (!$success) { return false; } $userId = ArrayHelper::getValue($user, 'id', 0, 'int'); if ($userId) { try { $db = Factory::getDbo(); $db->setQuery( 'DELETE FROM #__user_profiles WHERE user_id = ' . $userId . " AND profile_key LIKE 'profile.%'" ); $db->execute(); } catch (Exception $e) { $this->_subject->setError($e->getMessage()); return false; } } return true; } } home/digilove/public_html/components/com_users/models/profile.php 0000644 00000026153 15235600521 0021426 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_users * * @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\User\UserHelper; use Joomla\Registry\Registry; /** * Profile model class for Users. * * @since 1.6 */ class UsersModelProfile extends JModelForm { /** * @var object The user profile data. * @since 1.6 */ protected $data; /** * Constructor * * @param array $config An array of configuration options (name, state, dbo, table_path, ignore_request). * * @since 3.2 * * @throws Exception */ public function __construct($config = array()) { $config = array_merge( array( 'events_map' => array('validate' => 'user') ), $config ); parent::__construct($config); // Load the helper and model used for two factor authentication JLoader::register('UsersModelUser', JPATH_ADMINISTRATOR . '/components/com_users/models/user.php'); JLoader::register('UsersHelper', JPATH_ADMINISTRATOR . '/components/com_users/helpers/users.php'); } /** * Method to check in a user. * * @param integer $userId The id of the row to check out. * * @return boolean True on success, false on failure. * * @since 1.6 */ public function checkin($userId = null) { // Get the user id. $userId = (!empty($userId)) ? $userId : (int) $this->getState('user.id'); if ($userId) { // Initialise the table with JUser. $table = JTable::getInstance('User'); // Attempt to check the row in. if (!$table->checkin($userId)) { $this->setError($table->getError()); return false; } } return true; } /** * Method to check out a user for editing. * * @param integer $userId The id of the row to check out. * * @return boolean True on success, false on failure. * * @since 1.6 */ public function checkout($userId = null) { // Get the user id. $userId = (!empty($userId)) ? $userId : (int) $this->getState('user.id'); if ($userId) { // Initialise the table with JUser. $table = JTable::getInstance('User'); // Get the current user object. $user = JFactory::getUser(); // Attempt to check the row out. if (!$table->checkout($user->get('id'), $userId)) { $this->setError($table->getError()); return false; } } return true; } /** * Method to get the profile form data. * * The base form data is loaded and then an event is fired * for users plugins to extend the data. * * @return mixed Data object on success, false on failure. * * @since 1.6 */ public function getData() { if ($this->data === null) { $userId = $this->getState('user.id'); // Initialise the table with JUser. $this->data = new JUser($userId); // Set the base user data. $this->data->email1 = $this->data->get('email'); $this->data->email2 = $this->data->get('email'); // Override the base user data with any data in the session. $temp = (array) JFactory::getApplication()->getUserState('com_users.edit.profile.data', array()); foreach ($temp as $k => $v) { $this->data->$k = $v; } // Unset the passwords. unset($this->data->password1, $this->data->password2); $registry = new Registry($this->data->params); $this->data->params = $registry->toArray(); } return $this->data; } /** * Method to get the profile form. * * The base form is loaded from XML and then an event is fired * for users plugins to extend the form with extra fields. * * @param array $data An optional array of data for the form to interrogate. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * * @return JForm A JForm object on success, false on failure * * @since 1.6 */ public function getForm($data = array(), $loadData = true) { // Get the form. $form = $this->loadForm('com_users.profile', 'profile', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } // Check for username compliance and parameter set $isUsernameCompliant = true; $username = $loadData ? $form->getValue('username') : $this->loadFormData()->username; if ($username) { $isUsernameCompliant = !(preg_match('#[<>"\'%;()&\\\\]|\\.\\./#', $username) || strlen(utf8_decode($username)) < 2 || trim($username) !== $username); } $this->setState('user.username.compliant', $isUsernameCompliant); if ($isUsernameCompliant && !JComponentHelper::getParams('com_users')->get('change_login_name')) { $form->setFieldAttribute('username', 'class', ''); $form->setFieldAttribute('username', 'filter', ''); $form->setFieldAttribute('username', 'description', 'COM_USERS_PROFILE_NOCHANGE_USERNAME_DESC'); $form->setFieldAttribute('username', 'validate', ''); $form->setFieldAttribute('username', 'message', ''); $form->setFieldAttribute('username', 'readonly', 'true'); $form->setFieldAttribute('username', 'required', 'false'); } // When multilanguage is set, a user's default site language should also be a Content Language if (JLanguageMultilang::isEnabled()) { $form->setFieldAttribute('language', 'type', 'frontend_language', 'params'); } // If the user needs to change their password, mark the password fields as required if (JFactory::getUser()->requireReset) { $form->setFieldAttribute('password1', 'required', 'true'); $form->setFieldAttribute('password2', 'required', 'true'); } return $form; } /** * Method to get the data that should be injected in the form. * * @return mixed The data for the form. * * @since 1.6 */ protected function loadFormData() { $data = $this->getData(); $this->preprocessData('com_users.profile', $data, 'user'); return $data; } /** * Override preprocessForm to load the user plugin group instead of content. * * @param JForm $form A JForm object. * @param mixed $data The data expected for the form. * @param string $group The name of the plugin group to import (defaults to "content"). * * @return void * * @throws Exception if there is an error in the form event. * * @since 1.6 */ protected function preprocessForm(JForm $form, $data, $group = 'user') { if (JComponentHelper::getParams('com_users')->get('frontend_userparams')) { $form->loadFile('frontend', false); if (JFactory::getUser()->authorise('core.login.admin')) { $form->loadFile('frontend_admin', false); } } parent::preprocessForm($form, $data, $group); } /** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @return void * * @since 1.6 */ protected function populateState() { // Get the application object. $params = JFactory::getApplication()->getParams('com_users'); // Get the user id. $userId = JFactory::getApplication()->getUserState('com_users.edit.profile.id'); $userId = !empty($userId) ? $userId : (int) JFactory::getUser()->get('id'); // Set the user id. $this->setState('user.id', $userId); // Load the parameters. $this->setState('params', $params); } /** * Method to save the form data. * * @param array $data The form data. * * @return mixed The user id on success, false on failure. * * @since 1.6 */ public function save($data) { $userId = (!empty($data['id'])) ? $data['id'] : (int) $this->getState('user.id'); $user = new JUser($userId); // Prepare the data for the user object. $data['email'] = JStringPunycode::emailToPunycode($data['email1']); $data['password'] = $data['password1']; // Unset the username if it should not be overwritten $isUsernameCompliant = $this->getState('user.username.compliant'); if ($isUsernameCompliant && !JComponentHelper::getParams('com_users')->get('change_login_name')) { unset($data['username']); } // Unset block and sendEmail so they do not get overwritten unset($data['block'], $data['sendEmail']); // Handle the two factor authentication setup if (array_key_exists('twofactor', $data)) { $model = new UsersModelUser; $twoFactorMethod = $data['twofactor']['method']; // Get the current One Time Password (two factor auth) configuration $otpConfig = $model->getOtpConfig($userId); if ($twoFactorMethod !== 'none') { // Run the plugins FOFPlatform::getInstance()->importPlugin('twofactorauth'); $otpConfigReplies = FOFPlatform::getInstance()->runPlugins('onUserTwofactorApplyConfiguration', array($twoFactorMethod)); // Look for a valid reply foreach ($otpConfigReplies as $reply) { if (!is_object($reply) || empty($reply->method) || ($reply->method != $twoFactorMethod)) { continue; } $otpConfig->method = $reply->method; $otpConfig->config = $reply->config; break; } // Save OTP configuration. $model->setOtpConfig($userId, $otpConfig); // Generate one time emergency passwords if required (depleted or not set) if (empty($otpConfig->otep)) { $model->generateOteps($userId); } } else { $otpConfig->method = 'none'; $otpConfig->config = array(); $model->setOtpConfig($userId, $otpConfig); } // Unset the raw data unset($data['twofactor']); // Reload the user record with the updated OTP configuration $user->load($userId); } // Bind the data. if (!$user->bind($data)) { $this->setError(JText::sprintf('COM_USERS_PROFILE_BIND_FAILED', $user->getError())); return false; } // Load the users plugin group. JPluginHelper::importPlugin('user'); // Retrieve the user groups so they don't get overwritten unset($user->groups); $user->groups = JAccess::getGroupsByUser($user->id, false); // Store the data. if (!$user->save()) { $this->setError($user->getError()); return false; } // Destroy all active sessions for the user after changing the password if ($data['password']) { UserHelper::destroyUserSessions($user->id, true); } return $user->id; } /** * Gets the configuration forms for all two-factor authentication methods * in an array. * * @param integer $userId The user ID to load the forms for (optional) * * @return array * * @since 3.2 */ public function getTwofactorform($userId = null) { $userId = (!empty($userId)) ? $userId : (int) $this->getState('user.id'); $model = new UsersModelUser; $otpConfig = $model->getOtpConfig($userId); FOFPlatform::getInstance()->importPlugin('twofactorauth'); return FOFPlatform::getInstance()->runPlugins('onUserTwofactorShowConfiguration', array($otpConfig, $userId)); } /** * Returns the one time password (OTP) – a.k.a. two factor authentication – * configuration for a particular user. * * @param integer $userId The numeric ID of the user * * @return stdClass An object holding the OTP configuration for this user * * @since 3.2 */ public function getOtpConfig($userId = null) { $userId = (!empty($userId)) ? $userId : (int) $this->getState('user.id'); $model = new UsersModelUser; return $model->getOtpConfig($userId); } } home/digilove/public_html/components/com_users/controllers/profile.php 0000644 00000013641 15235600535 0022514 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_users * * @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; JLoader::register('UsersController', JPATH_COMPONENT . '/controller.php'); /** * Profile controller class for Users. * * @since 1.6 */ class UsersControllerProfile extends UsersController { /** * Method to check out a user for editing and redirect to the edit form. * * @return boolean * * @since 1.6 */ public function edit() { $app = JFactory::getApplication(); $user = JFactory::getUser(); $loginUserId = (int) $user->get('id'); // Get the previous user id (if any) and the current user id. $previousId = (int) $app->getUserState('com_users.edit.profile.id'); $userId = $this->input->getInt('user_id'); // Check if the user is trying to edit another users profile. if ($userId != $loginUserId) { $app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'), 'error'); $app->setHeader('status', 403, true); return false; } $cookieLogin = $user->get('cookieLogin'); // Check if the user logged in with a cookie if (!empty($cookieLogin)) { // If so, the user must login to edit the password and other data. $app->enqueueMessage(JText::_('JGLOBAL_REMEMBER_MUST_LOGIN'), 'message'); $this->setRedirect(JRoute::_('index.php?option=com_users&view=login', false)); return false; } // Set the user id for the user to edit in the session. $app->setUserState('com_users.edit.profile.id', $userId); // Get the model. $model = $this->getModel('Profile', 'UsersModel'); // Check out the user. if ($userId) { $model->checkout($userId); } // Check in the previous user. if ($previousId) { $model->checkin($previousId); } // Redirect to the edit screen. $this->setRedirect(JRoute::_('index.php?option=com_users&view=profile&layout=edit', false)); return true; } /** * Method to save a user's profile data. * * @return void * * @since 1.6 */ public function save() { // Check for request forgeries. $this->checkToken(); $app = JFactory::getApplication(); $model = $this->getModel('Profile', 'UsersModel'); $user = JFactory::getUser(); $userId = (int) $user->get('id'); // Get the user data. $requestData = $app->input->post->get('jform', array(), 'array'); // Force the ID to this user. $requestData['id'] = $userId; // Validate the posted data. $form = $model->getForm(); if (!$form) { JError::raiseError(500, $model->getError()); return false; } // Send an object which can be modified through the plugin event $objData = (object) $requestData; $app->triggerEvent( 'onContentNormaliseRequestData', array('com_users.user', $objData, $form) ); $requestData = (array) $objData; // Validate the posted data. $data = $model->validate($form, $requestData); // Check for errors. if ($data === false) { // Get the validation messages. $errors = $model->getErrors(); // Push up to three validation messages out to the user. for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) { if ($errors[$i] instanceof Exception) { $app->enqueueMessage($errors[$i]->getMessage(), 'warning'); } else { $app->enqueueMessage($errors[$i], 'warning'); } } // Unset the passwords. unset($requestData['password1'], $requestData['password2']); // Save the data in the session. $app->setUserState('com_users.edit.profile.data', $requestData); // Redirect back to the edit screen. $userId = (int) $app->getUserState('com_users.edit.profile.id'); $this->setRedirect(JRoute::_('index.php?option=com_users&view=profile&layout=edit&user_id=' . $userId, false)); return false; } // Attempt to save the data. $return = $model->save($data); // Check for errors. if ($return === false) { // Save the data in the session. $app->setUserState('com_users.edit.profile.data', $data); // Redirect back to the edit screen. $userId = (int) $app->getUserState('com_users.edit.profile.id'); $this->setMessage(JText::sprintf('COM_USERS_PROFILE_SAVE_FAILED', $model->getError()), 'warning'); $this->setRedirect(JRoute::_('index.php?option=com_users&view=profile&layout=edit&user_id=' . $userId, false)); return false; } // Redirect the user and adjust session state based on the chosen task. switch ($this->getTask()) { case 'apply': // Check out the profile. $app->setUserState('com_users.edit.profile.id', $return); $model->checkout($return); // Redirect back to the edit screen. $this->setMessage(JText::_('COM_USERS_PROFILE_SAVE_SUCCESS')); $redirect = $app->getUserState('com_users.edit.profile.redirect'); // Don't redirect to an external URL. if (!JUri::isInternal($redirect)) { $redirect = null; } if (!$redirect) { $redirect = 'index.php?option=com_users&view=profile&layout=edit&hidemainmenu=1'; } $this->setRedirect(JRoute::_($redirect, false)); break; default: // Check in the profile. $userId = (int) $app->getUserState('com_users.edit.profile.id'); if ($userId) { $model->checkin($userId); } // Clear the profile id from the session. $app->setUserState('com_users.edit.profile.id', null); $redirect = $app->getUserState('com_users.edit.profile.redirect'); // Don't redirect to an external URL. if (!JUri::isInternal($redirect)) { $redirect = null; } if (!$redirect) { $redirect = 'index.php?option=com_users&view=profile&user_id=' . $return; } // Redirect to the list screen. $this->setMessage(JText::_('COM_USERS_PROFILE_SAVE_SUCCESS')); $this->setRedirect(JRoute::_($redirect, false)); break; } // Flush the data from the session. $app->setUserState('com_users.edit.profile.data', null); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Генерация страницы: 0.01 |
proxy
|
phpinfo
|
Настройка