/** * Method to log in a user. * * @since 1.6 */ public function login() { JSession::checkToken('post') or jexit(JText::_('JInvalid_Token')); $app = JFactory::getApplication(); // Populate the data array: $data = array(); $data['return'] = base64_decode(JRequest::getVar('return', '', 'POST', 'BASE64')); $data['username'] = JRequest::getVar('username', '', 'method', 'username'); $data['password'] = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW); // Set the return URL if empty. if (empty($data['return'])) { $data['return'] = 'index.php?option=com_cvnusers&view=profile'; } // Set the return URL in the user state to allow modification by plugins $app->setUserState('users.login.form.return', $data['return']); // Get the log in options. $options = array(); $options['remember'] = JRequest::getBool('remember', false); $options['return'] = $data['return']; // Get the log in credentials. $credentials = array(); $credentials['username'] = $data['username']; $credentials['password'] = $data['password']; // Perform the log in. if (true === $app->login($credentials, $options)) { // Success // Kiểm tra xem đây có phải là email mặc địn hay không? $user = JFactory::getUser(); if (isEmailUpdated($user->email)) { $app->enqueueMessage(JText::_('COM_USERS_USER_MESSAGE')); $app->setUserState('users.login.form.data', array()); } $app->redirect(JRoute::_($app->getUserState('users.login.form.return'), false)); } else { // Login failed ! $data['remember'] = (int) $options['remember']; $app->setUserState('users.login.form.data', $data); $app->redirect(JRoute::_('index.php?option=com_cvnusers&view=login', false)); } }
/** * 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); // Lấy thông tin từ bảng player truyền kèm theo biến data $db =& JFactory::getDBO(); $query = "SELECT * FROM #__player WHERE userid = " . $userId; $db->setQuery($query); $result = $db->loadObjectList(); $mediaPath = JURI::base() . '/media/media_chessvn'; foreach ($result as $key => $value) { $this->data->coin = $value->coin; $this->data->birthday = $value->birthday; $this->data->address = $value->address; $this->data->occupation = $value->occupation; $this->data->aboutme = $value->aboutme; $this->data->avatar = $mediaPath . $value->mediaplayer . $value->avatar; $this->data->mediaplayer = '/media/media_chessvn/' . $value->mediaplayer; } // Kiểm tra xem email có phài mặc định không if (isEmailUpdated($this->data->email)) { $this->data->email = JText::_('COM_USERS_PROFILE_MESSAGE_MAIL'); } else { } // 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_cvnusers.edit.profile.data', array()); foreach ($temp as $k => $v) { $this->data->{$k} = $v; } // Unset the passwords. unset($this->data->password1); unset($this->data->password2); $registry = new JRegistry($this->data->params); $this->data->params = $registry->toArray(); // Get the dispatcher and load the users plugins. $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('user'); // Trigger the data preparation event. $results = $dispatcher->trigger('onContentPrepareData', array('com_cvnusers.profile', $this->data)); // Check for errors encountered while preparing the data. if (count($results) && in_array(false, $results, true)) { $this->setError($dispatcher->getError()); $this->data = false; } } return $this->data; }