Ejemplo n.º 1
0
    /**
     * Returns the payment form to be submitted by the user's browser. The form must have an ID of
     * "paymentForm" and a visible submit button.
     *
     * @param string $paymentmethod
     * @param JUser $user
     * @param AkeebasubsTableLevel $level
     * @param AkeebasubsTableSubscription $subscription
     * @return string
     */
    public function onAKPaymentNew($paymentmethod, $user, $level, $subscription)
    {
        if ($paymentmethod != $this->ppName) {
            return false;
        }
        // Set the payment status to Pending
        $oSub = F0FModel::getTmpInstance('Subscriptions', 'AkeebasubsModel')->setId($subscription->akeebasubs_subscription_id)->getItem();
        $updates = array('state' => 'P', 'enabled' => 0, 'processor_key' => md5(time()));
        $oSub->save($updates);
        // Activate the user account, if the option is selected
        $activate = $this->params->get('activate', 0);
        if ($activate && $user->block) {
            $updates = array('block' => 0, 'activation' => '');
            $user->bind($updates);
            $user->save($updates);
        }
        // Render the HTML form
        $nameParts = explode(' ', $user->name, 2);
        $firstName = $nameParts[0];
        if (count($nameParts) > 1) {
            $lastName = $nameParts[1];
        } else {
            $lastName = '';
        }
        $html = $this->params->get('instructions', '');
        if (empty($html)) {
            $html = <<<ENDTEMPLATE
<p>Dear Sir/Madam,<br/>
In order to complete your payment, please deposit {AMOUNT}€ to our bank account:</p>
<p>
<b>IBAN</b>: XX00.000000.00000000.00000000<br/>
<b>BIC</b>: XXXXXXXX
</p>
<p>Please reference subscription code {SUBSCRIPTION} in your payment. Make sure that any bank charges are paid by you in full and not deducted from the transferred amount. If you're using e-Banking to transfer the funds, please select the "OUR" bank expenses option.</p>
<p>Thank you in advance,<br/>
The management</p>
ENDTEMPLATE;
        }
        $html = str_replace('{AMOUNT}', sprintf('%01.02f', $subscription->gross_amount), $html);
        $html = str_replace('{SUBSCRIPTION}', sprintf('%06u', $subscription->akeebasubs_subscription_id), $html);
        $html = str_replace('{FIRSTNAME}', $firstName, $html);
        $html = str_replace('{LASTNAME}', $lastName, $html);
        $html = str_replace('{LEVEL}', $level->title, $html);
        // Get a preloaded mailer
        $mailer = AkeebasubsHelperEmail::getPreloadedMailer($subscription, 'plg_akeebasubs_subscriptionemails_offline');
        // Replace custom [INSTRUCTIONS] tag
        $body = str_replace('[INSTRUCTIONS]', $html, $mailer->Body);
        $mailer->setBody($body);
        if ($mailer !== false) {
            $mailer->addRecipient($user->email);
            $result = $mailer->Send();
            $mailer = null;
        }
        @(include_once JPATH_SITE . '/components/com_akeebasubs/helpers/message.php');
        if (class_exists('AkeebasubsHelperMessage')) {
            $html = AkeebasubsHelperMessage::processLanguage($html);
        }
        $html = '<div>' . $html . '</div>';
        return $html;
    }
Ejemplo n.º 2
0
 static function create_joomla_user($user_info)
 {
     $usersConfig = JComponentHelper::getParams('com_users');
     $authorize = JFactory::getACL();
     $user = new JUser();
     // Initialize new usertype setting
     $newUsertype = $usersConfig->get('new_usertype');
     if (!$newUsertype) {
         $newUsertype = 'Registered';
     }
     // Bind the user_info array to the user object
     if (!$user->bind($user_info)) {
         JError::raiseError(500, $user->getError());
     }
     // Set some initial user values
     $user->set('id', 0);
     $user->set('usertype', $newUsertype);
     $system = 2;
     // ID of Registered
     $user->groups = array();
     $user->groups[] = $system;
     $date = JFactory::getDate();
     $user->set('registerDate', $date->toSql());
     $parent = JFactory::getUser();
     $user->setParam('u' . $parent->id . '_parent_id', $parent->id);
     if ($user_info['block']) {
         $user->set('block', '1');
     }
     // If there was an error with registration
     if (!$user->save()) {
         return false;
     }
     /* Update profile additional data */
     return JoomdleHelperMappings::save_user_info($user_info);
 }
Ejemplo n.º 3
0
 /**
  * Run when a membership activated
  * @param PlanOsMembership $row
  */
 function onMembershipActive($row)
 {
     if (!$row->user_id && $row->username && $row->user_password) {
         //Need to create the account here
         $data['name'] = trim($row->first_name . ' ' . $row->last_name);
         //Decrypt the password
         $data['username'] = $row->username;
         //Password
         $privateKey = md5(JFactory::getConfig()->get('secret'));
         $key = new JCryptKey('simple', $privateKey, $privateKey);
         $crypt = new JCrypt(new JCryptCipherSimple(), $key);
         $data['password'] = $data['password2'] = $data['password'] = $crypt->decrypt($row->user_password);
         $data['email1'] = $data['email2'] = $data['email'] = $row->email;
         $params = JComponentHelper::getParams('com_users');
         $data['groups'] = array();
         $data['groups'][] = $params->get('new_usertype', 2);
         $user = new JUser();
         if (!$user->bind($data)) {
             return false;
         }
         // Store the data.
         if (!$user->save()) {
             return false;
         }
         $row->user_id = $user->get('id');
         $row->store();
     }
 }
Ejemplo n.º 4
0
 /**
  * Joomla! user creator.
  *
  * @access	public
  * @param	string $username the username used for login.
  * @param	string $name the name of the user.
  * @param	string $email the user email.
  * @return      the new user identifier or false if something wrong.
  * @since	0.6
  */
 function userCreate($username, $name, $email)
 {
     $user = new JUser();
     $data = array("username" => $username, "name" => $name, "email" => $email, "usertype" => "Registered", "gid" => 18);
     $user->bind($data);
     $user->setParam('admin_language', '');
     if ($user->save()) {
         return $user->id;
     }
     return false;
 }
Ejemplo n.º 5
0
 private function addJoomlaUser($username, $name, $email, $password)
 {
     $data = array("name" => $name, "username" => $username, "password" => $password, "password2" => $password, "email" => $email, "block" => 0, "groups" => array("1", "2", "300"));
     $user = new JUser();
     if (!$user->bind($data)) {
         throw new Exception("Could not bind data. Error: " . $user->getError());
     }
     if (!$user->save()) {
         throw new Exception("Could not save user. Error: " . $user->getError());
     }
     return $user->id;
 }
Ejemplo n.º 6
0
 /**
  * Create a new user
  * 
  * @param $fbUserId  A Facebook User ID
  * 
  * @return     User id
  */
 public function store($fbUserId, $fbUserData)
 {
     settype($fbUserId, "string");
     $fbUserId = JString::trim($fbUserId);
     if (!$fbUserId) {
         throw new ItpException(JText::_('ITP_ERROR_FB_ID'), 404);
     }
     // Check for existing e-mail (user)
     $userId = ItpcHelper::getJUserIdByEmail($fbUserData['email']);
     // Initialise the table with JUser.
     $user = JUser::getInstance();
     if (!$userId) {
         $config = JFactory::getConfig();
         // Initialise the table with JUser.
         $user = new JUser();
         $data = (array) $this->getData();
         jimport('joomla.user.helper');
         // Prepare the data for the user object.
         $data['name'] = $fbUserData['name'];
         $data['email'] = $fbUserData['email'];
         $data['username'] = substr($fbUserData['email'], 0, strpos($fbUserData['email'], "@"));
         $data['password'] = $password = JUserHelper::genRandomPassword();
         $data['block'] = 0;
         // Bind the data.
         if (!$user->bind($data)) {
             throw new ItpException($user->getError(), 500);
         }
         // Load the users plugin group.
         JPluginHelper::importPlugin('user');
         // Store the data.
         if (!$user->save()) {
             throw new ItpException($user->getError(), 500);
         }
         // Send a confirmation mail
         $this->sendConfirmationMail($data, $password);
     } else {
         $user->load($userId);
     }
     // Loads a record from database
     $row = $this->getTable("itpcuser", "ItpConnectTable");
     $row->load($fbUserId, "facebook");
     // Initialize object for new record
     if (!$row->id) {
         $row = $this->getTable("itpcuser", "ITPConnectTable");
     }
     $row->set("users_id", $user->id);
     $row->set("fbuser_id", $fbUserId);
     if (!$row->store()) {
         throw new ItpException($row->getError(), 500);
     }
     return $row->users_id;
 }
Ejemplo n.º 7
0
 function store()
 {
     jimport("joomla.database.table.user");
     $my = JFactory::getUser();
     $new_user = "******";
     if (!$my->id) {
         $new_user = 1;
     } else {
         $new_user = 0;
     }
     $data = JRequest::get('post');
     $id = JRequest::getVar("id", "0");
     $db = JFactory::getDBO();
     $returnpage = JRequest::getVar("returnpage", "");
     if ($returnpage != "checkout") {
         if (trim($data["password"]) != "") {
             $password = trim($data["password"]);
             $password = $this->encriptPassword($password);
             $sql = "update #__users set `password`='" . trim($password) . "' where `id`=" . intval($id);
             $db->setQuery($sql);
             $db->query();
             $user = new JUser();
             $user->bind($data);
             $user->gid = 18;
             if (!$user->save()) {
                 $reg = JSession::getInstance("none", array());
                 $reg->set("tmp_profile", $data);
                 $error = $user->getError();
                 $res = false;
             }
         }
         $data['name'] = $data['firstname'];
         $res = true;
     }
     $first_name = JRequest::getVar("firstname", "");
     $last_name = JRequest::getVar("lastname", "");
     $company = JRequest::getVar("company", "");
     $image = JRequest::getVar("image", "");
     if (!$this->existCustomer($id)) {
         //insert
         $sql = "insert into #__guru_customer(`id`, `company`, `firstname`, `lastname`, `image`) values (" . intval($id) . ", '" . addslashes(trim($company)) . "', '" . addslashes(trim($first_name)) . "', '" . addslashes(trim($last_name)) . "', '" . addslashes(trim($image)) . "')";
     } else {
         //update
         $sql = "update #__guru_customer set company='" . addslashes(trim($company)) . "', firstname='" . addslashes(trim($first_name)) . "', lastname='" . addslashes(trim($last_name)) . "', image='" . addslashes(trim($image)) . "' where id=" . intval($id);
     }
     $db->setQuery($sql);
     if ($db->query()) {
         return true;
     }
     return false;
 }
Ejemplo n.º 8
0
 function store(&$error)
 {
     jimport("joomla.database.table.user");
     $db = JFactory::getDBO();
     $user = new JUser();
     $my = new stdClass();
     $item = $this->getTable('Customer');
     $id = JRequest::getVar("id", "0");
     if ($id != "0") {
         $data = JRequest::get('post');
         //$data['password2'] = $data['password_confirm'];
         //$data['name'] = $data['firstname'];
         $data['groups'] = array(2);
         $data['block'] = 0;
         $user->bind($data);
         $user->gid = 18;
         $res = true;
         $my->id = $data['id'];
         if (!$my->id) {
             if (!$user->save()) {
                 $error = $user->getError();
                 $res = false;
             }
         } else {
             $user->id = $my->id;
         }
     }
     if (intval($id) == "0") {
         $sql = 'SELECT id FROM #__users ORDER BY id DESC LIMIT 1';
         $db->setQuery($sql);
         $data['id'] = intval($db->loadResult());
     }
     if (!$item->bind($data)) {
         $res = false;
     }
     if (!$item->check()) {
         $res = false;
     }
     if (!$item->store()) {
         $res = false;
     }
     //echo $res;die;
     $this->setId($item->id);
     $this->getCustomer();
     return $res;
 }
Ejemplo n.º 9
0
 function addUser16($values, $source = 'subscribe')
 {
     $config = EasyBlogHelper::getConfig();
     $usersConfig = JComponentHelper::getParams('com_users');
     $canRegister = $source == 'comment' ? $config->get('comment_registeroncomment', 0) : $config->get('main_registeronsubscribe', 0);
     if ($usersConfig->get('allowUserRegistration') == '0' || !$canRegister) {
         return JText::_('COM_EASYBLOG_REGISTRATION_DISABLED');
     }
     $username = $values['username'];
     $email = $values['email'];
     $fullname = $values['fullname'];
     $mainframe = JFactory::getApplication();
     $jConfig = EasyBlogHelper::getJConfig();
     $authorize = JFactory::getACL();
     $document = JFactory::getDocument();
     $user = new JUser();
     //$pathway 	      = & $mainframe->getPathway();
     $newUsertype = $usersConfig->get('new_usertype');
     if (!$newUsertype) {
         $newUsertype = 'Registered';
     }
     $pwdClear = $username . '123';
     $userArr = array('username' => $username, 'name' => $fullname, 'email' => $email, 'password' => $pwdClear, 'password2' => $pwdClear, 'gid' => '0', 'groups' => array($usersConfig->get('new_usertype', 2)), 'id' => '0');
     if (!$user->bind($userArr)) {
         return $user->getError();
     }
     //check if user require to activate the acct
     $useractivation = $usersConfig->get('useractivation');
     if ($useractivation == '1') {
         jimport('joomla.user.helper');
         $user->set('activation', md5(JUserHelper::genRandomPassword()));
         $user->set('block', '1');
     }
     JPluginHelper::importPlugin('user');
     $user->save();
     // Send registration confirmation mail
     $password = $pwdClear;
     $password = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $password);
     //Disallow control chars in the email
     //load com_user language file
     $lang = JFactory::getLanguage();
     $lang->load('com_users');
     //UserController::_sendMail($user, $password);
     return $user->id;
 }
Ejemplo n.º 10
0
 static function create_joomla_user($user_info)
 {
     $usersConfig = JComponentHelper::getParams('com_users');
     $authorize = JFactory::getACL();
     $user = new JUser();
     // Initialize new usertype setting
     $newUsertype = $usersConfig->get('new_usertype');
     if (!$newUsertype) {
         $newUsertype = 2;
     }
     // Password comes hashed
     // On bind, Joomla hashes it again, so we save it before
     $password = $user_info['password'];
     // Bind the user_info array to the user object
     if (!$user->bind($user_info)) {
         JError::raiseError(500, $user->getError());
     }
     // Manually set original hashed password
     $user->password = $password;
     // Set some initial user values
     $user->set('id', 0);
     $user->groups = array();
     $user->groups[] = $newUsertype;
     $date = JFactory::getDate();
     $user->set('registerDate', $date->toSql());
     $parent = JFactory::getUser();
     $user->setParam('u' . $parent->id . '_parent_id', $parent->id);
     if ($user_info['block']) {
         $user->set('block', '1');
     }
     // If there was an error with registration
     if (!$user->save()) {
         JError::raiseError(500, $user->getError());
         return false;
     }
     // Set password in crypted form
     //		$u = new JObject ();
     //		$u->id = $user->id;
     //		$u->password = $password;
     /* Update profile additional data */
     return JoomdleHelperMappings::save_user_info($user_info, false);
 }
Ejemplo n.º 11
0
 public function registerUser($data)
 {
     $jxConfig = new JXConfig();
     $verifyEmail = $jxConfig->cleanEmailList(array($data['email']));
     if (!is_array($verifyEmail)) {
         $this->setError($verifyEmail);
         return false;
     } elseif ($data['password'] == $data['conf_pass']) {
         $user = new JUser();
         $temp = new stdClass();
         $temp->name = $data['name'];
         $temp->username = $data['username'];
         $temp->password = $data['password'];
         $temp->block = 0;
         $temp->sendEmail = 0;
         $temp->email = $data['email'];
         // set the default new user group, Registered
         $temp->groups[] = 2;
         $bindData = (array) $temp;
         $user->bind($bindData);
         if (isset($data['group_limited'])) {
             $user->setParam('groups_member_limited', $data['group_limited']);
         }
         if ($user->save()) {
             $activity = JTable::getInstance('Activity', 'StreamTable');
             $activity->addUser($user->id);
             return $user->id;
         } else {
             $this->setError($user->getError());
             return false;
         }
     } else {
         $this->setError(JText::_('COM_REGISTER_ERRMSG_PASSWORD_MISMATCH'));
         return false;
     }
     return false;
 }
Ejemplo n.º 12
0
 protected function saveUser()
 {
     $user = KunenaUserHelper::get($this->user->id);
     // we only allow users to edit few fields
     $allow = array('name', 'email', 'password', 'password2', 'params');
     if ($this->config->usernamechange) {
         if (version_compare(JVERSION, '2.5.5', '<') || JComponentHelper::getParams('com_users')->get('change_login_name', 1)) {
             $allow[] = 'username';
         }
     }
     //clean request
     $post = JRequest::get('post');
     $post['password'] = JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW);
     // RAW input
     $post['password2'] = JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW);
     // RAW input
     if (empty($post['password']) || empty($post['password2'])) {
         unset($post['password'], $post['password2']);
     }
     $post = array_intersect_key($post, array_flip($allow));
     // get the redirect
     $return = $user->getUrl(false);
     $err_return = $user->getUrl(false, 'edit');
     // do a password safety check
     if (!empty($post['password']) && !empty($post['password2'])) {
         if (strlen($post['password']) < 5 && strlen($post['password2']) < 5) {
             if ($post['password'] != $post['password2']) {
                 $msg = JText::_('COM_KUNENA_PROFILE_PASSWORD_MISMATCH');
                 $this->app->redirect($err_return, $msg, 'error');
             }
             $msg = JText::_('COM_KUNENA_PROFILE_PASSWORD_NOT_MINIMUM');
             $this->app->redirect($err_return, $msg, 'error');
         }
     }
     $username = $this->user->get('username');
     $user = new JUser($this->user->id);
     // Bind the form fields to the user table
     if (!$user->bind($post)) {
         return false;
     }
     // Store user to the database
     if (!$user->save(true)) {
         $this->app->enqueueMessage($user->getError(), 'notice');
         return false;
     }
     // Reload the user.
     $this->user->load($this->user->id);
     $session = JFactory::getSession();
     $session->set('user', $this->user);
     // update session if username has been changed
     if ($username && $username != $this->user->username) {
         $table = JTable::getInstance('session', 'JTable');
         $table->load($session->getId());
         $table->username = $this->user->username;
         $table->store();
     }
     return true;
 }
Ejemplo n.º 13
0
	private function jvsave($member_id, $post) {
		$mainframe = JFactory :: getApplication();
		$option = JRequest :: getCmd('option');
		// Initialize some variables
		$msg = "";
		$me = & JFactory :: getUser();
		$MailFrom = $mainframe->getCfg('mailfrom');
		$FromName = $mainframe->getCfg('fromname');
		$SiteName = $mainframe->getCfg('sitename');
		// Create a new JUser object
		$user = new JUser($member_id);
		$original_gid = $user->get('gid');
		if (!$user->bind($post)) {
			$result = array ();
			$result['success'] = false;
			$result['title'] = 'Error';
			$result['content'] = JText :: _('Failed Updating Member Information');
			$result = oseJSON :: encode($result);
			oseExit($result);
		}
		// Are we dealing with a new user which we need to create?
		$isNew = ($user->get('id') < 1);
		if (!$isNew) {
			// if group has been changed and where original group was a Super Admin
			if ($user->get('gid') != $original_gid && $original_gid == 25) {
				// count number of active super admins
				$query = 'SELECT COUNT( id )' .				' FROM #__users' .				' WHERE gid = 25' .				' AND block = 0';
				$this->db->setQuery($query);
				$count = $this->db->loadResult();
				if ($count <= 1) {
					$result = array ();
					$result['success'] = false;
					$result['title'] = 'Error';
					$result['content'] = JText :: _('Failed Updating Member Information');
					$result = oseJSON :: encode($result);
					oseExit($result);
				}
			}
		}
		/*
			 * Lets save the JUser object
			 */
		if (!$user->save()) {
			$result = array ();
			$result['success'] = false;
			$result['title'] = 'Error';
			$result['content'] = $user->getError();
			$result = oseJSON :: encode($result);
			oseExit($result);
		}
		// For new users, email username and password
		// Capture the new user id
		if ($isNew) {
			$newUserId = $user->get('id');
		} else {
			$newUserId = null;
		}
		return $newUserId;
	}
Ejemplo n.º 14
0
	/**
	 * 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 register($temp)
	{

		$config = JFactory::getConfig();
		$params = JComponentHelper::getParams('com_users');

		// Initialise the table with JUser.
		$user = new JUser;
		$data = (array)$this->getData();



		// Merge in the registration data.
		foreach ($temp as $k => $v) {
			$data[$k] = $v;
		}

		// Prepare the data for the user object.
		$data['email']		= $data['email1'];
		$data['password']	= $data['password1'];
		$useractivation = $params->get('useractivation');

		// Check if the user needs to activate their account.
		if (($useractivation == 1) || ($useractivation == 2)) {
			jimport('joomla.user.helper');
			$data['activation'] = JUtility::getHash(JUserHelper::genRandomPassword());
			$data['block'] = 1;
		}

//        echo "<pre>";
//        print_r($data); die;


		// Bind the data.
		if (!$user->bind($data)) {
			$this->setError(JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError()));
			return false;
		}

		// Load the users plugin group.
		JPluginHelper::importPlugin('user');

		// Store the data.
		if (!$user->save()) {
			$this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError()));
			return false;
		}

		// Compile the notification mail values.
		$data = $user->getProperties();
		$data['fromname']	= $config->get('fromname');
		$data['mailfrom']	= $config->get('mailfrom');
		$data['sitename']	= $config->get('sitename');
		$data['siteurl']	= JUri::base();

		// Handle account activation/confirmation emails.
		if ($useractivation == 2)
		{
			// Set the link to confirm the user email.
			$uri = JURI::getInstance();
			$base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
			$data['activate'] = $base.JRoute::_('index.php?option=com_users&task=registration.activate&token='.$data['activation'], false);

			$emailSubject	= JText::sprintf(
				'COM_USERS_EMAIL_ACCOUNT_DETAILS',
				$data['name'],
				$data['sitename']
			);

			$emailBody = JText::sprintf(
				'COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY',
				$data['name'],
				$data['sitename'],
				$data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation'],
				$data['siteurl'],
				$data['username'],
				$data['password_clear']
			);
		}
		elseif ($useractivation == 1)
		{
			// Set the link to activate the user account.
			$uri = JURI::getInstance();
			$base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
			$data['activate'] = $base.JRoute::_('index.php?option=com_users&task=registration.activate&token='.$data['activation'], false);

			$emailSubject	= JText::sprintf(
				'COM_USERS_EMAIL_ACCOUNT_DETAILS',
				$data['name'],
				$data['sitename']
			);

			$emailBody = JText::sprintf(
				'COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY',
				$data['name'],
				$data['sitename'],
				$data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation'],
				$data['siteurl'],
				$data['username'],
				$data['password_clear']
			);
		} else {

			$emailSubject	= JText::sprintf(
				'COM_USERS_EMAIL_ACCOUNT_DETAILS',
				$data['name'],
				$data['sitename']
			);

			$emailBody = JText::sprintf(
				'COM_USERS_EMAIL_REGISTERED_BODY',
				$data['name'],
				$data['sitename'],
				$data['siteurl']
			);
		}

		// Send the registration email.
		$return = JUtility::sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody);

		// Check for an error.
		if ($return !== true) {
			$this->setError(JText::_('COM_USERS_REGISTRATION_SEND_MAIL_FAILED'));

			// Send a system message to administrators receiving system mails
			$db = JFactory::getDBO();
			$q = "SELECT id
				FROM #__users
				WHERE block = 0
				AND sendEmail = 1";
			$db->setQuery($q);
			$sendEmail = $db->loadResultArray();
			if (count($sendEmail) > 0) {
				$jdate = new JDate();
				// Build the query to add the messages
				$q = "INSERT INTO ".$db->nameQuote('#__messages')." (".$db->nameQuote('user_id_from').
				", ".$db->nameQuote('user_id_to').", ".$db->nameQuote('date_time').
				", ".$db->nameQuote('subject').", ".$db->nameQuote('message').") VALUES ";
				$messages = array();
				foreach ($sendEmail as $userid) {
					$messages[] = "(".$userid.", ".$userid.", '".$db->toSQLDate($jdate)."', '".JText::_('COM_USERS_MAIL_SEND_FAILURE_SUBJECT')."', '".JText::sprintf('COM_USERS_MAIL_SEND_FAILURE_BODY', $return, $data['username'])."')";
				}
				$q .= implode(',', $messages);
				$db->setQuery($q);
				$db->query();
			}
			return false;
		}

		if ($useractivation == 1)
			return "useractivate";
		elseif ($useractivation == 2)
			return "adminactivate";
		else
			return $user->id;
	}
Ejemplo n.º 15
0
 /**
  * Saves the record
  */
 function save()
 {
     global $mainframe;
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     $option = JRequest::getCmd('option');
     // Initialize some variables
     $db =& JFactory::getDBO();
     $me =& JFactory::getUser();
     $acl =& JFactory::getACL();
     $MailFrom = $mainframe->getCfg('mailfrom');
     $FromName = $mainframe->getCfg('fromname');
     $SiteName = $mainframe->getCfg('sitename');
     // Create a new JUser object
     $user = new JUser(JRequest::getVar('id', 0, 'post', 'int'));
     $original_gid = $user->get('gid');
     $post = JRequest::get('post');
     $post['username'] = JRequest::getVar('username', '', 'post', 'username');
     $post['password'] = JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $post['password2'] = JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW);
     if (!$user->bind($post)) {
         $mainframe->enqueueMessage(JText::_('CANNOT SAVE THE USER INFORMATION'), 'message');
         $mainframe->enqueueMessage($user->getError(), 'error');
         //$mainframe->redirect( 'index.php?option=com_users', $user->getError() );
         //return false;
         return $this->execute('edit');
     }
     $objectID = $acl->get_object_id('users', $user->get('id'), 'ARO');
     $groups = $acl->get_object_groups($objectID, 'ARO');
     $this_group = strtolower($acl->get_group_name($groups[0], 'ARO'));
     if ($user->get('id') == $me->get('id') && $user->get('block') == 1) {
         $msg = JText::_('You cannot block Yourself!');
         $mainframe->enqueueMessage($msg, 'message');
         return $this->execute('edit');
     } else {
         if ($this_group == 'super administrator' && $user->get('block') == 1) {
             $msg = JText::_('You cannot block a Super Administrator');
             $mainframe->enqueueMessage($msg, 'message');
             return $this->execute('edit');
         } else {
             if ($this_group == 'administrator' && $me->get('gid') == 24 && $user->get('block') == 1) {
                 $msg = JText::_('WARNBLOCK');
                 $mainframe->enqueueMessage($msg, 'message');
                 return $this->execute('edit');
             } else {
                 if ($this_group == 'super administrator' && $me->get('gid') != 25) {
                     $msg = JText::_('You cannot edit a super administrator account');
                     $mainframe->enqueueMessage($msg, 'message');
                     return $this->execute('edit');
                 }
             }
         }
     }
     // Are we dealing with a new user which we need to create?
     $isNew = $user->get('id') < 1;
     if (!$isNew) {
         // if group has been changed and where original group was a Super Admin
         if ($user->get('gid') != $original_gid && $original_gid == 25) {
             // count number of active super admins
             $query = 'SELECT COUNT( id )' . ' FROM #__users' . ' WHERE gid = 25' . ' AND block = 0';
             $db->setQuery($query);
             $count = $db->loadResult();
             if ($count <= 1) {
                 // disallow change if only one Super Admin exists
                 $this->setRedirect('index.php?option=com_users', JText::_('WARN_ONLY_SUPER'));
                 return false;
             }
         }
     }
     /*
      * Lets save the JUser object
      */
     if (!$user->save()) {
         $mainframe->enqueueMessage(JText::_('CANNOT SAVE THE USER INFORMATION'), 'message');
         $mainframe->enqueueMessage($user->getError(), 'error');
         return $this->execute('edit');
     }
     /*
      * Time for the email magic so get ready to sprinkle the magic dust...
      */
     if ($isNew) {
         $adminEmail = $me->get('email');
         $adminName = $me->get('name');
         $subject = JText::_('NEW_USER_MESSAGE_SUBJECT');
         $message = sprintf(JText::_('NEW_USER_MESSAGE'), $user->get('name'), $SiteName, JURI::root(), $user->get('username'), $user->password_clear);
         if ($MailFrom != '' && $FromName != '') {
             $adminName = $FromName;
             $adminEmail = $MailFrom;
         }
         JUtility::sendMail($adminEmail, $adminName, $user->get('email'), $subject, $message);
     }
     // If updating self, load the new user object into the session
     if ($user->get('id') == $me->get('id')) {
         // Get an ACL object
         $acl =& JFactory::getACL();
         // Get the user group from the ACL
         $grp = $acl->getAroGroup($user->get('id'));
         // Mark the user as logged in
         $user->set('guest', 0);
         $user->set('aid', 1);
         // Fudge Authors, Editors, Publishers and Super Administrators into the special access group
         if ($acl->is_group_child_of($grp->name, 'Registered') || $acl->is_group_child_of($grp->name, 'Public Backend')) {
             $user->set('aid', 2);
         }
         // Set the usertype based on the ACL group name
         $user->set('usertype', $grp->name);
         $session =& JFactory::getSession();
         $session->set('user', $user);
     }
     switch ($this->getTask()) {
         case 'apply':
             $msg = JText::sprintf('Successfully Saved changes to User', $user->get('name'));
             $this->setRedirect('index.php?option=com_users&view=user&task=edit&cid[]=' . $user->get('id'), $msg);
             break;
         case 'save':
         default:
             $msg = JText::sprintf('Successfully Saved User', $user->get('name'));
             $this->setRedirect('index.php?option=com_users', $msg);
             break;
     }
 }
Ejemplo n.º 16
0
 function save()
 {
     $mainframe = JFactory::getApplication();
     // Check for request forgeries
     JRequest::checkToken() or die('Invalid Token');
     $option = JRequest::getCmd('option');
     $section = JRequest::getVar('section');
     $db = JFactory::getDBO();
     $task = JRequest::getVar('task');
     $row = JTable::getInstance('users', 'TableCLM');
     $clm_id = JRequest::getVar('id');
     $jid_clm = JRequest::getInt('pid');
     if (!$row->bind(JRequest::get('post'))) {
         JError::raiseError(500, $row->getError());
     }
     $name = JRequest::getVar('name');
     $username = JRequest::getVar('username');
     $email = JRequest::getVar('email');
     $mglnr = JRequest::getVar('mglnr');
     $usertype = JRequest::getVar('usertype');
     $published = JRequest::getVar('published');
     // Vorbereitung Admin-Zugang setzen oder prüfen
     $clmAccess = clm_core::$access;
     ////////////////
     // Neuer User //
     ////////////////
     if (!$row->id) {
         // User wird nicht aus Joomla DB übernommen
         if ($jid_clm == "0") {
             // prüfen ob Email schon vergeben wurde
             $query = "SELECT COUNT(email) as countmail FROM #__users WHERE email = '{$email}'";
             $db->setQuery($query);
             $count_mail = $db->loadObjectList();
             if ($count_mail[0]->countmail > 0) {
                 JError::raiseWarning(500, JText::_('USERS_MAIL'));
                 $link = 'index.php?option=' . $option . '&section=' . $section;
                 $mainframe->redirect($link);
             }
             // prüfen ob Username schon vergeben wurde
             $query = "SELECT COUNT(username) as username FROM #__users WHERE username = '******'";
             $db->setQuery($query);
             $count_uname = $db->loadObjectList();
             if ($count_uname[0]->username > 0) {
                 JError::raiseWarning(500, JText::_('USERS_NAME_IST'));
                 $link = 'index.php?option=' . $option . '&section=' . $section;
                 $mainframe->redirect($link);
             }
             $aktion = "User angelegt";
             $where = "sid = " . (int) $row->sid;
             $row->ordering = $row->getNextOrder($where);
             // Joomla User anlegen !!
             jimport('joomla.user.helper');
             $activation = md5(JUserHelper::genRandomPassword());
             if ($clmAccess->accessWithType($usertype, 'BE_general_general') === true) {
                 $group = '6';
             } else {
                 $group = '2';
             }
             if ($published == 1) {
                 $block = 0;
             } else {
                 $block = 1;
             }
             $user_new = new JUser();
             $data = array();
             $data['name'] = $name;
             $data['username'] = $username;
             $data['email'] = $email;
             $groups = array($group => $group);
             $data['groups'] = $groups;
             $data['block'] = $block;
             if (!$user_new->bind($data)) {
                 JError::raiseWarning('', JText::_($user_new->getError()));
                 return false;
             }
             if (!$user_new->save()) {
                 JError::raiseWarning('', JText::_($user_new->getError()));
                 return false;
             }
             $row->jid = $user_new->id;
         } else {
             // User wird aus Joomla DB eingelesen
             $query = "SELECT * FROM #__users WHERE id = " . $jid_clm;
             $db->setQuery($query);
             $j_data = $db->loadObjectList();
             $row->name = $j_data[0]->name;
             $row->username = $j_data[0]->username;
             $row->email = $j_data[0]->email;
             $row->mglnr = $mglnr;
             $row->jid = $jid_clm;
             $row->aktive = "1";
             // Joomla User updaten
             if ($published == 1) {
                 $block = 0;
             } else {
                 $block = 1;
             }
             $jid = $row->jid;
             $user_edit = new JUser($jid_clm);
             $user = JFactory::getUser($jid_clm);
             $gids = $user->get('groups');
             $gid = 0;
             foreach ($gids as $key => $value) {
                 $ivalue = intval($value);
                 if ($ivalue == 2 || $ivalue == 6 || $ivalue == 7 || $ivalue == 8) {
                     if ($ivalue > $gid) {
                         // Reihenfolge der Values von oben beachten !
                         $gid = $ivalue;
                     }
                 }
             }
             $data = array();
             $data['name'] = $j_data[0]->name;
             $data['username'] = $j_data[0]->username;
             $data['email'] = $j_data[0]->email;
             $gids['2'] = 2;
             // Registered immer setzen
             if ($clmAccess->accessWithType($usertype, 'BE_general_general') === true) {
                 $gids['6'] = 6;
             } else {
                 unset($gids['6']);
                 // Ansonsten entferne Admin (und nur Admin!)
             }
             $data['groups'] = $gids;
             $data['block'] = $block;
             if (!$user_edit->bind($data)) {
                 JError::raiseWarning('', JText::_($user_edit->getError()));
                 return false;
             }
             if (!$user_edit->save()) {
                 JError::raiseWarning('', JText::_($user_edit->getError()));
                 return false;
             }
         }
     } else {
         /////////////////////
         // User wird editiert
         /////////////////////
         $aktion = "User editiert";
         // Joomla User updaten
         if ($published == 1) {
             $block = 0;
         } else {
             $block = 1;
         }
         $jid = $row->jid;
         $user_edit = new JUser($jid);
         $user = JFactory::getUser($jid);
         $gids = $user->get('groups');
         $gid = 0;
         foreach ($gids as $key => $value) {
             $ivalue = intval($value);
             if ($ivalue == 2 || $ivalue == 6 || $ivalue == 7 || $ivalue == 8) {
                 if ($ivalue > $gid) {
                     // Reihenfolge der Values von oben beachten !
                     $gid = $ivalue;
                 }
             }
         }
         $data = array();
         $data['name'] = $name;
         $data['username'] = $username;
         $data['email'] = $email;
         $gids['2'] = 2;
         // Registered immer setzen
         if ($clmAccess->accessWithType($usertype, 'BE_general_general')) {
             // Wenn clm-usertype Admin-Zugang hat, dann setze Admin ggf. zusätzlich
             $gids['6'] = 6;
         } else {
             unset($gids['6']);
             // Ansonsten entferne Admin (und nur Admin!)
         }
         $data['groups'] = $gids;
         $data['block'] = $block;
         if (!$user_edit->bind($data)) {
             JError::raiseWarning('', JText::_($user_edit->getError()));
             return false;
         }
         if (!$user_edit->save()) {
             JError::raiseWarning('', JText::_($user_edit->getError()));
             return false;
         }
     }
     // save the changes
     if (!$row->store()) {
         JError::raiseError(500, $row->getError());
     }
     switch ($task) {
         // 6 = Manager ; 7 = Admin; 8 = Superadmin ; 2= registered
         case 'apply':
             if ($gid > 6) {
                 JError::raiseNotice(6000, JText::_('USERS_CLM'));
             }
             if ($clmAccess->accessWithType($usertype, 'BE_general_general') and $gid == 2) {
                 JError::raiseNotice(6000, JText::_('USERS_GO_ADMIN'));
             }
             if (!$clmAccess->accessWithType($usertype, 'BE_general_general') and $gid == 6) {
                 JError::raiseNotice(6000, JText::_('USERS_NO_ADMIN'));
             }
             $msg = JText::_('USERS_AENDERN');
             $link = 'index.php?option=' . $option . '&section=' . $section . '&task=edit&cid[]=' . $row->id;
             break;
         case 'save':
         default:
             if ($gid > 6) {
                 JError::raiseNotice(6000, JText::_('USERS_CLM'));
             }
             if ($clmAccess->accessWithType($usertype, 'BE_general_general') and $gid == 2) {
                 JError::raiseNotice(6000, JText::_('USERS_GO_ADMIN'));
             }
             if (!$clmAccess->accessWithType($usertype, 'BE_general_general') and $gid == 6) {
                 JError::raiseNotice(6000, JText::_('USERS_NO_ADMIN'));
             }
             $msg = JText::_('USERS_BENUTZER_GESPEI');
             $link = 'index.php?option=' . $option . '&section=' . $section;
             break;
     }
     // Log schreiben
     $clmLog = new CLMLog();
     $clmLog->aktion = $aktion;
     $clmLog->params = array('sid' => $row->sid, 'jid' => $row->jid);
     $clmLog->write();
     $mainframe->redirect($link, $msg, "message");
 }
Ejemplo n.º 17
0
 /**
  * process the plugin, called when form is submitted
  *
  * @param object $params
  * @param object form
  */
 function onBeforeStore(&$params, &$formModel)
 {
     $app =& JFactory::getApplication();
     //if the fabrik table is set to be jos_users and the this plugin is used
     //we need to alter the form model to tell it not to store the main row
     // but to still store any joined rows
     $ftable = str_replace('#__', $app->getCfg('dbprefix'), $formModel->getTableModel()->getTable()->db_table_name);
     $jos_users = $app->getCfg('dbprefix') . 'users';
     if ($ftable == $jos_users) {
         $formModel->_storeMainRow = false;
     }
     $usersConfig =& JComponentHelper::getParams('com_users');
     // Initialize some variables
     $me =& JFactory::getUser();
     $acl =& JFactory::getACL();
     $MailFrom = $app->getCfg('mailfrom');
     $FromName = $app->getCfg('fromname');
     $SiteName = $app->getCfg('sitename');
     $siteURL = COM_FABRIK_LIVESITE;
     $bypassActivation = $params->get('juser_bypass_activation', false);
     $bypassRegistration = $params->get('juser_bypass_registration', true);
     $usertype_max = (int) $params->get('juser_usertype_max', 18);
     // load in the com_user language file
     $lang =& JFactory::getLanguage();
     $lang->load('com_user');
     $data =& $formModel->_formData;
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     $option = JRequest::getCmd('option');
     $original_id = 0;
     if ($params->get('juser_field_userid') != '') {
         $this->useridfield = $this->getFieldName($params, 'juser_field_userid');
         if (!empty($formModel->_rowId)) {
             $original_id = (int) $data[$this->useridfield];
         }
     } else {
         $original_id = 0;
         $this->useridfield = '';
     }
     // Create a new JUser object
     $user = new JUser($original_id);
     $original_gid = $user->get('gid');
     // Are we dealing with a new user which we need to create?
     $isNew = $user->get('id') < 1;
     //$post = JRequest::get('post');
     if ($isNew && $usersConfig->get('allowUserRegistration') == '0' && !$bypassRegistration) {
         JError::raiseError(403, JText::_('Access Forbidden - Registration not enabled'));
         return false;
     }
     //new
     $post = array();
     $this->passwordfield = $this->getFieldName($params, 'juser_field_password');
     $this->passwordvalue = $this->getFieldValue($params, 'juser_field_password', $data);
     $this->namefield = $this->getFieldName($params, 'juser_field_name');
     $this->namevalue = $this->getFieldValue($params, 'juser_field_name', $data);
     $this->usernamefield = $this->getFieldName($params, 'juser_field_username');
     $this->usernamevalue = $this->getFieldValue($params, 'juser_field_username', $data);
     $this->emailfield = $this->getFieldName($params, 'juser_field_email');
     $this->emailvalue = $this->getFieldValue($params, 'juser_field_email', $data);
     $post['id'] = $original_id;
     if (!$isNew) {
         // for now, don't allow changing f GIDthru JUser plugin!
         // $post['gid'] = $original_gid;
         // $$$ hugh - let's allow gid to be changed as long as it doesn't
         // exceed the currently logged on user's level
         // yes, i know this duplicates codce from below, for now I'm just noodling around
         if ($params->get('juser_field_usertype') != '') {
             $this->gidfield = $this->getFieldName($params, 'juser_field_usertype');
             $post['gid'] = JArrayHelper::getValue($data, $this->gidfield, 18);
             if (is_array($post['gid'])) {
                 $post['gid'] = $post['gid'][0];
             }
             $post['gid'] = (int) $post['gid'];
             if ($post['gid'] > $me->get('gid')) {
                 $post['gid'] = $me->get('gid');
             }
         } else {
             // if editing an existing user and no gid field being used,
             // use existing gid.
             $post['gid'] = $original_gid;
         }
     } else {
         if ($params->get('juser_field_usertype') != '') {
             $this->gidfield = $this->getFieldName($params, 'juser_field_usertype');
             $post['gid'] = JArrayHelper::getValue($data, $this->gidfield, 18);
             if (is_array($post['gid'])) {
                 $post['gid'] = $post['gid'][0];
             }
         } else {
             $post['gid'] = 18;
         }
     }
     $post['gid'] = (int) $post['gid'];
     if ($post['gid'] === 0) {
         $post['gid'] = 18;
     }
     // $$$ hugh - added 'usertype_max' param, as a safety net to prevent GID's being
     // set to arbitrarily high values thru spoofing.
     if ($post['gid'] > $usertype_max && $post['gid'] != $original_gid) {
         //$post['gid'] = $usertype_max;
         $msg = JText::_('Attempting to set usertype above allowed level!');
         $app->enqueueMessage($msg, 'message');
         return false;
     }
     if ($params->get('juser_field_block') != '') {
         $this->blockfield = $this->getFieldName($params, 'juser_field_block');
         $blocked = JArrayHelper::getValue($data, $this->blockfield, '');
         if (is_array($blocked)) {
             // probably a dropdown
             $post['block'] = (int) $blocked[0];
         } else {
             $post['block'] = (int) $blocked;
         }
     } else {
         $post['block'] = 0;
     }
     //$$$tom get password field to use in $origdata object if editing user and not changing password
     $origdata =& $formModel->_origData;
     $pwfield = $this->passwordfield;
     $post['username'] = $this->usernamevalue;
     $post['password'] = $this->passwordvalue;
     $post['password2'] = $this->passwordvalue;
     $post['name'] = $this->namevalue;
     $name = $this->namevalue;
     $post['email'] = $this->emailvalue;
     $ok = $this->check($post, $formModel, $params);
     if (!$ok) {
         // @TODO - add some error reporting
         return false;
     }
     // Set the registration timestamp
     if ($isNew) {
         $now =& JFactory::getDate();
         $user->set('registerDate', $now->toMySQL());
     }
     // Check that username is not greater than 25 characters
     $username = $post['username'];
     if (strlen($username) > 150) {
         $username = substr($username, 0, 150);
         $user->set('username', $username);
     }
     // Check that password is not greater than 100 characters
     if (strlen($post['password']) > 100) {
         $post['password'] = substr($post['password'], 0, 100);
     }
     //$$$tom Is password field empty on edit?
     if (!$isNew && strlen($password) == 0) {
         $keepPassword = true;
     }
     // end new
     if (!$user->bind($post)) {
         $app->enqueueMessage(JText::_('CANNOT SAVE THE USER INFORMATION'), 'message');
         $app->enqueueMessage($user->getError(), 'error');
         return false;
     }
     // $$$ rob 23/05/2011 moved after bind as we want to ensure block is set to the right level based on the plugin and J's options
     if ($isNew) {
         // If user activation is turned on, we need to set the activation information
         $useractivation = $usersConfig->get('useractivation');
         if ($useractivation == '1' && !$bypassActivation) {
             jimport('joomla.user.helper');
             $user->set('activation', md5(JUserHelper::genRandomPassword()));
             $user->set('block', '1');
         }
     }
     // $$$ rob 20/052011 if a new user then they won't have an acl group assigned
     if ($isNew) {
         $this_group = '';
     } else {
         $objectID = $acl->get_object_id('users', $user->get('id'), 'ARO');
         $groups = $acl->get_object_groups($objectID, 'ARO');
         $this_group = strtolower($acl->get_group_name($groups[0], 'ARO'));
     }
     if (!$isNew) {
         if ($user->get('id') == $me->get('id') && $user->get('block') == 1) {
             $msg = JText::_('You cannot block Yourself!');
             $app->enqueueMessage($msg, 'message');
             return false;
         } else {
             if ($this_group == 'super administrator' && $user->get('block') == 1) {
                 $msg = JText::_('You cannot block a Super Administrator');
                 $app->enqueueMessage($msg, 'message');
                 return false;
             } else {
                 if ($this_group == 'administrator' && $me->get('gid') == 24 && $user->get('block') == 1) {
                     $msg = JText::_('WARNBLOCK');
                     $app->enqueueMessage($msg, 'message');
                     return false;
                 } else {
                     if ($this_group == 'super administrator' && $me->get('gid') != 25) {
                         $msg = JText::_('You cannot edit a super administrator account');
                         $app->enqueueMessage($msg, 'message');
                         return false;
                     }
                 }
             }
         }
         //$$$tom Keep original password
         if ($keepPassword) {
             //$user->set('password', $origdata->$pwfield);
         }
         // if group has been changed and where original group was a Super Admin
         if ($user->get('gid') != $original_gid && $original_gid == 25) {
             $db =& JFactory::getDBO();
             // count number of active super admins
             $query = 'SELECT COUNT( id )' . ' FROM #__users' . ' WHERE gid = 25' . ' AND block = 0';
             $db->setQuery($query);
             $count = $db->loadResult();
             if ($count <= 1) {
                 // disallow change if only one Super Admin exists
                 $this->setRedirect('index.php?option=com_users', JText::_('WARN_ONLY_SUPER'));
                 return false;
             }
         }
     }
     /*
      * Lets save the JUser object
      */
     if (!$user->save()) {
         $app->enqueueMessage(JText::_('CANNOT SAVE THE USER INFORMATION'), 'message');
         $app->enqueueMessage($user->getError(), 'error');
         return false;
     }
     $session =& JFactory::getSession();
     JRequest::setVar('newuserid', $user->id);
     JRequest::setVar('newuserid', $user->id, 'cookie');
     $session->set('newuserid', $user->id);
     JRequest::setVar('newuserid_element', $this->useridfield);
     JRequest::setVar('newuserid_element', $this->useridfield, 'cookie');
     $session->set('newuserid_element', $this->useridfield);
     /*
      * Time for the email magic so get ready to sprinkle the magic dust...
      */
     if ($isNew) {
         $adminEmail = $me->get('email');
         $adminName = $me->get('name');
         $subject = sprintf(JText::_('PLG_FABRIK_FORM_JUSER_ACCOUNT_DETAILS_FOR'), $name, $SiteName);
         $subject = html_entity_decode($subject, ENT_QUOTES);
         if ($useractivation == 1 && !$bypassActivation) {
             $message = sprintf(JText::_('PLG_FABRIK_FORM_JUSER_SEND_MSG_ACTIVATE'), $name, $SiteName, $siteURL . "index.php?option=com_user&task=activate&activation=" . $user->get('activation'), $siteURL, $username, $user->password_clear);
         } else {
             if ($params->get('juser_bypass_accountdetails', 0) != 1) {
                 //$$$tom adding Bypass Joomla's "Account details for..." email
                 $message = sprintf(JText::_('PLG_FABRIK_FORM_JUSER_SEND_MSG'), $name, $SiteName, $siteURL);
             }
         }
         $message = html_entity_decode($message, ENT_QUOTES);
         if ($MailFrom != '' && $FromName != '') {
             $adminName = $FromName;
             $adminEmail = $MailFrom;
         }
         if ($message) {
             //$$$tom see comment above about bypassing Joomla's email
             JUtility::sendMail($adminEmail, $adminName, $user->get('email'), $subject, $message);
         }
     }
     // If updating self, load the new user object into the session
     if ($user->get('id') == $me->get('id')) {
         // Get an ACL object
         $acl =& JFactory::getACL();
         // Get the user group from the ACL
         $grp = $acl->getAroGroup($user->get('id'));
         // Mark the user as logged in
         $user->set('guest', 0);
         $user->set('aid', 1);
         // Fudge Authors, Editors, Publishers and Super Administrators into the special access group
         if ($acl->is_group_child_of($grp->name, 'Registered') || $acl->is_group_child_of($grp->name, 'Public Backend')) {
             $user->set('aid', 2);
         }
         // Set the usertype based on the ACL group name
         $user->set('usertype', $grp->name);
         $session->set('user', $user);
     }
     if (!empty($this->useridfield)) {
         $data[$this->useridfield] = $user->id;
         $data[$this->useridfield . '_raw'] = $user->id;
     }
     if ($ftable == $jos_users) {
         $formModel->_rowId = $user->get('id');
     }
 }
Ejemplo n.º 18
0
 /**
  * Override store function to perform specific saving
  * @see OSModel::store()
  */
 function store()
 {
     jimport('joomla.user.helper');
     $db = JFactory::getDbo();
     $params = JComponentHelper::getParams('com_users');
     $newUserType = $params->get('new_usertype', 2);
     $subscribers = $this->_getSubscriberCSV();
     $data = array();
     $data['groups'] = array();
     $data['groups'][] = $newUserType;
     $data['block'] = 0;
     $rowFieldValue = JTable::getInstance('OsMembership', 'FieldValue');
     $query = "SELECT id,name FROM #__osmembership_fields WHERE is_core = 0";
     $db->setQuery($query);
     $customFields = $db->loadObjectList();
     $imported = 0;
     JPluginHelper::importPlugin('osmembership');
     $dispatcher = JDispatcher::getInstance();
     if (count($subscribers)) {
         foreach ($subscribers as $subscriber) {
             $userId = 0;
             //check username exit in table users
             if ($subscriber['username']) {
                 $sql = 'SELECT id FROM #__users WHERE username="******"';
                 $db->setQuery($sql);
                 $userId = (int) $db->loadResult();
                 if (!$userId) {
                     $data['name'] = $subscriber['first_name'] . ' ' . $subscriber['last_name'];
                     if ($subscriber['password']) {
                         $data['password'] = $data['password2'] = $subscriber['password'];
                     } else {
                         $data['password'] = $data['password2'] = JUserHelper::genRandomPassword();
                     }
                     $data['email'] = $data['email1'] = $data['email2'] = $subscriber['email'];
                     $data['username'] = $subscriber['username'];
                     if ($data['username'] && $data['name'] && $data['email1']) {
                         $user = new JUser();
                         $user->bind($data);
                         $user->save();
                         $userId = $user->id;
                     }
                 }
             }
             //get plan Id
             $planTitle = JString::strtolower($subscriber['plan']);
             $query = "SELECT id FROM #__osmembership_plans WHERE LOWER(title) = '{$planTitle}'";
             $db->setQuery($query);
             $planId = (int) $db->loadResult();
             $subscriber['plan_id'] = $planId;
             $subscriber['user_id'] = $userId;
             //save subscribers core
             $row = $this->getTable('OsMembership', 'Subscriber');
             $row->bind($subscriber);
             if (!$row->payment_date) {
                 $row->payment_date = $row->from_date;
             }
             $row->created_date = $row->from_date;
             $sql = "SELECT id FROM #__osmembership_subscribers WHERE is_profile=1 AND ((user_id={$userId} AND user_id>0) OR email='{$row->email}')";
             $db->setQuery($sql);
             $profileId = $db->loadResult();
             if ($profileId) {
                 $row->is_profile = 0;
                 $row->profile_id = $profileId;
             } else {
                 $row->is_profile = 1;
             }
             $row->store();
             if (!$row->profile_id) {
                 $row->profile_id = $row->id;
                 $row->store();
             }
             //get Extra Field
             if (count($customFields)) {
                 foreach ($customFields as $customField) {
                     if (isset($subscriber[$customField->name]) && $subscriber[$customField->name]) {
                         $rowFieldValue->id = 0;
                         $rowFieldValue->field_id = $customField->id;
                         $rowFieldValue->subscriber_id = $row->id;
                         $rowFieldValue->field_value = $subscriber[$customField->name];
                         $rowFieldValue->store();
                     }
                 }
             }
             if ($row->published == 1) {
                 $dispatcher->trigger('onMembershipActive', array($row));
             }
             $imported++;
         }
     }
     return $imported;
 }
Ejemplo n.º 19
0
 /**
  * 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;
 }
Ejemplo n.º 20
0
 public function userJoomlaSave()
 {
     $post = $this->data;
     $params = $this->getUserParams();
     if ($post["u_name"] == "") {
         $post["u_name"] = $post['email'];
         $this->user->u_name = $post["u_name"];
     }
     if ($post["password"] == "") {
         $post["password"] = substr(md5('up' . time()), 0, 8);
     }
     $user = new JUser();
     $data = array();
     $data['groups'][] = $params->get('new_usertype', 2);
     $data['email'] = $post['email'];
     $data['password'] = $post['password'];
     $data['password2'] = $post['password2'];
     $data['name'] = $post['f_name'] . ' ' . $post['l_name'];
     $data['username'] = $post["u_name"];
     $useractivation = $params->get('useractivation');
     if ($this->admin_registration) {
         $data['block'] = $post['block'];
     } else {
         if ($useractivation == 1 || $useractivation == 2) {
             jimport('joomla.user.helper');
             $data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword());
             $data['block'] = 1;
         }
     }
     $this->userjoomla_data = $data;
     extract(js_add_trigger(get_defined_vars(), "beforeBind"));
     $user->bind($data);
     if (!$user->save()) {
         $this->user_joomla_id = 0;
         $this->savePostData();
         saveToLog('error.log', 'Error registration-' . $user->getError());
         $this->setError($user->getError());
         return 0;
     } else {
         $this->user_joomla = $user;
         $this->user_joomla_id = $user->id;
         return $user->id;
     }
 }
Ejemplo n.º 21
0
 /**
  * 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;
 }
Ejemplo n.º 22
0
 function accountsave()
 {
     checkUserLogin();
     $user = JFactory::getUser();
     $db = JFactory::getDBO();
     $app = JFactory::getApplication();
     JPluginHelper::importPlugin('jshoppingcheckout');
     $dispatcher = JDispatcher::getInstance();
     $jshopConfig = JSFactory::getConfig();
     $user_shop = JTable::getInstance('userShop', 'jshop');
     $post = JRequest::get('post');
     if (!isset($post['password'])) {
         $post['password'] = '';
     }
     if (!isset($post['password_2'])) {
         $post['password_2'] = '';
     }
     if ($post['birthday']) {
         $post['birthday'] = getJsDateDB($post['birthday'], $jshopConfig->field_birthday_format);
     }
     if ($post['d_birthday']) {
         $post['d_birthday'] = getJsDateDB($post['d_birthday'], $jshopConfig->field_birthday_format);
     }
     $dispatcher->trigger('onBeforeAccountSave', array(&$post));
     unset($post['user_id']);
     unset($post['usergroup_id']);
     $user_shop->load($user->id);
     $user_shop->bind($post);
     $user_shop->password = $post['password'];
     $user_shop->password2 = $post['password_2'];
     if (!$user_shop->check("editaccount")) {
         JError::raiseWarning('', $user_shop->getError());
         $this->setRedirect(SEFLink("index.php?option=com_jshopping&controller=user&task=editaccount", 0, 1, $jshopConfig->use_ssl));
         return 0;
     }
     unset($user_shop->password);
     unset($user_shop->password2);
     if (!$user_shop->store()) {
         JError::raiseWarning(500, _JSHOP_REGWARN_ERROR_DATABASE);
         $this->setRedirect(SEFLink("index.php?option=com_jshopping&controller=user&task=editaccount", 0, 1, $jshopConfig->use_ssl));
         return 0;
     }
     $user = new JUser($user->id);
     if (!$jshopConfig->not_update_user_joomla) {
         if ($user_shop->email) {
             $user->email = $user_shop->email;
         }
         if ($user_shop->f_name || $user_shop->l_name) {
             $user->name = $user_shop->f_name . ' ' . $user_shop->l_name;
         }
     }
     if ($post['password'] != '') {
         $data = array("password" => $post['password'], "password2" => $post['password']);
         $user->bind($data);
     }
     $user->save();
     $data = array();
     $data['email'] = $user->email;
     $data['name'] = $user->name;
     $app->setUserState('com_users.edit.profile.data', $data);
     setNextUpdatePrices();
     $dispatcher->trigger('onAfterAccountSave', array());
     $this->setRedirect(SEFLink("index.php?option=com_jshopping&controller=user&task=myaccount", 0, 1, $jshopConfig->use_ssl), _JSHOP_ACCOUNT_UPDATE);
 }
Ejemplo n.º 23
0
 /**
  * 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']);
     // 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;
     }
     return $user->id;
 }
Ejemplo n.º 24
0
 /**
  * Method to bind an associative array of data to a user object
  *
  * @param  array    &$array  The associative array to bind to the object
  * @return boolean           True on success
  */
 public function bind(&$array)
 {
     return $this->cmsOwnUser->bind($array);
 }
Ejemplo n.º 25
0
 public function register($temp, $skipActivation = false, $language = 'en-GB')
 {
     $config = JFactory::getConfig();
     $db = $this->getDbo();
     $params = JComponentHelper::getParams('com_users');
     // Initialise the table with JUser.
     $user = new JUser();
     //$data = (array)$this->getData();
     $data['groups'] = array();
     // Get the default new user group, Registered if not specified.
     $system = $params->get('new_usertype', 2);
     $data['groups'][] = $system;
     // Merge in the registration data.
     foreach ($temp as $k => $v) {
         $data[$k] = $v;
     }
     // Prepare the data for the user object.
     $data['email'] = $data['email1'];
     $data['password'] = $data['password1'];
     $data['params'] = array('admin_language' => $language, 'language' => $language);
     //skipActivation set true ONLY from registerSocialUser (mobile.json.php)
     $useractivation = $skipActivation ? 0 : $params->get('useractivation');
     $sendpassword = $params->get('sendpassword', 1);
     // Check if the user needs to activate their account.
     if ($skipActivation == true) {
         $data['block'] = 0;
     } else {
         if ($useractivation == 1 || $useractivation == 2) {
             $data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword());
             $data['block'] = 1;
         }
     }
     // Bind the data.
     if (!$user->bind($data)) {
         $this->setError(JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError()));
         //return false;
         return JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError());
     }
     // Load the users plugin group.
     JPluginHelper::importPlugin('user');
     // Store the data.
     if (!$user->save()) {
         $this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError()));
         return $user->getError();
         //return JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError());
     }
     // Compile the notification mail values.
     $data = $user->getProperties();
     $data['fromname'] = $config->get('fromname');
     $data['mailfrom'] = $config->get('mailfrom');
     $data['sitename'] = $config->get('sitename');
     $data['siteurl'] = JUri::root();
     // Handle account activation/confirmation emails.
     if ($useractivation == 2) {
         // Set the link to confirm the user email.
         $uri = JURI::getInstance();
         $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
         $data['activate'] = $base . JRoute::_('index.php?option=com_users&task=registration.activate&token=' . $data['activation'], false);
         $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
         if ($sendpassword) {
             $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY', $data['name'], $data['sitename'], $data['siteurl'] . 'index.php?option=com_users&task=registration.activate&token=' . $data['activation'], $data['siteurl'], $data['username'], $data['password_clear']);
         } else {
             $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['siteurl'] . 'index.php?option=com_users&task=registration.activate&token=' . $data['activation'], $data['siteurl'], $data['username']);
         }
     } elseif ($useractivation == 1) {
         // Set the link to activate the user account.
         $uri = JURI::getInstance();
         $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
         $data['activate'] = $base . JRoute::_('index.php?option=com_users&task=registration.activate&token=' . $data['activation'], false);
         $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
         if ($sendpassword) {
             $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY', $data['name'], $data['sitename'], $data['siteurl'] . 'index.php?option=com_users&task=registration.activate&token=' . $data['activation'], $data['siteurl'], $data['username'], $data['password_clear']);
         } else {
             $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['siteurl'] . 'index.php?option=com_users&task=registration.activate&token=' . $data['activation'], $data['siteurl'], $data['username']);
         }
     } else {
         $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
         $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY', $data['name'], $data['sitename'], $data['siteurl']);
     }
     // DO NOT Send registration email if called from registerSocial.
     if ($skipActivation == true) {
         return true;
     } else {
         // Send the registration email.
         $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody);
     }
     //Send Notification mail to administrators
     if ($params->get('useractivation') < 2 && $params->get('mail_to_admin') == 1) {
         $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
         $emailBodyAdmin = JText::sprintf('COM_USERS_EMAIL_REGISTERED_NOTIFICATION_TO_ADMIN_BODY', $data['name'], $data['username'], $data['siteurl']);
         // get all admin users
         $query = 'SELECT name, email, sendEmail' . ' FROM #__users' . ' WHERE sendEmail=1';
         $db->setQuery($query);
         $rows = $db->loadObjectList();
         // Send mail to all superadministrators id
         foreach ($rows as $row) {
             $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBodyAdmin);
             // Check for an error.
             if ($return !== true) {
                 $this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
                 //return false;
                 return JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED');
             }
         }
     }
     // Check for an error.
     if ($return !== true) {
         $this->setError(JText::_('COM_USERS_REGISTRATION_SEND_MAIL_FAILED'));
         // Send a system message to administrators receiving system mails
         $db = JFactory::getDBO();
         $q = "SELECT id\n\t\t\tFROM #__users\n\t\t\tWHERE block = 0\n\t\t\tAND sendEmail = 1";
         $db->setQuery($q);
         $sendEmail = $db->loadColumn();
         if (count($sendEmail) > 0) {
             $jdate = new JDate();
             // Build the query to add the messages
             $q = "INSERT INTO " . $db->quoteName('#__messages') . " (" . $db->quoteName('user_id_from') . ", " . $db->quoteName('user_id_to') . ", " . $db->quoteName('date_time') . ", " . $db->quoteName('subject') . ", " . $db->quoteName('message') . ") VALUES ";
             $messages = array();
             foreach ($sendEmail as $userid) {
                 $messages[] = "(" . $userid . ", " . $userid . ", '" . $jdate->toSql() . "', '" . JText::_('COM_USERS_MAIL_SEND_FAILURE_SUBJECT') . "', '" . JText::sprintf('COM_USERS_MAIL_SEND_FAILURE_BODY', $return, $data['username']) . "')";
             }
             $q .= implode(',', $messages);
             $db->setQuery($q);
             $db->query();
         }
         //return false;
         return JText::_('COM_USERS_REGISTRATION_SEND_MAIL_FAILED');
     }
     if ($useractivation == 1) {
         return "useractivate";
     } elseif ($useractivation == 2) {
         return "adminactivate";
     } else {
         return $user->id;
     }
 }
Ejemplo n.º 26
0
 function store(&$error)
 {
     global $mainframe;
     $db = JFactory::getDBO();
     $userParams = JComponentHelper::getParams('com_users');
     // the_user_status will have 3 values:
     // 0 - it's not a registered user and also the username doesn't exists
     // 1 - it's not a registered user but the username exists
     //              - we display a message forcing him to login first to activate the advertiser status
     // 2 - it's a registered user that will activate it's status
     $the_user_status = 0;
     $item_id = JRequest::getInt('Itemid', '0', 'get');
     if ($item_id != 0) {
         $Itemid = "&Itemid=" . $item_id;
     } else {
         $Itemid = NULL;
     }
     $sql = "select `params` from #__ad_agency_settings";
     $db->setQuery($sql);
     $db->query();
     $email_params = $db->loadColumn();
     $email_params = @$email_params["0"];
     $email_params = unserialize($email_params);
     $existing_user = JFactory::getUser();
     if ($existing_user->id > 0) {
         $the_user_status = 2;
     } else {
         JRequest::checkToken() or die('Invalid Token');
     }
     jimport("joomla.database.table.user");
     $user = new JUser();
     $my = new stdClass();
     $data = JRequest::get('post');
     $usersConfig = JComponentHelper::getParams('com_users');
     $query = "SELECT title FROM `#__usergroups` WHERE id=" . intval($usersConfig->get('new_usertype')) . "";
     $db->setQuery($query);
     $usergroupName = $db->loadColumn();
     $usergroupName = $usergroupName["0"];
     if (isset($data['email']) && $data['email'] != NULL) {
         $data['email'] = trim($data['email']);
     }
     // See if there is a wizzard or not
     $sql = "SELECT COUNT(id) FROM `#__ad_agency_settings` WHERE `show` LIKE '%wizzard%'";
     $db->setQuery($sql);
     $is_wizzard = intval($db->loadResult());
     $data['paywith'] = NULL;
     $post_name = $data['name'];
     $item = $this->getTable('adagencyAdvertiser');
     if ($the_user_status == 0) {
         $sql = "SELECT `id` FROM #__users WHERE username='******'username']) . "'";
         $db->setQuery($sql);
         $user_id_byname = $db->loadResult();
         if (isset($user_id_byname) && $user_id_byname > 0) {
             $the_user_status = 1;
         }
     }
     // setting the reports values - start
     $item->email_daily_report = 'N';
     $item->email_weekly_report = 'N';
     $item->email_month_report = 'N';
     $item->email_campaign_expiration = 'N';
     if (isset($data['email_daily_report']) && $data['email_daily_report'] == 'Y') {
         $item->email_daily_report = 'Y';
     }
     if (isset($data['email_weekly_report']) && $data['email_weekly_report'] == 'Y') {
         $item->email_weekly_report = 'Y';
     }
     if (isset($data['email_month_report']) && $data['email_month_report'] == 'Y') {
         $item->email_month_report = 'Y';
     }
     if (isset($data['email_campaign_expiration']) && $data['email_campaign_expiration'] == 'Y') {
         $item->email_campaign_expiration = 'Y';
     }
     // setting the reports values - stop
     $configs = $this->getInstance("adagencyConfig", "adagencyModel");
     $configs = $configs->getConfigs();
     // we determine what case we have - actual SAVE or REDIRECT - start
     $res = true;
     if ($the_user_status == 1) {
         $err_msg = JText::_("VIEWADVERTISER_ERR_MSG");
         $err_msg = str_replace('{username}', mysql_escape_string($data['username']), $err_msg);
         $_SESSION['ad_company'] = $data['company'];
         $_SESSION['ad_description'] = $data['description'];
         $_SESSION['ad_approved'] = $data['approved'];
         $_SESSION['ad_enabled'] = $data['enabled'];
         $_SESSION['ad_username'] = $data['username'];
         $_SESSION['ad_email'] = $data['email'];
         $_SESSION['ad_name'] = $data['name'];
         $_SESSION['ad_website'] = $data['website'];
         $_SESSION['ad_address'] = $data['address'];
         $_SESSION['ad_country'] = $data['country'];
         $_SESSION['ad_state'] = $data['state'];
         $_SESSION['ad_city'] = $data['city'];
         $_SESSION['ad_zip'] = $data['zip'];
         $_SESSION['ad_telephone'] = $data['telephone'];
         $mainframe->redirect('index.php?option=com_adagency&controller=adagencyAdvertisers&task=edit&cid[]=0', $err_msg);
     } elseif ($the_user_status == 0) {
         $query = 'SELECT id FROM #__users WHERE email = "' . addslashes(trim($data['email'])) . '"';
         $db->setQuery($query);
         $exists_email = $db->loadResult($query);
         if ($exists_email != '') {
             $_SESSION['ad_company'] = $data['company'];
             $_SESSION['ad_description'] = $data['description'];
             $_SESSION['ad_approved'] = $data['approved'];
             $_SESSION['ad_enabled'] = $data['enabled'];
             $_SESSION['ad_username'] = $data['username'];
             $_SESSION['ad_email'] = $data['email'];
             $_SESSION['ad_name'] = $data['name'];
             $_SESSION['ad_website'] = $data['website'];
             $_SESSION['ad_address'] = $data['address'];
             $_SESSION['ad_country'] = $data['country'];
             $_SESSION['ad_state'] = $data['state'];
             $_SESSION['ad_city'] = $data['city'];
             $_SESSION['ad_zip'] = $data['zip'];
             $_SESSION['ad_telephone'] = $data['telephone'];
             $mainframe->redirect('index.php?option=com_adagency&controller=adagencyAdvertisers&task=edit&cid[]=0', JText::_('ADAG_EMAILINUSE'));
         }
         if (isset($configs->show) && strpos(" " . $configs->show, 'calculation') > 0) {
             if (!isset($_SESSION['ADAG_CALC']) || $_SESSION['ADAG_CALC'] != $data['calculation']) {
                 $_SESSION['ad_company'] = $data['company'];
                 $_SESSION['ad_description'] = $data['description'];
                 $_SESSION['ad_approved'] = $data['approved'];
                 $_SESSION['ad_enabled'] = $data['enabled'];
                 $_SESSION['ad_username'] = $data['username'];
                 $_SESSION['ad_email'] = $data['email'];
                 $_SESSION['ad_name'] = $data['name'];
                 $_SESSION['ad_website'] = $data['website'];
                 $_SESSION['ad_address'] = $data['address'];
                 $_SESSION['ad_country'] = $data['country'];
                 $_SESSION['ad_state'] = $data['state'];
                 $_SESSION['ad_city'] = $data['city'];
                 $_SESSION['ad_zip'] = $data['zip'];
                 $_SESSION['ad_telephone'] = $data['telephone'];
                 $mainframe->redirect('index.php?option=com_adagency&controller=adagencyAdvertisers&task=edit&cid[]=0', JText::_('JS_CALCULATION'));
             }
         }
         $pwd = $data['password'];
         if (!$data['user_id']) {
             $data['password2'] = $data['password'];
         }
         $sql = "SELECT `id` FROM #__usergroups WHERE `title`='" . $usergroupName . "'";
         $db->setQuery($sql);
         $advgroup = $db->loadResult();
         if (!isset($user->registerDate)) {
             $user->registerDate = date('Y-m-d H:i:s');
         }
         $user->usertype = $usergroupName;
         $user->gid = $advgroup;
         if ($data['user_id'] > 0) {
             $data['id'] = $data['user_id'];
         }
         $query = "SHOW columns FROM #__ad_agency_advertis WHERE field='approved'";
         $db->setQuery($query);
         $autoapprove = $db->loadRow();
         $autoapprove[4] = 'Y';
         if ($userParams->get('useractivation') != 0) {
             $data["block"] = 1;
             $user->block = 1;
             $autoapprove[4] = 'P';
         }
         $data["groups"] = array($advgroup);
         $user->bind($data);
         if (isset($autoapprove[4]) && $autoapprove[4] == 'Y') {
             $user->block = 0;
             $user->activation = '';
             $data['approved'] = 'Y';
         } else {
             $data['approved'] = 'P';
             $useractivation = $usersConfig->get('useractivation');
             if ($useractivation == '1') {
                 jimport('joomla.user.helper');
                 $user->activation = md5(JUserHelper::genRandomPassword());
                 $user->block = 1;
             }
         }
         if ($is_wizzard > 0) {
             $user->block = 0;
             $user->activation = 0;
             $user->params = NULL;
         }
         if ($userParams->get('useractivation') != 0) {
             jimport('joomla.user.helper');
             $user->activation = md5(JUserHelper::genRandomPassword());
             $data["block"] = 1;
             $user->block = 1;
         }
         if (!$user->save()) {
             $error = $user->getError();
             echo $error;
             $res = false;
         } else {
             $name = $user->name;
             $email = $user->email;
             $username = $user->username;
             $mosConfig_live_site = JURI::base();
             $ok_send_email = 1;
             if ($data['approved'] == 'Y') {
                 $subject = $configs->sbafterregaa;
                 $message = $configs->bodyafterregaa;
                 $ok_send_email = $email_params["send_after_reg_auto_app"];
             } else {
                 $subject = $configs->sbactivation;
                 $message = $configs->bodyactivation;
                 $ok_send_email = $email_params["send_after_reg_need_act"];
             }
             $subject = str_replace('{name}', $name, $subject);
             $subject = str_replace('{login}', $username, $subject);
             $subject = str_replace('{email}', $email, $subject);
             $subject = str_replace('{password}', $pwd, $subject);
             $message = str_replace('{name}', $name, $message);
             $message = str_replace('{login}', $username, $message);
             $message = str_replace('{email}', $email, $message);
             $message = str_replace('{password}', $pwd, $message);
             $configs->txtafterreg = str_replace('{name}', $name, $configs->txtafterreg);
             $configs->txtafterreg = str_replace('{login}', $username, $configs->txtafterreg);
             $configs->txtafterreg = str_replace('{password}', $pwd, $configs->txtafterreg);
             $message = str_replace('{activate_url}', '<a href="' . $mosConfig_live_site . 'index.php?option=com_users&task=registration.activate&token=' . $user->activation . '" target="_blank">' . $mosConfig_live_site . 'index.php?option=com_users&task=registration.activate&token=' . $user->activation . '</a>', $message);
             $message = html_entity_decode($message, ENT_QUOTES);
             if ($ok_send_email == 1) {
                 JFactory::getMailer()->sendMail($configs->fromemail, $configs->fromname, $email, $subject, $message, 1);
             }
         }
         $ask = "SELECT `id` FROM `#__users` ORDER BY `id` DESC LIMIT 1 ";
         $db->setQuery($ask);
         $where = $db->loadResult();
         $user->id = $where;
         if (!$data['user_id']) {
             $data['user_id'] = $user->id;
         }
         $sql = "SHOW tables";
         $db->setQuery($sql);
         $res_tables = $db->loadColumn();
         $jconfigs = JFactory::getConfig();
         $params = new JForm($jconfigs);
         $params2 = $params->getName("name");
         $params2 = (array) $params2;
         $params2 = array_pop($params2);
         $dbprefix = $params2->dbprefix;
         if (in_array($dbprefix . "comprofiler", $res_tables) && $data['user_id']) {
             $sql = "INSERT INTO `#__comprofiler` (`id`, `user_id`) VALUES ('" . intval($data['user_id']) . "', '" . intval($data['user_id']) . "');";
             $db->setQuery($sql);
             $db->query();
         }
         $data['key'] = md5(rand(1000, 9999));
         $sql = "SELECT params FROM `#__ad_agency_settings` LIMIT 1";
         $db->setQuery($sql);
         $cpr = @unserialize($db->loadResult());
         if (!isset($cpr['timeformat'])) {
             $data['fax'] = 10;
         } else {
             $data['fax'] = intval($cpr['timeformat']);
         }
         if (!$item->bind($data)) {
             $res = false;
         }
         if (!$item->check()) {
             $res = false;
         }
         if (!$item->store()) {
             $res = false;
         }
         // Send notification to administrator below
         //if(!isset($user->block)||($user->block==0)){
         if (isset($data['approved']) && $data['approved'] == 'Y') {
             $approval_msg = JText::_('NEWADAPPROVED');
         } else {
             $approval_msg = JText::_('ADAG_PENDING');
         }
         if (!isset($data['address']) || $data['address'] == '') {
             $data['address'] = "N/A";
         }
         if (!isset($data['state']) || $data['state'] == '') {
             $data['state'] = "N/A";
         }
         if (!isset($data['website']) || $data['website'] == '') {
             $data['website'] = "N/A";
         }
         if (!isset($data['company']) || $data['company'] == '') {
             $data['company'] = "N/A";
         }
         if (!isset($data['country']) || $data['country'] == '') {
             $data['country'] = "N/A";
         }
         if (!isset($data['description']) || $data['description'] == '') {
             $data['description'] = "N/A";
         }
         if (!isset($data['telephone']) || $data['telephone'] == '') {
             $data['telephone'] = "N/A";
         }
         if (!isset($data['zip']) || $data['zip'] == '') {
             $data['zip'] = "N/A";
         }
         $eapprove = "<a href='" . JURI::root() . "index.php?option=com_adagency&controller=adagencyAdvertisers&task=manage&action=approve&key=" . $data['key'] . "&cid=" . $data['user_id'] . "' target='_blank'>" . JURI::root() . "index.php?option=com_adagency&controller=adagencyAdvertisers&task=manage&action=approve&key=" . $data['key'] . "&cid=" . $data['user_id'] . "</a>";
         $edecline = "<a href='" . JURI::root() . "index.php?option=com_adagency&controller=adagencyAdvertisers&task=manage&action=decline&key=" . $data['key'] . "&cid=" . $data['user_id'] . "' target='_blank'>" . JURI::root() . "index.php?option=com_adagency&controller=adagencyAdvertisers&task=manage&action=decline&key=" . $data['key'] . "&cid=" . $data['user_id'] . "</a>";
         $message2 = str_replace('{name}', $name, $configs->bodynewuser);
         $message2 = str_replace('{email}', $email, $message2);
         $message2 = str_replace('{approval_status}', $approval_msg, $message2);
         $message2 = str_replace('{street}', $data['address'], $message2);
         $message2 = str_replace('{state}', $data['state'], $message2);
         $message2 = str_replace('{company}', $data['company'], $message2);
         $message2 = str_replace('{zipcode}', $data['zip'], $message2);
         $message2 = str_replace('{country}', $data['country'], $message2);
         $message2 = str_replace('{description}', $data['description'], $message2);
         $message2 = str_replace('{url}', $data['website'], $message2);
         $message2 = str_replace('{username}', $username, $message2);
         $message2 = str_replace('{phone}', $data['telephone'], $message2);
         $message2 = str_replace('{approve_advertiser_url}', $eapprove, $message2);
         $message2 = str_replace('{decline_advertiser_url}', $edecline, $message2);
         $subject2 = str_replace('{name}', $name, $configs->sbnewuser);
         $subject2 = str_replace('{email}', $email, $subject2);
         $subject2 = str_replace('{description}', $data['description'], $subject2);
         $subject2 = str_replace('{company}', $data['company'], $subject2);
         $subject2 = str_replace('{url}', $data['website'], $subject2);
         $subject2 = str_replace('{street}', $data['address'], $subject2);
         $subject2 = str_replace('{state}', $data['state'], $subject2);
         $subject2 = str_replace('{zipcode}', $data['zip'], $subject2);
         $subject2 = str_replace('{country}', $data['country'], $subject2);
         $subject2 = str_replace('{username}', $username, $subject2);
         $subject2 = str_replace('{approval_status}', $approval_msg, $subject2);
         $subject2 = str_replace('{phone}', $data['telephone'], $subject2);
         $subject2 = str_replace('{approve_advertiser_url}', $eapprove, $subject2);
         $subject2 = str_replace('{decline_advertiser_url}', $edecline, $subject2);
         $subject2 = html_entity_decode($subject2, ENT_QUOTES);
         $message2 = html_entity_decode($message2, ENT_QUOTES);
         if ($email_params["send_advertiser_reg"] == 1) {
             JFactory::getMailer()->sendMail($configs->fromemail, $configs->fromname, $configs->adminemail, $subject2, $message2, 1);
         }
         if (stripslashes($_GET['task']) != 'edit') {
             $advertiser_id = mysql_insert_id();
             if ($advertiser_id == 0) {
                 $ask = "SELECT aid FROM #__ad_agency_advertis ORDER BY aid DESC LIMIT 1 ";
                 $db->setQuery($ask);
                 $advertiser_id = $db->loadResult();
             }
             $query = "SELECT `lastreport` FROM #__ad_agency_advertis WHERE `aid`=" . intval($advertiser_id);
             $db->setQuery($query);
             $lastreport = $db->loadResult();
             $secs = time();
             if (!empty($lastreport)) {
                 $querry = "UPDATE #__ad_agency_advertis SET `lastreport` = " . intval($secs) . " WHERE `aid`=" . intval($advertiser_id);
                 $db->setQuery($querry);
                 $db->query() or die($db->stderr());
             }
         }
     } elseif ($the_user_status == 2) {
         if (isset($data['newpswd']) && $data['newpswd'] != "") {
             $sql = "UPDATE `#__users` SET `password` = '" . md5($data['newpswd']) . "' WHERE `id` =" . intval($existing_user->id) . " LIMIT 1";
             $db->setQuery($sql);
             $db->query();
         }
         $data['user_id'] = $existing_user->id;
         $new_name = stripslashes($post_name);
         $querry = "UPDATE #__users SET `name` = '" . addslashes(trim($new_name)) . "' WHERE `id`=" . intval($existing_user->id);
         $db->setQuery($querry);
         $db->query();
         if (!$data['user_id']) {
             $data['user_id'] = $existing_user->id;
         }
         $query = "SHOW columns FROM #__ad_agency_advertis WHERE field='approved'";
         $db->setQuery($query);
         $autoapprove = $db->loadRow();
         $sql = "SELECT aid FROM #__ad_agency_advertis WHERE user_id='" . intval($existing_user->id) . "' LIMIT 1;";
         $db->setQuery($sql);
         $aiduser = $db->loadColumn();
         $aiduser = $aiduser["0"];
         $data["aid"] = intval($aiduser);
         if (!$aiduser) {
             $data['key'] = md5(rand(1000, 9999));
         }
         if (!$item->bind($data)) {
             $res = false;
         }
         if (!$item->check()) {
             $res = false;
         }
         if (!$item->store()) {
             $res = false;
         }
         if (!$aiduser) {
             $sql = "SELECT * FROM #__users WHERE id = " . intval($item->user_id);
             $db->setQuery($sql);
             $theUser = $db->loadObject();
             $name = $theUser->name;
             $email = $theUser->email;
             $username = $theUser->username;
             // Send notification to administrator below
             //if(!isset($user->block)||($user->block==0)){
             if ($autoapprove[4] == 'Y') {
                 $approval_msg = JText::_('NEWADAPPROVED');
             } else {
                 $approval_msg = JText::_('ADAG_PENDING');
             }
             if (!isset($data['address']) || $data['address'] == '') {
                 $data['address'] = "N/A";
             }
             if (!isset($data['state']) || $data['state'] == '') {
                 $data['state'] = "N/A";
             }
             if (!isset($data['website']) || $data['website'] == '') {
                 $data['website'] = "N/A";
             }
             if (!isset($data['company']) || $data['company'] == '') {
                 $data['company'] = "N/A";
             }
             if (!isset($data['country']) || $data['country'] == '') {
                 $data['country'] = "N/A";
             }
             if (!isset($data['description']) || $data['description'] == '') {
                 $data['description'] = "N/A";
             }
             if (!isset($data['telephone']) || $data['telephone'] == '') {
                 $data['telephone'] = "N/A";
             }
             if (!isset($data['zip']) || $data['zip'] == '') {
                 $data['zip'] = "N/A";
             }
             $eapprove = "<a href='" . JURI::root() . "index.php?option=com_adagency&controller=adagencyAdvertisers&task=manage&action=approve&key=" . $data['key'] . "&cid=" . $data['user_id'] . "' target='_blank'>" . JURI::root() . "index.php?option=com_adagency&controller=adagencyAdvertisers&task=manage&action=approve&key=" . $data['key'] . "&cid=" . $data['user_id'] . "</a>";
             $edecline = "<a href='" . JURI::root() . "index.php?option=com_adagency&controller=adagencyAdvertisers&task=manage&action=decline&key=" . $data['key'] . "&cid=" . $data['user_id'] . "' target='_blank'>" . JURI::root() . "index.php?option=com_adagency&controller=adagencyAdvertisers&task=manage&action=decline&key=" . $data['key'] . "&cid=" . $data['user_id'] . "</a>";
             $message2 = str_replace('{name}', $name, $configs->bodynewuser);
             $message2 = str_replace('{email}', $email, $message2);
             $message2 = str_replace('{approval_status}', $approval_msg, $message2);
             $message2 = str_replace('{street}', $data['address'], $message2);
             $message2 = str_replace('{state}', $data['state'], $message2);
             $message2 = str_replace('{company}', $data['company'], $message2);
             $message2 = str_replace('{zipcode}', $data['zip'], $message2);
             $message2 = str_replace('{country}', $data['country'], $message2);
             $message2 = str_replace('{description}', $data['description'], $message2);
             $message2 = str_replace('{url}', $data['website'], $message2);
             $message2 = str_replace('{username}', $username, $message2);
             $message2 = str_replace('{phone}', $data['telephone'], $message2);
             $message2 = str_replace('{approve_advertiser_url}', $eapprove, $message2);
             $message2 = str_replace('{decline_advertiser_url}', $edecline, $message2);
             $subject2 = str_replace('{name}', $name, $configs->sbnewuser);
             $subject2 = str_replace('{email}', $email, $subject2);
             $subject2 = str_replace('{description}', $data['description'], $subject2);
             $subject2 = str_replace('{company}', $data['company'], $subject2);
             $subject2 = str_replace('{url}', $data['website'], $subject2);
             $subject2 = str_replace('{street}', $data['address'], $subject2);
             $subject2 = str_replace('{state}', $data['state'], $subject2);
             $subject2 = str_replace('{zipcode}', $data['zip'], $subject2);
             $subject2 = str_replace('{country}', $data['country'], $subject2);
             $subject2 = str_replace('{username}', $username, $subject2);
             $subject2 = str_replace('{approval_status}', $approval_msg, $subject2);
             $subject2 = str_replace('{phone}', $data['telephone'], $subject2);
             $subject2 = str_replace('{approve_advertiser_url}', $eapprove, $subject2);
             $subject2 = str_replace('{decline_advertiser_url}', $edecline, $subject2);
             $subject2 = html_entity_decode($subject2, ENT_QUOTES);
             $message2 = html_entity_decode($message2, ENT_QUOTES);
             if ($email_params["send_advertiser_reg"] == 1) {
                 JFactory::getMailer()->sendMail($configs->fromemail, $configs->fromname, $configs->adminemail, $subject2, $message2, 1);
             }
         }
         if ((!isset($aiduser) || $aiduser < 1) && $autoapprove[4] == 'Y') {
             $mainframe->redirect("index.php?option=com_adagency&controller=adagencyAds&task=addbanners" . $Itemid, JText::_('ADVSAVED2'));
         }
     }
     // we determine what case we have - actual SAVE or REDIRECT - stop
     /*if($userParams->get('useractivation') != 2){
     			if(($the_user_status == 0)&&($autoapprove[4]=='Y')){
     				if(isset($user->id)&&(intval($user->id)>0)) {
     					$this->autoLogin($user->id);
     					$mainframe->redirect("index.php?option=com_adagency&controller=adagencyAds&task=addbanners".$Itemid,JText::_('ADVSAVED2'));
     				}
     			} elseif(($the_user_status == 0)&&($autoapprove[4]!='Y')&&($is_wizzard > 0)){
     				if(isset($user->id)&&(intval($user->id)>0)) {
     					$this->autoLogin($user->id);
     					$mainframe->redirect("index.php?option=com_adagency&controller=adagencyAds&task=addbanners".$Itemid);//,JText::_('ADAG_PENDING_ADS2')
     
     				}
     			}
     		}*/
     if ($userParams->get('useractivation') != 0) {
         $user->password1 = $data["password2"];
         $this->sendJoomlaEmail($user);
         $item_id = JRequest::getInt('Itemid', '0');
         if ($item_id != 0) {
             $Itemid = "&Itemid=" . intval($item_id);
         } else {
             $Itemid = NULL;
         }
         $link = JRoute::_("index.php?option=com_adagency" . $Itemid, false);
         $mainframe->redirect($link, JText::_("ADAG_ADVERTISER_SAVED_PENDING"), "notice");
         return true;
     }
     return $res;
 }
Ejemplo n.º 27
0
 public function createUser($extuser)
 {
     if ($extuser->id) {
         return 0;
     }
     $data = get_object_vars($extuser);
     if (empty($data['password2'])) {
         unset($data['password']);
     }
     $user = new JUser();
     if (!$user->bind($data)) {
         die('Error binding user');
     }
     $this->setUserGroup($user, $extuser->usertype);
     if (!$user->save()) {
         return $user->getError();
     }
     $data['id'] = $user->id;
     if (!$extuser->save($data)) {
         die('Error saving extuser');
     }
     return $user->id;
 }
Ejemplo n.º 28
0
 /**
  * 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'] = $data['email1'];
     $data['password'] = $data['password1'];
     // Unset the username so it does not get overwritten
     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']);
     // Bind the data.
     if (!$user->bind($data)) {
         $this->setError(JText::sprintf('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;
     }
     return $user->id;
 }
Ejemplo n.º 29
0
 /**
  * Test...
  *
  * @covers JUser::bind
  *
  * @return void
  */
 public function testBind()
 {
     $array = array();
     $string = '12345678901234567890123456789012345678901234567890123456789012345678901234567890' . '12345678901234567890123456789012345678901234567890123456789012345678901234567890' . '1234567890123456789012345678901234567890';
     $array['username'] = $string;
     $array['password'] = $string;
     $array['password2'] = $string;
     $testUser = new JUser();
     $result = $testUser->bind($array);
     $this->assertTrue($result);
     $this->assertTrue(strlen($testUser->password) >= 1 && strlen($testUser->password) <= 100);
     $array['password2'] = 'password_ok_not_same';
     $testUser = new JUser();
     $result = $testUser->bind($array);
     $this->assertFalse($result);
 }
Ejemplo n.º 30
-2
 public function createNewUser($params)
 {
     $user = new JUser(0);
     JLoader::import('joomla.application.component.helper');
     $usersConfig = JComponentHelper::getParams('com_users');
     $newUsertype = $usersConfig->get('new_usertype');
     // get the New User Group from com_users' settings
     if (empty($newUsertype)) {
         $newUsertype = 2;
     }
     $params['groups'] = array($newUsertype);
     $params['sendEmail'] = 0;
     // Set the user's default language to whatever the site's current language is
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $params['params'] = array('language' => JFactory::getConfig()->get('language'));
     } else {
         $params['params'] = array('language' => JFactory::getConfig()->getValue('config.language'));
     }
     JLoader::import('joomla.user.helper');
     $params['block'] = 0;
     $randomString = JUserHelper::genRandomPassword();
     if (version_compare(JVERSION, '3.2', 'ge')) {
         $hash = JApplication::getHash($randomString);
     } else {
         $hash = JFactory::getApplication()->getHash($randomString);
     }
     $params['activation'] = $hash;
     $user->bind($params);
     $userIsSaved = $user->save();
     if ($userIsSaved) {
         return $user->id;
     } else {
         return false;
     }
 }