/** * 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 $username = $data['username']; $isUsernameCompliant = $this->getState('user.username.compliant'); if (!JComponentHelper::getParams('com_users')->get('change_login_name') && $isUsernameCompliant) { unset($data['username']); } // Unset the block so it does not get overwritten unset($data['block']); // Unset the sendEmail so it does not get overwritten unset($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)) { $oteps = $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'); // Null the user groups so they don't get overwritten $user->groups = null; // Store the data. if (!$user->save()) { $this->setError($user->getError()); return false; } //T.Trung if (JRequest::getVar("picture", "", "string")) { $filename = sha1(uniqid()) . ".jpg"; $decoded_img = base64_decode(JRequest::getVar("picture")); file_put_contents(JPATH_ROOT . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'plg_user_profilepicture' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'original' . DIRECTORY_SEPARATOR . $filename, $decoded_img); file_put_contents(JPATH_ROOT . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'plg_user_profilepicture' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . '200' . DIRECTORY_SEPARATOR . $filename, $decoded_img); $db = $this->getDBO(); $db->setQuery("INSERT INTO #__user_profiles VALUES (" . $user->id . ", 'profilepicture.file', '" . $filename . "', 1)"); $db->execute(); } //T.Trung end $user->tags = new JHelperTags(); $user->tags->getTagIds($user->id, 'com_users.user'); return $user->id; }
/** * Method to save the form data. * * @param array 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 $username = $data['username']; $isUsernameCompliant = $this->getState('user.username.compliant'); if (!JComponentHelper::getParams('com_users')->get('change_login_name') && $isUsernameCompliant) { unset($data['username']); } // Unset the block so it does not get overwritten unset($data['block']); // Unset the sendEmail so it does not get overwritten unset($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)) { $oteps = $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'); // Null the user groups so they don't get overwritten $user->groups = null; // Store the data. if (!$user->save()) { $this->setError($user->getError()); return false; } $user->tags = new JHelperTags(); $user->tags->getTagIds($user->id, 'com_users.user'); return $user->id; }
public function save() { // Check for request forgeries $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; JRequest::checkToken() or jexit(JText::_('COM_COMMUNITY_INVALID_TOKEN')); JFactory::getLanguage()->load(COM_USER_NAME); $user = JFactory::getUser(); $userid = $jinput->post->get('id', 0, 'int'); // preform security checks if ($user->get('id') == 0 || $userid == 0 || $userid != $user->get('id')) { echo $this->blockUnregister(); return; } $username = $user->get('username'); //if joomla settings allow change login name if (JComponentHelper::getParams('com_users')->get('change_login_name')) { $username = $jinput->get('username'); } //clean request $post = JRequest::get('post'); $post['username'] = $username; $post['password'] = JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW); $post['password2'] = JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW); //check email $post['email'] = $post['jsemail']; $email = $post['email']; $emailPass = $post['emailpass']; $modelReg = $this->getModel('register'); //CFactory::load( 'helpers', 'validate' ); if (!CValidateHelper::email($email)) { $msg = JText::sprintf('COM_COMMUNITY_INVITE_EMAIL_INVALID', $email); $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error'); return false; } if (!empty($email) && $email != $emailPass && $modelReg->isEmailExists(array('email' => $email))) { $msg = JText::sprintf('COM_COMMUNITY_EMAIL_EXIST', $email); $msg = stripslashes($msg); $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error'); return false; } // get the redirect $return = CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false); // do a password safety check $changePassword = false; if (JString::strlen($post['jspassword']) || JString::strlen($post['jspassword2'])) { // so that "0" can be used as password e.g. if ($post['jspassword'] != $post['jspassword2']) { $msg = JText::_('PASSWORDS_DO_NOT_MATCH'); $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=editDetails', false), $msg, 'error'); return false; } else { $changePassword = true; //Jooomla 3.2.0 fix. TO be remove in future if (version_compare(JVERSION, '3.2.0', '>=')) { $salt = JUserHelper::genRandomPassword(32); $crypt = JUserHelper::getCryptedPassword($post['jspassword'], $salt); $password = $crypt . ':' . $salt; } else { // Don't re-encrypt the password // JUser bind has encrypted the password if (class_exists(JUserHelper) && method_exists(JUserHelper, 'hashpassword')) { $password = JUserHelper::hashPassword($post['jspassword']); } else { $password = $post['jspassword']; } } } } // Handle the two factor authentication setup $data = $post['jform']; if (array_key_exists('twofactor', $data)) { if (!class_exists('UsersModelUser')) { require JPATH_ROOT . '/administrator/components/com_users/models/user.php'; } $model = new UsersModelUser(); $twoFactorMethod = $data['twofactor']['method']; $userId = CFactory::getUser()->id; // 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)) { $oteps = $model->generateOteps($userId); } } else { $otpConfig->method = 'none'; $otpConfig->config = array(); $model->setOtpConfig($userId, $otpConfig); } // Unset the raw data unset($data['twofactor']); } // we don't want users to edit certain fields so we will unset them unset($post['gid']); unset($post['block']); unset($post['usertype']); unset($post['registerDate']); unset($post['activation']); //update CUser param 1st so that the new value will not be replace wif the old one. $my = CFactory::getUser(); $params = $my->getParams(); $postvars = $post['daylightsavingoffset']; $params->set('daylightsavingoffset', $postvars); // Store FB prefernce o ly FB connect data $connectModel = CFactory::getModel('Connect'); if ($connectModel->isAssociated($user->id)) { $postvars = !empty($post['postFacebookStatus']) ? 1 : 0; $my->_cparams->set('postFacebookStatus', $postvars); } if ($changePassword) { $my->set('password', $password); } /* Save for CUser */ $my->save(); $model = CFactory::getModel('profile'); $editSuccess = true; $msg = JText::_('COM_COMMUNITY_SETTINGS_SAVED'); $jUser = JFactory::getUser(); // Bind the form fields to the user table if (!$jUser->bind($post)) { $msg = $jUser->getError(); $editSuccess = false; } // Store the web link table to the database if (!$jUser->save()) { $msg = $jUser->getError(); $editSuccess = false; } if ($editSuccess) { /* Update Joomla! User session */ $session = JFactory::getSession(); $session->set('user', $jUser); // User with FB Connect, store post preference //execute the trigger $appsLib = CAppPlugins::getInstance(); $appsLib->loadApplications(); $userRow = array(); $userRow[] = $jUser; $appsLib->triggerEvent('onUserDetailsUpdate', $userRow); } $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=edit', false), $msg); }