Example #1
0
	public function load($id = null)
	{
		JTable::addIncludePath( JPATH_ROOT . '/libraries/joomla/database/table' );

		$result = parent::load($id);
		return $result;
	}
Example #2
0
 function &getUserObject($user, $options = array())
 {
     JLoader::import('joomla.user.helper');
     $instance = new JUser();
     if ($id = intval(JUserHelper::getUserId($user['username']))) {
         $instance->load($id);
         return $instance;
     }
     JLoader::import('joomla.application.component.helper');
     $config = JComponentHelper::getParams('com_users');
     $defaultUserGroup = $config->get('new_usertype', 2);
     $acl = JFactory::getACL();
     $instance->set('id', 0);
     $instance->set('name', $user['fullname']);
     $instance->set('username', $user['username']);
     $instance->set('password_clear', $user['password_clear']);
     $instance->set('email', $user['email']);
     // Result should contain an email (check)
     $instance->set('usertype', 'deprecated');
     $instance->set('groups', array($defaultUserGroup));
     return $instance;
 }
Example #3
0
 function activateUser($user_id)
 {
     /*		global $mainframe;
     		$mainframe->logout();*/
     $new_user = new JUser();
     $new_user->load($user_id);
     $acl =& JFactory::getACL();
     $grp = $acl->getAroGroup($user_id);
     $new_user->set('guest', 0);
     $new_user->set('aid', 1);
     if ($acl->is_group_child_of($grp->name, 'Registered') || $acl->is_group_child_of($grp->name, 'Public Backend')) {
         $new_user->set('aid', 2);
     }
     $new_user->set('usertype', $grp->name);
     $session =& JFactory::getSession();
     $session->set('user', $new_user);
     $table =& JTable::getInstance('session');
     $table->load($session->getId());
     $table->guest = $new_user->get('guest');
     $table->username = $new_user->get('username');
     $table->userid = intval($new_user->get('id'));
     $table->usertype = $new_user->get('usertype');
     $table->gid = intval($new_user->get('gid'));
     $table->update();
     $new_user->setLastVisit();
 }
 /**
  * Event onUserAfterSave
  * 
  * @access public
  * @param array $user
  * @param bool $isnew
  * @param bool $success
  * @param string $msg
  * @return bool
  */
 public function onUserAfterSave($user, $isnew, $success, $msg)
 {
     // Check if we can run this event or not
     if (MageBridgePluginHelper::allowEvent('onUserAfterSave') == false) {
         return;
     }
     // Get system variables
     $application = JFactory::getApplication();
     // Copy the username to the email address (if this is configured)
     if ($application->isSite() == true && $this->getParam('username_from_email') == 1 && $user['username'] != $user['email']) {
         MageBridgeModelDebug::getInstance()->notice("onUserAfterSave::bind on user " . $user['username']);
         // Load the right JUser object
         $data = array('username' => $user['email']);
         $object = new JUser();
         $object->load($user['id']);
         // Check whether user-syncing is allowed for this user
         if ($this->getUser()->allowSynchronization($object, 'save') == true) {
             // Change the record in the database
             $object->bind($data);
             $object->save();
             // Bind this new user-object into the session
             $session = JFactory::getSession();
             $session_user = $session->get('user');
             if ($session_user->id == $user['id']) {
                 $session_user->username = $user['email'];
             }
         }
     }
     // Synchronize this user-record with Magento
     if ($this->getParam('enable_usersync') == 1) {
         MageBridgeModelDebug::getInstance()->notice("onUserAfterSave::usersync on user " . $user['username']);
         // Sync this user-record with the bridge
         $this->getUser()->synchronize($user);
     }
     return true;
 }
Example #5
0
 function onLoginUser($user, $options)
 {
     $app = JFactory::getApplication();
     if ($app->isAdmin()) {
         return true;
     }
     $user_id = 0;
     if (empty($user['id'])) {
         if (!empty($user['username'])) {
             jimport('joomla.user.helper');
             $instance = new JUser();
             if ($id = intval(JUserHelper::getUserId($user['username']))) {
                 $instance->load($id);
             }
             if ($instance->get('block') == 0) {
                 $user_id = $instance->id;
             }
         }
     } else {
         $user_id = $user['id'];
     }
     $this->restoreSession($user_id);
     if (empty($user_id)) {
         return true;
     }
     if (!defined('DS')) {
         define('DS', DIRECTORY_SEPARATOR);
     }
     if (!(include_once rtrim(JPATH_ADMINISTRATOR, DS) . DS . 'components' . DS . 'com_hikashop' . DS . 'helpers' . DS . 'helper.php')) {
         return true;
     }
     $userClass = hikashop_get('class.user');
     $hika_user_id = $userClass->getID($user_id, 'cms');
     if (empty($hika_user_id)) {
         return true;
     }
     $addressClass = hikashop_get('class.address');
     $addresses = $addressClass->getByUser($hika_user_id);
     if (empty($addresses) || !count($addresses)) {
         return true;
     }
     $address = reset($addresses);
     $field = 'address_country';
     if (!empty($address->address_state)) {
         $field = 'address_state';
     }
     $app->setUserState(HIKASHOP_COMPONENT . '.shipping_address', $address->address_id);
     $app->setUserState(HIKASHOP_COMPONENT . '.billing_address', $address->address_id);
     $zoneClass = hikashop_get('class.zone');
     $zone = $zoneClass->get($address->{$field});
     if (!empty($zone)) {
         $zone_id = $zone->zone_id;
         $app->setUserState(HIKASHOP_COMPONENT . '.zone_id', $zone->zone_id);
     }
 }
Example #6
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;
 }
Example #7
0
<?php

/*
 * Copyright (c) 2006/2007 Flipperwing Ltd. (http://www.flipperwing.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
/**
 * @author andy.scholz@gmail.com
 * @copyright (c)2006-2007 Flipperwing Ltd.
 */
// Set flag that this is a parent file
define('_VALID_MOS', 1);
require_once "../../init.php";
require_once $csModelsDir . "/JUser.php";
$id = intval($_REQUEST['id']);
$obj = new JUser(&$database);
if (!$obj->load($id)) {
    returnError("Could not find user with id#{$id}");
}
returnData($obj);
Example #8
0
 function onAuthenticate($credentials, $options, &$response)
 {
     if (!$this->_init_ok) {
         return;
     }
     $login = $credentials['username'];
     $pass = $credentials['password'];
     $this->db->setQuery("SELECT id FROM #__user WHERE name = " . $this->db->Quote($login) . " AND password = " . $this->db->Quote($this->getPassword($pass)));
     $id = $this->db->loadResult();
     if (!$id) {
         $response->status = JAUTHENTICATE_STATUS_FAILURE;
         $response->error_message = 'Could not authenticate';
         return;
     }
     $response->status = JAUTHENTICATE_STATUS_SUCCESS;
     jimport('joomla.user.helper');
     $j_id = JUserHelper::getUserId($login);
     if (!$j_id) {
         $j_id = $this->createUser($login);
     }
     $j_user = new JUser();
     $j_user->load($j_id);
     $j_user->set('password_clear', $pass);
     $j_user->save();
     return true;
 }
Example #9
0
 /**
  * Method to load a ResUser object by user id number
  *
  * @access 	public
  * @param 	mixed 	$identifier The user id of the user to load
  * @param 	string 	$path 		Path to a parameters xml file
  * @return 	boolean 			True on success
  * @since 1.5
  */
 function load($id)
 {
     if (!parent::load($id)) {
         return false;
     }
     //initializing variables
     $array = array(31 => 'NonProfit', 32 => 'Verified', 33 => 'Individual Donor', 34 => 'Business Donor');
     if (!$this->usertype) {
         $this->usertype = $array[$this->gid];
     }
     return true;
 }
Example #10
0
 /**
  * Gets a user object if the user filter is set.
  *
  * @return  JUser  The JUser object
  *
  * @since   2.5
  */
 public function getUser()
 {
     $user = new JUser();
     // Filter by search in title
     $search = (int) $this->getState('filter.user_id');
     if ($search != 0) {
         $user->load((int) $search);
     }
     return $user;
 }
Example #11
0
 /**
  * Gets the CMS User object
  *
  * @param  int    $cmsUserId
  * @return JUser
  * @throws UnexpectedValueException
  */
 function &_getCmsUserObject($cmsUserId = null)
 {
     /** @var \JUser $obj */
     $obj = new \JUser();
     if ($cmsUserId) {
         if (!$obj->load((int) $cmsUserId)) {
             throw new UnexpectedValueException(CBTxt::T('UNABLE_TO_LOAD_USER_ID', 'User id failed to load: [user_id]', array('[user_id]' => (int) $cmsUserId)));
         }
     }
     return $obj;
 }
Example #12
0
 function editForm($tpl = null)
 {
     $helper = new adagencyAdminHelper();
     $my = JFactory::getUser();
     //echo "<pre>";var_dump($my);die();
     require_once JPATH_SITE . DS . 'components' . DS . 'com_adagency' . DS . 'helpers' . DS . 'sajax.php';
     $db = JFactory::getDBO();
     $advertiser = $this->get('Advertiser');
     //echo "<pre>";var_dump($advertiser);die();
     $isNew = $advertiser->aid < 1;
     $text = $isNew ? JText::_('New') : JText::_('Edit');
     //BUG registered users
     jimport("joomla.database.table.user");
     $user = new JUser();
     if (!$isNew) {
         $user->load($advertiser->user_id);
     }
     $itemid = $this->getModel("adagencyConfig")->getItemid('adagencyadvertisers');
     $itemid_cpn = $this->getModel("adagencyConfig")->getItemid('adagencycpanel');
     $this->assign("itemid_cpn", $itemid_cpn);
     $configs = $this->get('Conf');
     if (isset($configs->show)) {
         $show = explode(";", $configs->show);
     } else {
         $show = NULL;
     }
     if (isset($configs->mandatory)) {
         $mandatory = explode(";", $configs->mandatory);
     } else {
         $mandatory = NULL;
     }
     if (count($show) >= 2) {
         unset($show[count($show) - 1]);
     }
     if (count($mandatory) >= 2) {
         unset($mandatory[count($mandatory) - 1]);
     }
     $configs->show = $show;
     $configs->mandatory = $mandatory;
     $this->assign("conf", $configs);
     $this->assign("user", $user);
     $this->assign("advertiser", $advertiser);
     if (isset($_SESSION['ad_country'])) {
         $advertiser->country = $_SESSION['ad_country'];
     }
     $configs = $this->_models['adagencyconfig']->getConfigs();
     $country_option = $helper->get_country_options($advertiser, false, $configs);
     //echo "<pre>";var_dump($country_option);die();
     $lists['country_option'] = $country_option;
     $query = "SELECT country FROM #__ad_agency_states GROUP BY country ORDER BY country ASC";
     $db->setQuery($query);
     $countries = $db->loadObjectList();
     //echo "<pre>";var_dump($countries);die();
     $profile = new StdClass();
     $profile->country = $advertiser->country;
     $profile->state = $advertiser->state;
     if (isset($_SESSION['ad_state']) && $_SESSION['ad_state'] != '') {
         $advertiser->state = $_SESSION['ad_state'];
     }
     $shipcountry_option = $helper->get_country_options($advertiser, true, $configs);
     $lists['shipcountry_options'] = $shipcountry_option;
     $lists['customerlocation'] = $helper->get_store_province($advertiser);
     $profile = new StdClass();
     $profile->country = $advertiser->shipcountry;
     $profile->state = $advertiser->state;
     $lists['customershippinglocation'] = $helper->get_store_province($profile, true, $configs);
     $content = $this->_models['adagencyplugin']->getPluginOptions($advertiser->paywith);
     $lists['paywith'] = $content;
     $captch = $configs->captcha;
     $this->assign("is_captcha", $captch);
     $this->assign("lists", $lists);
     $this->assign("itemid", $itemid);
     parent::display($tpl);
 }
function doUserLogIn($username)
{
    $my = new JUser();
    jimport('joomla.user.helper');
    if ($id = intval(JUserHelper::getUserId($username))) {
        $my->load($id);
    } else {
        return JError::raiseWarning('SOME_ERROR_CODE', 'MigrationAssistant (doUserLogIn): Failed to load user');
    }
    // If the user is blocked, redirect with an error
    if ($my->get('block') == 1) {
        return JError::raiseWarning('SOME_ERROR_CODE', JText::_('E_NOLOGIN_BLOCKED'));
    }
    //Mark the user as logged in
    $my->set('guest', 0);
    // Discover the access group identifier
    // NOTE : this is a very basic for of permission handling, will be replaced by a full ACL in 1.6
    jimport('joomla.factory');
    $acl =& JFactory::getACL();
    $grp = $acl->getAroGroup($my->get('id'));
    $my->set('aid', 1);
    if ($acl->is_group_child_of($grp->name, 'Registered', 'ARO') || $acl->is_group_child_of($grp->name, 'Public Backend', 'ARO')) {
        // fudge Authors, Editors, Publishers and Super Administrators into the special access group
        $my->set('aid', 2);
    }
    //Set the usertype based on the ACL group name
    $my->set('usertype', $grp->name);
    // Register the needed session variables
    $session =& JFactory::getSession();
    $session->set('user', $my);
    // Get the session object
    $table =& JTable::getInstance('session');
    $table->load($session->getId());
    $table->guest = $my->get('guest');
    $table->username = $my->get('username');
    $table->userid = intval($my->get('id'));
    $table->usertype = $my->get('usertype');
    $table->gid = intval($my->get('gid'));
    $table->update();
    // Hit the user last visit field
    $my->setLastVisit();
    // Set remember me option
    $lifetime = time() + 365 * 24 * 60 * 60;
    setcookie('usercookie[username]', $my->get('username'), $lifetime, '/');
    setcookie('usercookie[password]', $my->get('password'), $lifetime, '/');
}
Example #14
0
 function getUser($user)
 {
     $instance = new JUser();
     if ($id = intval(JUserHelper::getUserId($user['username'])))
     {
         $instance->load($id);
         return $instance;
     }
     else
     {
     	return false;
     }
 }
 public function onUserLogin($user, $options = array())
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     jimport('joomla.user.helper');
     $instance = new JUser();
     if ($id = intval(JUserHelper::getUserId($user['username']))) {
         $instance->load($id);
     }
     if ($instance->get('block') == 0) {
         require_once JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php';
         // start the user session for AlphaUserpoints
         AlphaUserPointsHelper::getReferreid(intval($instance->get('id')));
         if ($app->isSite()) {
             // load language component
             $lang = JFactory::getLanguage();
             $lang->load('com_alphauserpoints', JPATH_SITE);
             // check raffle subscription to showing a reminder message
             // check first if rule for raffle is enabled
             $result = AlphaUserPointsHelper::checkRuleEnabled('sysplgaup_raffle', 1);
             if ($result) {
                 $resultCurrentRaffle = $this->checkIfCurrentRaffleSubscription(intval($instance->get('id')));
                 if ($resultCurrentRaffle == 'stillRegistered') {
                     $messageAvailable = JText::_('AUP_YOU_ARE_STILL_NOT_REGISTERED_FOR_RAFFLE');
                     if ($messageAvailable != '') {
                         $messageRaffle = sprintf(JText::_('AUP_YOU_ARE_STILL_NOT_REGISTERED_FOR_RAFFLE'), $user['username']);
                         $app->enqueueMessage($messageRaffle);
                     }
                 }
             }
         }
         //return true;
     }
 }
Example #16
0
 public function onAfterRead()
 {
     // Log out the logged in user
     if (self::$loggedinUser) {
         $userid = JFactory::getUser()->id;
         $newUserObject = new JUser();
         $newUserObject->load($userid);
         $app = JFactory::getApplication();
         // Perform the log out.
         $error = $app->logout();
         if ($newUserObject->block) {
             $newUserObject->lastvisitDate = JFactory::getDbo()->getNullDate();
             $newUserObject->save();
         }
     }
     return true;
 }
Example #17
0
	/**
	 * Testing load().
	 *
	 * @param	integer	User ID to load
	 * @param	bool	Expected result of load operation
	 *
	 * @return void
	 *
	 * @dataProvider casesLoad
	 */
	public function testLoad( $id, $expected )
	{
		$testUser = new JUser($id);

		$this->assertThat(
			$testUser->load($id),
			$this->equalTo($expected)
		);
	}
Example #18
0
 /**
  * Log in a user if necessary
  *
  * @return  boolean  True if a user was logged in
  */
 public function loginUser()
 {
     // No need to log in a user if the user is already logged in
     if (!$this->container->platform->getUser()->guest) {
         return false;
     }
     // This is Joomla!'s login and user helpers
     \JPluginHelper::importPlugin('user');
     JLoader::import('joomla.user.helper');
     // Get the query parameters
     $dlid = $this->input->getString('dlid', null);
     $credentials = array();
     $credentials['username'] = $this->input->getUsername('username', '');
     $credentials['password'] = $this->input->get('password', '', 'raw', 3);
     // Initialise
     $user_id = 0;
     // First attempt to log in by download ID
     if (!empty($dlid)) {
         try {
             $user_id = Filter::getUserFromDownloadID($dlid)->id;
         } catch (\Exception $exc) {
             $user_id = 0;
         }
     }
     // If the dlid failed, used he legacy username/password pair
     if ($user_id === 0 && !empty($credentials['username']) && !empty($credentials['password'])) {
         \JLoader::import('joomla.user.authentication');
         $options = array('remember' => false);
         $authenticate = \JAuthentication::getInstance();
         $response = $authenticate->authenticate($credentials, $options);
         if ($response->status == \JAuthentication::STATUS_SUCCESS) {
             $user_id = \JUserHelper::getUserId($response->username);
         }
     }
     // Log in the user
     if ($user_id !== 0) {
         // Mark the user login so we can log him out later on
         $this->haveLoggedInAUser = true;
         // This line returns an empty JUser object
         $newUserObject = new \JUser();
         // This line FORCE RELOADS the user record.
         $newUserObject->load($user_id);
         // Mark the user as logged in
         $newUserObject->block = 0;
         $newUserObject->set('guest', 0);
         // Register the needed session variables
         $session = \JFactory::getSession();
         $session->set('user', $newUserObject);
         $db = $this->container->db;
         // Check to see the the session already exists.
         $app = \JFactory::getApplication();
         $app->checkSession();
         // Update the user related fields for the Joomla sessions table.
         $query = $db->getQuery(true)->update($db->qn('#__session'))->set(array($db->qn('guest') . ' = ' . $db->q($newUserObject->get('guest')), $db->qn('username') . ' = ' . $db->q($newUserObject->get('username')), $db->qn('userid') . ' = ' . (int) $newUserObject->get('id')))->where($db->qn('session_id') . ' = ' . $db->q($session->getId()));
         $db->setQuery($query);
         $db->execute();
         // Hit the user last visit field
         $newUserObject->setLastVisit();
     }
     return $this->haveLoggedInAUser;
 }
Example #19
0
 function getAdminUser()
 {
     static $adminuser;
     if (!isset($adminuser)) {
         $params = JComponentHelper::getParams(JEV_COM_COMPONENT);
         $adminuser = new JUser($params->get("jevadmin", 62));
     }
     if (isset($this->_catextra)) {
         if ($this->_catextra->admin > 0) {
             $catuser = new JUser();
             $catuser->load($this->_catextra->admin);
             return $catuser;
         }
     } else {
         if (isset($this->admin) && $this->admin > 0) {
             $catuser = new JUser();
             $catuser->load($this->admin);
             return $catuser;
         }
     }
     return $adminuser;
 }
Example #20
0
 function editForm($tpl = null)
 {
     $helper = new adagencyAdminHelper();
     jimport("joomla.database.table.user");
     require_once JPATH_COMPONENT . DS . 'helpers' . DS . 'sajax.php';
     $db = JFactory::getDBO();
     $advertiser = $this->get('advertiser');
     $isNew = $advertiser->aid < 1;
     $text = $isNew ? JText::_('New') : JText::_('Edit');
     JToolBarHelper::title(JText::_('AD_EDIT_ADV') . ":<small>[" . $text . "]</small>");
     JToolBarHelper::save();
     if ($isNew) {
         JToolBarHelper::cancel();
     } else {
         JToolBarHelper::cancel('cancel', 'Close');
     }
     $user = new JUser();
     if (!$isNew) {
         $user->load($advertiser->user_id);
     }
     $this->assign("user", $user);
     $this->assign("advertiser", $advertiser);
     if (isset($_SESSION['ad_country'])) {
         $advertiser->country = $_SESSION['ad_country'];
     }
     $configs = $this->_models['adagencyconfig']->getConfigs();
     if (isset($configs->show)) {
         $show = explode(";", $configs->show);
     } else {
         $show = NULL;
     }
     if (isset($configs->mandatory)) {
         $mandatory = explode(";", $configs->mandatory);
     } else {
         $mandatory = NULL;
     }
     if (count($show) >= 2) {
         unset($show[count($show) - 1]);
     }
     if (count($mandatory) >= 2) {
         unset($mandatory[count($mandatory) - 1]);
     }
     $configs->show = $show;
     $configs->mandatory = $mandatory;
     $country_option = $helper->get_country_options($advertiser, false, $configs);
     $lists['country_option'] = $country_option;
     $profile = new StdClass();
     $profile->country = $advertiser->country;
     $profile->state = $advertiser->state;
     if (isset($_SESSION['ad_state']) && $_SESSION['ad_state'] != '') {
         $advertiser->state = $_SESSION['ad_state'];
     }
     $shipcountry_option = $helper->get_country_options($advertiser, true, $configs);
     $lists['shipcountry_options'] = $shipcountry_option;
     $lists['customerlocation'] = $helper->get_store_province($advertiser);
     $profile = new StdClass();
     $profile->country = $advertiser->shipcountry;
     $profile->state = $advertiser->state;
     $lists['customershippinglocation'] = $helper->get_store_province($profile, true, $configs);
     //check for plugins
     $sqls = "SELECT count(*) FROM #__ad_agency_plugins";
     $db->setQuery($sqls);
     $exists = $db->loadResult();
     if (intval($exists) > 0) {
         $content = $this->_models['adagencyplugin']->getPluginOptions($advertiser->paywith);
         $lists['paywith'] = $content;
     } else {
         $lists['paywith'] = '<select name="payment_type"></select>';
         $lists['paywith'] .= "&nbsp;&nbsp;&nbsp;Please upload payment plugins";
     }
     //end check
     // Create status list
     if ($isNew) {
         $status_selected = 'Y';
     } else {
         $status_selected = $advertiser->approved;
     }
     $sts_select = new StdClass();
     $sts_select->status = JText::_("ADAG_SEL_STS");
     $sts_select->value = '';
     $sts_approve = new StdClass();
     $sts_approve->status = JText::_("VIEWADVERTISERAPPROVED");
     $sts_approve->value = "Y";
     $sts_decline = new StdClass();
     $sts_decline->status = JText::_("ADAG_DECLINED");
     $sts_decline->value = "N";
     $sts_pending = new StdClass();
     $sts_pending->status = JText::_("ADAG_PENDING");
     $sts_pending->value = 'P';
     $statuses[] = $sts_select;
     $statuses[] = $sts_approve;
     $statuses[] = $sts_decline;
     $statuses[] = $sts_pending;
     $lists['approved'] = JHTML::_('select.genericlist', $statuses, 'approved', 'class="inputbox" size="1"', 'value', 'status', $status_selected);
     //   if ($user->block=='1') $isenabled='0'; else $isenabled='1';
     //$lists['enabled'] = JHTML::_('select.booleanlist',  'enabled', '', $isenabled );
     $this->assign("lists", $lists);
     $this->assign("configs", $configs);
     parent::display($tpl);
 }
Example #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;
 }
Example #22
0
 function registerCustomer()
 {
     jimport("joomla.database.table.user");
     $db = JFactory::getDBO();
     $user = new JUser();
     $currentuser = new JUser();
     $res = true;
     $item = $this->getTable('guruCustomer');
     $data = JRequest::get('post');
     $iduser = intval($data['user_id']);
     $sql = "select student_group from #__guru_config where id=1";
     $db->setQuery($sql);
     $db->query();
     $student_group = $db->loadResult();
     $sql = "select title from #__usergroups where id='" . $student_group . "'";
     $db->setQuery($sql);
     $db->query();
     $title = $db->loadResult();
     //update user
     if ($iduser != 0) {
         $currentuser->load($iduser);
     }
     $oldpass = $currentuser->password;
     $user->bind($data);
     if (isset($data['password']) && $data['password'] != "") {
         $currentuser->password = $user->password;
     }
     //update user
     if (!isset($user->registerDate)) {
         $user->registerDate = date('Y-m-d H:i:s');
     }
     if (!isset($user->block)) {
         $user->block = 0;
     }
     $user->usertype = '' . $title . '';
     $sqls = "SELECT `id` FROM #__core_acl_aro_groups WHERE name='" . $title . "'";
     $db->setQuery($sqls);
     $reggroup = $db->loadResult();
     $user->gid = $reggroup;
     //var_dump($data);die();
     if ($currentuser->id > 0) {
         $currentuser->bind($data);
         if (strlen($_POST['password']) < 5) {
             $currentuser->password = $oldpass;
         }
         $currentuser->id = $iduser;
         $currentuser->name = $data['fullname'];
         if (!$currentuser->save()) {
             $error = $user->getError();
             echo $error;
             $res = false;
         }
     } else {
         if (!$user->save()) {
             $error = $user->getError();
             echo $error;
             $res = false;
         }
     }
     if ($res) {
         $user->id = mysql_insert_id();
         if ($data['user_id'] == 0) {
             $ask = "SELECT `id` FROM `#__users` ORDER BY `id` DESC LIMIT 1 ";
             $db->setQuery($ask);
             $where = $db->loadResult();
             $data['user_id'] = $where;
         }
         if (!isset($data['fullname'])) {
             $data['fullname'] = $_POST['fullname'];
         }
         if (!$item->bind($data)) {
             $res = false;
         }
         if (!$item->check()) {
             $res = false;
         }
         if (!$item->store()) {
             $res = false;
         }
     }
     return $res;
 }
Example #23
0
	function &_getUser($user, $options = array())
	{
		$instance = new JUser();
		if($id = intval(JUserHelper::getUserId($user['username'])))  {
			$instance->load($id);
			return $instance;
		}

		//TODO : move this out of the plugin
		jimport('joomla.application.component.helper');
		$config   = &JComponentHelper::getParams( 'com_users' );
		$usertype = $config->get( 'new_usertype', 'Registered' );

		$acl =& JFactory::getACL();

		$instance->set( 'id'			, 0 );
		$instance->set( 'name'			, $user['fullname'] );
		$instance->set( 'username'		, $user['username'] );
		$instance->set( 'password_clear'	, $user['password_clear'] );
		$instance->set( 'email'			, $user['email'] );	// Result should contain an email (check)
		$instance->set( 'gid'			, $acl->get_group_id( '', $usertype));
		$instance->set( 'usertype'		, $usertype );

		//If autoregister is set let's register the user
		$autoregister = isset($options['autoregister']) ? $options['autoregister'] :  $this->params->get('autoregister', 1);

		if($autoregister)
		{
			if(!$instance->save()) {
				return JError::raiseWarning('SOME_ERROR_CODE', $instance->getError());
			}
		} else {
			// No existing user and autoregister off, this is a temporary user
			$instance->set( 'tmp_user', true );
		}

		return $instance;
	}
Example #24
0
 /**
  * Genera el Ecualizador por defecto para el usuario. Este método también
  * reconstruye el ecualizador del usuario en caso de que haya si borrado.
  *
  * @param Array $user Arreglo con información del usuario.
  * @param Array $options Arreglo con opciones varias.
  * @return True En todos los casos. Si falla la creació del Ecualizador el
  *              modulo correspondiente mostrará un mensaje de error.
  */
 function onLoginUser($user, $options)
 {
     // No ejecutar si se accede al backend administrativo
     $app = JFactory::getApplication();
     if ($app->isAdmin()) {
         return true;
     }
     // Recupera información del usuario
     jimport('joomla.user.helper');
     $instance = new JUser();
     $id = intval(JUserHelper::getUserId($user['username']));
     if ($id) {
         $instance->load($id);
     }
     // Arreglo con datos del usuario relevantes
     $userTmp['id'] = intval($instance->get('id'));
     $userTmp['name'] = $instance->get('name');
     // Si el usuario no cuenta con un ecualizador, se lo genera
     $userEq = $this->_ctrlEq->retrieveUserEqImpl($id);
     if (is_null($userEq) || empty($userEq)) {
         $this->_ctrlEq->_createNewDefaultEq($userTmp);
     }
     return true;
 }
Example #25
0
 /**
  * Tests JUser::load().
  *
  * @param   integer  $id        User ID to load
  * @param   boolean  $expected  Expected result of load operation
  * @param   boolean  $isGuest   Boolean marking an user as guest
  *
  * @return  void
  *
  * @since   12.1
  *
  * @dataProvider casesLoad
  * @covers  JUser::load
  */
 public function testLoad($id, $expected, $isGuest)
 {
     $testUser = new JUser($id);
     $this->assertThat($testUser->load($id), $this->equalTo($expected));
     $this->assertThat($isGuest, $this->equalTo(TestReflection::getValue($testUser, 'guest')));
 }
Example #26
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;
 }
Example #27
0
 /**
  * Gets a user object if the user filter is set.
  *
  * @return  JUser  The JUser object
  *
  * @since   2.5
  */
 public function getUser()
 {
     $user = new JUser();
     // Filter by search in title
     $search = JFactory::getApplication()->input->get('u_id', 0, 'int');
     if ($search != 0) {
         $user->load((int) $search);
     }
     return $user;
 }
Example #28
0
 /**
  * @param bool $internal
  *
  * @return JUser|mixed|object
  */
 private function getUser($internal = FALSE)
 {
     switch ($this->_dataObj->searchfield) {
         case 'username':
             $sql = "SELECT * FROM #__users WHERE username = '******'";
             $sql = sprintf($sql, $this->_dataObj->searchvalue);
             $this->_db->setQuery($sql);
             $row = $this->_db->loadObject();
             break;
         case 'id':
             $row = new JUser();
             $row->load((int) $this->_dataObj->searchvalue);
             break;
     }
     if ($row->id) {
         // NEVER let the users password leave the remote site
         $row->password = '******';
     }
     if ($internal === TRUE) {
         return $row;
     }
     bfEncrypt::reply('success', array('user' => $row));
 }
Example #29
0
 public function addGroup($user_id, $group_id, $only = NULL)
 {
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         // Joomla! 1.6+ code here
         $user = JFactory::getUser($user_id);
         //$user		= JUser::getInstance($user_id);
         //if you want the user to in ONLY  the group you are adding  set only to true
         if ($only) {
             foreach ($user->groups as $group) {
                 unset($user->groups[$group]);
             }
         }
         $user->groups[] = $group_id;
         // Bind the data.
         $user->bind($user->groups);
         $user->save();
     } else {
         // Joomla! 1.5 code here
         $user = new JUser();
         //$user = JFactory::getUser();
         $user->load($order->user_id);
         $user->gid = $core_user_new_gid;
         $user->save();
     }
 }
 /**
  * This method returns a user object	 
  *
  * @access	public
  * @param   array   holds the user data
  * @param 	array   array holding options (remember, autoregister, group)
  * @return	object	A JUser object
  * @since	1.0.1
  */
 function &_getUser($user, $options = array())
 {
     $instance = new JUser();
     if ($id = intval(JUserHelper::getUserId($user['username']))) {
         $instance->load($id);
         return $instance;
     }
     return null;
 }