/** User Login Task */
 public function getLogin()
 {
     $db = JFactory::getDbo();
     header("Content-Type: application/json; charset=UTF-8");
     // ["fields",{"product_id":"10"}]
     //$data=json_decode(JRequest::getVar('fields'),true);
     //$product_id= $data['product_id'];
     $result = array();
     $username = JRequest::getVar('username');
     $password = JRequest::getVar('password');
     $query = $db->getQuery(true);
     $query->select('*')->from($db->quoteName('#__users'))->where($db->quoteName('username') . " = " . $db->quote($username));
     $db->setQuery($query);
     $data = $db->loadAssocList();
     foreach ($data as $results) {
         $dbpassword = $results['password'];
         $dbuserid = $results['id'];
     }
     if (JUserHelper::verifyPassword($password, $dbpassword, $dbuserid)) {
         $datelogged = date('Y-m-d H:i:s');
         $dat = array('status' => '1', 'result' => $results);
         echo json_encode($dat);
         exit;
     } else {
         $dat = array('status' => '0', 'result' => '');
         echo json_encode($dat);
         exit;
     }
 }
Example #2
0
 public function createCoupon($key, $pwd)
 {
     // Do I have a key/pwd pair?
     if (!$key || !$pwd) {
         return array('error' => JText::_('COM_AKEEBASUBS_APICOUPONS_INVALID_CREDENTIALS'));
     }
     $table = $this->getTable();
     $table->load(array('key' => $key, 'password' => $pwd));
     // Are they valid?
     if (!$table->akeebasubs_apicoupon_id || !$table->enabled) {
         return array('error' => JText::_('COM_AKEEBASUBS_APICOUPONS_INVALID_CREDENTIALS'));
     }
     // Do I hit a limit?
     if (!$this->performApiChecks($table)) {
         return array('error' => JText::_('COM_AKEEBASUBS_APICOUPONS_LIMIT_EXCEEDED'));
     }
     // If I'm here, I'm clear to go
     JLoader::import('joomla.user.helper');
     $coupon = F0FTable::getAnInstance('Coupon', 'AkeebasubsTable');
     $data['akeebasubs_apicoupon_id'] = $table->akeebasubs_apicoupon_id;
     $data['title'] = 'API coupon for: ' . $table->title;
     $data['coupon'] = strtoupper(JUserHelper::genRandomPassword(10));
     $data['subscriptions'] = $table->subscriptions;
     // By default I want the coupon to be single-use
     $data['hitslimit'] = 1;
     $data['userhits'] = 1;
     $data['type'] = $table->type;
     $data['value'] = $table->value;
     if (!$coupon->save($data)) {
         return array('error' => JText::_('COM_AKEEBASUBS_APICOUPONS_COUPON_ERROR'));
     }
     return array('coupon' => $coupon->coupon);
 }
 /**
  * Function to create a user of Joomla.
  *
  * @param array  $params associated array
  * @param string $mail email id for cms user
  *
  * @return uid if user exists, false otherwise
  *
  * @access public
  */
 function createUser(&$params, $mail)
 {
     require_once JPATH_SITE . '/components/com_users/models/registration.php';
     $userParams = JComponentHelper::getParams('com_users');
     $model = new UsersModelRegistration();
     $ufID = NULL;
     // get the default usertype
     $userType = $userParams->get('new_usertype');
     if (!$userType) {
         $userType = 2;
     }
     if (isset($params['name'])) {
         $fullname = trim($params['name']);
     } elseif (isset($params['contactID'])) {
         $fullname = trim(CRM_Contact_BAO_Contact::displayName($params['contactID']));
     } else {
         $fullname = trim($params['cms_name']);
     }
     // Prepare the values for a new Joomla user.
     $values = array();
     $values['name'] = $fullname;
     $values['username'] = trim($params['cms_name']);
     $values['password1'] = $values['password2'] = $params['cms_pass'];
     $values['email1'] = $values['email2'] = trim($params[$mail]);
     $lang = JFactory::getLanguage();
     $lang->load('com_users');
     $register = $model->register($values);
     $ufID = JUserHelper::getUserId($values['username']);
     return $ufID;
 }
 /**
  * Password is saved to Joomla DB after succesful authentication
  *
  * @access    public
  * @return    boolean
  * @since 1.5
  */
 function onUserAfterLogin()
 {
     /* po uspesnem prihlaseni ulozime heslo */
     if (isset($_POST["password"]) && $_POST["password"] != "") {
         // misto $_POST["password"] by melo byt
         //$jinput = JFactory::getApplication()->input;
         //$password = $jinput->get('password', '', 'STRING');
         // http://stackoverflow.com/questions/2727043/using-php-to-create-a-joomla-user-password
         jimport('joomla.user.helper');
         $salt = JUserHelper::genRandomPassword(32);
         $crypt = JUserHelper::getCryptedPassword($_POST["password"], $salt);
         $password = $crypt . ':' . $salt;
         // Get a database object
         $user = JFactory::getUser();
         $db =& JFactory::getDBO();
         $query = $db->getQuery(true);
         $fields = array($db->quoteName('password') . ' = "' . $password . '"');
         $conditions = array($db->quoteName('username') . ' = "' . $user->username . '"');
         $query->update($db->quoteName('#__users'))->set($fields)->where($conditions);
         $db->setQuery($query);
         $result = $db->execute();
         return $result;
     }
     return false;
 }
Example #5
0
 /**
  * Returns the global KunenaUser object, only creating it if it doesn't already exist.
  *
  * @access	public
  * @param	int	$id	The user to load - Can be an integer or string - If string, it is converted to ID automatically.
  * @return	JUser			The User object.
  * @since	1.6
  */
 public static function getInstance($identifier = null, $reset = false)
 {
     $c = __CLASS__;
     if ($identifier instanceof KunenaUser) {
         return $identifier;
     }
     if ($identifier === null || $identifier === false) {
         $identifier = JFactory::getUser();
     }
     // Find the user id
     if ($identifier instanceof JUser) {
         $id = intval($identifier->id);
     } else {
         if (is_numeric($identifier)) {
             $id = intval($identifier);
         } else {
             jimport('joomla.user.helper');
             $id = intval(JUserHelper::getUserId((string) $identifier));
         }
     }
     if ($id < 1) {
         return new $c();
     }
     if (!$reset && empty(self::$_instances[$id])) {
         self::$_instances[$id] = new $c($id);
     }
     return self::$_instances[$id];
 }
Example #6
0
 public function action($request)
 {
     $db = JFactory::getDBO();
     $set = array();
     if ($this->settings['activate']) {
         $set[] = '`block` = \'0\'';
         $set[] = '`activation` = \'\'';
     }
     $username = $this->getUsername($request);
     if (!empty($username)) {
         $set[] = '`username` = \'' . $username . '\'';
     }
     if (!empty($this->settings['password'])) {
         $pw = AECToolbox::rewriteEngineRQ($this->settings['password'], $request);
         jimport('joomla.user.helper');
         $salt = JUserHelper::genRandomPassword(32);
         $crypt = JUserHelper::getCryptedPassword($pw, $salt);
         $password = $crypt . ':' . $salt;
         $set[] = '`password` = \'' . $password . '\'';
     }
     if (!empty($set)) {
         $query = 'UPDATE #__users';
         $query .= ' SET ' . implode(', ', $set);
         $query .= ' WHERE `id` = \'' . (int) $request->metaUser->userid . '\'';
         $db->setQuery($query);
         $db->query() or die($db->stderr());
         $userid = $request->metaUser->userid;
         // Reloading metaUser object for other MIs
         $request->metaUser = new metaUser($userid);
     }
     if (!empty($this->settings['set_fields'])) {
         $this->setFields($request);
     }
 }
Example #7
0
 function ajaxSaveRow()
 {
     $user = JFactory::getUser();
     $id = $user->get('id');
     jimport('joomla.mail.helper');
     jimport('joomla.user.helper');
     global $mainframe;
     $db =& JFactory::getDBO();
     $varolan = JRequest::getVar('varolan');
     $yeni = JRequest::getVar('yeni');
     $sql = "select password from jos_users where id={$id}";
     $liste = mysql_fetch_array(mysql_query($sql));
     $parts = explode(":", $liste[password]);
     $crypt = $parts[0];
     $salt = @$parts[1];
     $testcrypt = JUserHelper::getCryptedPassword($varolan, $salt);
     if ($crypt == $testcrypt) {
         $salt = JUserHelper::genRandomPassword(32);
         $crypt = JUserHelper::getCryptedPassword($yeni, $salt);
         $password = $crypt . ':' . $salt;
         $query = 'UPDATE #__users' . ' SET `password` = "' . $password . '"' . ' WHERE id = ' . (int) $id . ' AND block = 0';
         $db->setQuery($query);
         $db->query();
         echo "<p align=center>Şifreniz başarıyla değiştirildi.</p>";
     } else {
         echo "<p align=center>Geçerli şifreniz yanlış.</p><p align=center><a href='index.php?option=com_user&view=changepass'>Yeniden deneyiniz</a></p>";
     }
 }
Example #8
0
 private function authenticate($username, $password = null, $valid = 86400)
 {
     // Get a database object
     $db = JFactory::getDbo();
     // Look for any tokens for this user
     $db->setQuery($db->getQuery(true)->select('*')->from('#__rvs_user_tokens')->where('uid=' . $db->q($result->id)));
     $obj = $db->loadObject();
     // If there is already a valid token, just return that, otherwise try to create one
     if ($obj->valid > JDate::getInstance()->toUnix()) {
         return $obj->token;
     } else {
         $db->setQuery($db->getQuery(true)->select('id, password')->from('#__users')->where('username='******':', $result->password);
         $crypt = $parts[0];
         $salt = @$parts[1];
         $testcrypt = JUserHelper::getCryptedPassword($password, $salt);
         if ($crypt == $testcrypt) {
             // Authentication successful, create a token and populate the table
             $obj = new stdClass();
             $obj->uid = $result->id;
             $obj->token = md5(rand() . $salt);
             $obj->valid = JDate::getInstance()->toUnix() + $valid;
             $db->setQuery($db->getQuery(true)->select('uid')->from('#__rvs_user_tokens')->where('uid=' . $db->q($obj->uid)));
             if ($db->loadResult()) {
                 $db->updateObject('#__rvs_user_tokens', $obj, 'uid');
             } else {
                 $db->insertObject('#__rvs_user_tokens', $obj, 'uid');
             }
             return $obj->token;
         }
     }
     return null;
 }
Example #9
0
 function _owner($getgroup = false)
 {
     static $owner = false;
     static $group = false;
     if ($getgroup === false && !empty($owner)) {
         return $owner;
     }
     if ($getgroup === true && !empty($group)) {
         return $group;
     }
     jimport('joomla.user.helper');
     $tmp = md5(JUserHelper::genRandomPassword(16));
     $dir = self::tmpdir();
     if ($dir) {
         $test = $dir . DS . $tmp;
         // Create the test file
         JFile::write($test, '');
         // Test ownership
         $owner = fileowner($test);
         $group = filegroup($test);
         // Delete the test file
         JFile::delete($test);
     }
     return $getgroup ? $group : $owner;
 }
Example #10
0
 /**
  * Generate token here to standardize the token generation
  * @condition if the userId is provided it will be assign to the user directly
  * @see assignToken()
  * @return String generated token
  */
 public function generateToken()
 {
     $salt = JUserHelper::genRandomPassword(20);
     $crypt = JUserHelper::getCryptedPassword(rand(), $salt);
     $token = $crypt . ':' . $salt;
     return $token;
 }
Example #11
0
 function display($tpl = null)
 {
     $option = JRequest::getCMD('option');
     $mainframe = JFactory::getApplication();
     $user = JFactory::getUser();
     if ($user->get('guest')) {
         // Redirect to login
         $uri = JFactory::getURI();
         $mainframe->redirect('index.php?option=com_users&view=login&return=' . base64_encode($uri), null);
         return;
     } else {
         $groups = JUserHelper::getUserGroups($user->get('id'));
         if (!in_array(4, $groups)) {
             JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
             return;
         }
     }
     $document =& JFactory::getDocument();
     //$document->addScript( '/media/system/js/viewutils.js');
     //$document->addScript('/media/system/js/mootools1.js');
     //$document->addStyleSheet('/media/system/css/global.css');
     //$document->addStyleSheet('/media/system/css/content.css');
     $document->addStylesheet('/media/system/css/ZoneStyle.css');
     $helper = new comZonalesHelper();
     $this->assignRef('template', $mainframe->getTemplate());
     $this->assignRef('user', $user);
     $host = 'localhost';
     $this->assignRef('tomcat_host', $host);
     $port = '38080';
     $this->assignRef('tomcat_port', $port);
     $this->assignRef('zonal_id', ucwords(str_replace("_", "+", $helper->getZonalActual())));
     parent::display($tpl);
 }
Example #12
0
 function simple_registration($username, $password, $name, $email, $defaultUserGroups = array(2))
 {
     //Default group 2=registered
     $result = array('error', 'message');
     $usersConfig =& JComponentHelper::getParams('com_users');
     if ($usersConfig->get('allowUserRegistration') == '1') {
         //PASSWORD
         $salt = JUserHelper::genRandomPassword(32);
         $password_clear = $password;
         $crypted = JUserHelper::getCryptedPassword($password_clear, $salt);
         $password = $crypted . ':' . $salt;
         //set
         $instance = JUser::getInstance();
         $instance->set('id', 0);
         $instance->set('name', $name);
         $instance->set('username', $username);
         $instance->set('password', $password);
         $instance->set('password_clear', $password_clear);
         $instance->set('email', $email);
         $instance->set('groups', $defaultUserGroups);
         if (!$instance->save()) {
             //resultat
             $result['error'] = true;
             $result['message'] = 'bad data';
         } else {
             $result['error'] = false;
             $result['message'] = 'success';
         }
     } else {
         $result['error'] = true;
         $result['message'] = 'no allow user registration';
     }
     return $result;
 }
 function onAuthenticate($credentials, $options, &$response)
 {
     jimport('joomla.user.helper');
     if (empty($credentials['password'])) {
         $response->status = JAUTHENTICATE_STATUS_FAILURE;
         $response->error_message = 'Empty password not allowed';
         return false;
     }
     $db =& JFactory::getDBO();
     $sql = 'SELECT `id`, `password`, `gid` FROM `#__users` WHERE payroll=' . $db->Quote($credentials['username']);
     $db->setQuery($sql);
     $result = $db->loadObject();
     if ($result) {
         $parts = explode(':', $result->password);
         $crypt = $parts[0];
         $salt = @$parts[1];
         $testcrypt = JUserHelper::getCryptedPassword($credentials['password'], $salt);
         if ($crypt == $testcrypt) {
             $user = JUser::getInstance($result->id);
             // Bring this in line with the rest of the system
             $response->username = $user->username;
             $response->email = $user->email;
             $response->fullname = $user->name;
             $response->status = JAUTHENTICATE_STATUS_SUCCESS;
             $response->error_message = '';
         } else {
             $response->status = JAUTHENTICATE_STATUS_FAILURE;
             $response->error_message = 'Invalid password';
         }
     } else {
         $response->status = JAUTHENTICATE_STATUS_FAILURE;
         $response->error_message = 'User does not exist';
     }
 }
 public function handle()
 {
     require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Memberships.php';
     $ms = new \Components\Storefront\Models\Memberships();
     /* NEW
     		$subscription = StorefrontModelMemberships::getSubscriptionObject($this->type, $this->pId, $this->uId);
     		// Get the expiration for the current subscription (if any)
     		$currentExpiration = $subscription->getExpiration();
     		*/
     // Get current registration
     $membership = $ms->getMembershipInfo($this->crtId, $this->item['info']->pId);
     $expiration = $membership['crtmExpires'];
     /* Add the user to the corresponding user access group (pull access group ID from the meta) */
     try {
         // Get user ID for the cart
         require_once dirname(dirname(dirname(__DIR__))) . DS . 'models' . DS . 'Cart.php';
         $userId = \Components\Cart\Models\Cart::getCartUser($this->crtId);
         // Get the user group ID to set the user to (from meta)
         require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Product.php';
         $userGId = \Components\Storefront\Models\Product::getMeta($this->item['info']->pId, 'userGroupId');
         $add = \JUserHelper::addUserToGroup($userId, $userGId);
         if ($add instanceof \Exception) {
             mail(Config::get('mailfrom'), 'Error adding to the group', $add->getMessage() . ' Cart #' . $this->crtId);
         }
         $table = \JTable::getInstance('User', 'JTable', array());
         $table->load($userId);
         // Trigger the onAftereStoreUser event
         Event::trigger('onUserAfterSave', array($table->getProperties(), false, true, null));
     } catch (Exception $e) {
         // Error
         return false;
     }
 }
Example #15
0
 /**
  * validate the elements data against the rule
  * @param string data to check
  * @param object element
  * @param int plugin sequence ref
  * @return bol true if validation passes, false if fails
  */
 function validate($data, &$element, $c)
 {
     $params =& $this->getParams();
     $ornot = $params->get('userexists_or_not');
     $condition = $params->get('userexists-validation_condition');
     $condition = $condition[$c];
     if ($condition !== '') {
         if (@eval($condition)) {
             return true;
         }
     }
     $ornot = $ornot[$c];
     jimport('joomla.user.helper');
     $id = 0;
     if (!($id = JUserHelper::getUserId($data))) {
         if ($ornot == 'fail_if_exists') {
             return true;
         }
     } else {
         if ($ornot == 'fail_if_not_exists') {
             return true;
         }
     }
     return false;
 }
Example #16
0
 function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $model = new EstivoleModelMember();
     $this->state = $this->get('State');
     $this->member = $this->get('Item');
     $this->form = $this->get('Form');
     $userId = $this->member->user_id;
     if ($userId != '') {
         $this->user = JFactory::getUser($userId);
     } else {
         $this->user = null;
     }
     $this->userProfile = JUserHelper::getProfile($userId);
     $this->userProfilEstivole = EstivoleHelpersUser::getProfilEstivole($userId);
     if ($this->member->member_id != null) {
         $modelCalendars = new EstivoleModelCalendars();
         $modelDaytime = new EstivoleModelDaytime();
         $this->calendars = $modelCalendars->listItems();
         for ($i = 0; $i < count($this->calendars); $i++) {
             $this->calendars[$i]->member_daytimes = $modelDaytime->getMemberDaytimes($this->member->member_id, $this->calendars[$i]->calendar_id);
         }
     }
     $this->addToolbar();
     //display
     return parent::display($tpl);
 }
 /**
  * getChannels
  *
  * @param   string  $author  Param
  *
  * @return	array
  */
 public function getChannels($author)
 {
     $channels = F0FModel::getTmpInstance('Channels', 'AutoTweetModel');
     $channels->set('published', true);
     $channels->set('scope', 'S');
     $channels->set('filter_order', 'ordering');
     $channels->set('filter_order_Dir', 'ASC');
     $list = $channels->getItemList(true);
     if (!empty($author)) {
         $user_id = JUserHelper::getUserId($author);
         if ($user_id) {
             $userChannels = F0FModel::getTmpInstance('Channels', 'AutoTweetModel');
             $userChannels->set('published', true);
             $userChannels->set('scope', 'U');
             $userChannels->set('created_by', $user_id);
             $userChannels->set('filter_order', 'ordering');
             $userChannels->set('filter_order_Dir', 'ASC');
             $userList = $userChannels->getItemList(true);
             $list = array_merge($list, $userList);
         }
     }
     $channels = array();
     foreach ($list as $channel) {
         $channels[$channel->id] = self::createChannel($channel);
     }
     $logger = AutotweetLogger::getInstance();
     $channels_ids = array_keys($channels);
     $logger->log(JLog::INFO, 'ChannelFactory getChannels user=' . $author, $channels_ids);
     return $channels;
 }
Example #18
0
 /**
  * the user is admin?
  * @param JUser $user
  * @return boolean      
  */
 public function isAdmin($user = false)
 {
     jimport('joomla.user.helper');
     if ($user == false) {
         $user = JFactory::getUser();
     }
     $result = false;
     if ($user) {
         $groups = JUserHelper::getUserGroups($user->id);
         //DBG foreach($groups as $fn => $fv) echo '<p>'.$fn.'='.$fv.'</p>'; exit();
         $admin_groups = array();
         //put all the groups that you consider to be admins
         $admin_groups[] = "Super Users";
         $admin_groups[] = "Administrator";
         $admin_groups[] = "Manager";
         $admin_groups[] = "8";
         $admin_groups[] = "7";
         $admin_groups[] = "6";
         foreach ($admin_groups as $temp) {
             if (!empty($groups[$temp])) {
                 $result = true;
             }
         }
     }
     return $result;
 }
Example #19
0
 public function addTempUser($data)
 {
     $db =& $this->getDBO();
     //get current session id.
     $mySess =& JFactory::getSession();
     $token = $mySess->get('JS_REG_TOKEN', '');
     $nowDate = JFactory::getDate();
     $nowDate = $nowDate->toMysql();
     // Combine firsname and last name as full name
     if (empty($data['jsname'])) {
         $data['jsname'] = $data['jsfirstname'] . ' ' . $data['jslastname'];
     }
     $obj = new stdClass();
     $obj->name = $data['jsname'];
     $obj->firstname = isset($data['jsfirstname']) ? $data['jsfirstname'] : '';
     $obj->lastname = isset($data['jslastname']) ? $data['jslastname'] : '';
     $obj->token = $token;
     $obj->username = $data['jsusername'];
     $obj->email = $data['jsemail'];
     $obj->password = $data['jspassword'];
     $obj->created = $nowDate;
     $obj->ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
     // no clear text password store in db
     jimport('joomla.user.helper');
     $salt = JUserHelper::genRandomPassword(32);
     $crypt = JUserHelper::getCryptedPassword($obj->password, $salt);
     $obj->password = $crypt . ':' . $salt;
     $db->insertObject('#__community_register', $obj);
     if ($db->getErrorNum()) {
         JError::raiseError(500, $db->stderr());
     }
     $this->return_value[__FUNCTION__] = true;
     return $this;
 }
Example #20
0
 /**
  * Returns the global KunenaUser object, only creating it if it doesn't already exist.
  *
  * @param   mixed $identifier	The user to load - Can be an integer or string - If string, it is converted to ID automatically.
  * @param   bool $reload		Reload user from database.
  *
  * @return KunenaUser
  */
 public static function get($identifier = null, $reload = false)
 {
     KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
     if ($identifier === null || $identifier === false) {
         KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
         return self::$_me;
     }
     if ($identifier instanceof KunenaUser) {
         KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
         return $identifier;
     }
     // Find the user id
     if ($identifier instanceof JUser) {
         $id = (int) $identifier->id;
     } elseif ((string) (int) $identifier === (string) $identifier) {
         // Ignore imported users, which haven't been mapped to Joomla (id<0).
         $id = (int) max($identifier, 0);
     } else {
         // Slow, don't use usernames!
         $id = (int) JUserHelper::getUserId((string) $identifier);
     }
     // Always return fresh user if id is anonymous/not found
     if ($id === 0) {
         KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
         return new KunenaUser($id);
     } elseif ($reload || empty(self::$_instances[$id])) {
         self::$_instances[$id] = new KunenaUser($id);
         // Preload avatar if configured.
         $avatars = KunenaFactory::getAvatarIntegration();
         $avatars->load(array($id));
     }
     KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
     return self::$_instances[$id];
 }
Example #21
0
function addUser($username, $rnames, $email, $password, $block)
{
    /*
    jimport('joomla.user.helper');
    $salt   = JUserHelper::genRandomPassword(32);
    $crypted  = JUserHelper::getCryptedPassword($password, $salt);
    $cpassword = $crypted.':'.$salt; $data = array( "name"=>$name, "username"=>$username, "password"=>$password,
    "password2"=>$password, "email"=>$email, "block"=>0, "groups"=>array("1","2") );
    $user = new JUser;
    if(!$user->bind($data)) { throw new Exception("Could not bind data. Error: " . $user->getError()); }
    if (!$user->save()) { echo "<br>Could not save user $name - " . $user->getError(); }
    return $user->id;
    */
    $db = JFactory::getDbo();
    jimport('joomla.user.helper');
    $pass = JUserHelper::hashPassword($password);
    $time = time();
    $params = '{"admin_style":"","admin_language":"","language":"","editor":"","helpsite":"","timezone":""}';
    $registerDate = date('Y-m-d H:i:s', $time);
    $n_name = explode(" ", $rnames);
    $username = $n_name[0] . $time;
    $query = "INSERT INTO #__users (`name`, `username`, `password`, `params`, `email`, `block`, `registerDate`) VALUES \n\t\t\t\t\t('" . $rnames . "', '" . $username . "', '" . $pass . "', '" . $params . "', '" . $email . "', '" . $block . "', '" . $registerDate . "')";
    $db->setQuery($query);
    $db->query();
    $last_id = $db->insertid();
    $query = "INSERT INTO #__user_usergroup_map (`user_id`, `group_id`) VALUES ('" . $last_id . "', '2')";
    $db->setQuery($query);
    $db->query();
    return $last_id;
}
Example #22
0
 /**
  * Checks if the current user, or userID passed to function is an administrator
  *
  * @param INT
  */
 public static function isAdmin($userid = NULL, $admin_groups = array("7", "8"), $group_ids_passed = true)
 {
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         // Joomla! 1.6+ code here
         jimport('joomla.user.helper');
         $user = JFactory::getUser($userid);
         $groups = JUserHelper::getUserGroups($user->id);
         //var_dump($admin_groups);
         if ($group_ids_passed) {
             foreach ($groups as $temp) {
                 if (in_array($temp, $admin_groups)) {
                     return true;
                 }
             }
         } else {
             foreach ($admin_groups as $temp) {
                 if (!empty($groups[$temp])) {
                     return true;
                 }
             }
         }
         return false;
     } else {
         // Joomla! 1.5 code here
         jimport('joomla.user.helper');
         $user = JFactory::getUser($userid);
         // Note: in practice I'd use $user->gid here
         if (in_array($user->usertype, array("Super Administrator", "Administrator"))) {
             return true;
         } else {
             return false;
         }
     }
 }
Example #23
0
 /**
  * Returns the global KunenaUserHelper object, only creating it if it doesn't already exist.
  *
  * @access	public
  * @param	int	$id	The user to load - Can be an integer or string - If string, it is converted to ID automatically.
  * @return	JUser			The User object.
  * @since	1.6
  */
 public static function get($identifier = null, $reload = false)
 {
     KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
     if ($identifier === null || $identifier === false) {
         KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
         return self::$_me;
     }
     if ($identifier instanceof KunenaUser) {
         KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
         return $identifier;
     }
     // Find the user id
     if ($identifier instanceof JUser) {
         $id = intval($identifier->id);
     } else {
         if (is_numeric($identifier)) {
             $id = intval($identifier);
         } else {
             jimport('joomla.user.helper');
             $id = intval(JUserHelper::getUserId((string) $identifier));
         }
     }
     // Always return fresh user if id is anonymous/not found
     if ($id === 0) {
         KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
         return new KunenaUser($id);
     } else {
         if ($reload || empty(self::$_instances[$id])) {
             self::$_instances[$id] = new KunenaUser($id);
         }
     }
     KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
     return self::$_instances[$id];
 }
 /**
  * This method will return a user object
  *
  * If options['autoregister'] is true, if the user doesn't exist yet he will be created
  *
  * @param	array	$user		Holds the user data.
  * @param	array	$options	Array holding options (remember, autoregister, group).
  *
  * @return	object	A JUser object
  * @since	1.5
  */
 protected function _getUser($user, $options = array())
 {
     $instance = JUser::getInstance();
     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');
     // Default to Registered.
     $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));
     //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 #25
0
 function display($tpl = NULL)
 {
     /**
      * @var JSite $app
      */
     $app = JFactory::getApplication();
     $this->params = $app->getParams();
     /* Default Page fallback*/
     $active = $app->getMenu()->getActive();
     if (NULL == $active) {
         $this->params->merge($app->getMenu()->getDefault()->params);
         $active = $app->getMenu()->getDefault();
     }
     $this->currentItemid = $active->id;
     $entriesPerPage = $this->params->get('max_events_per_page', 12);
     $model = $this->getModel('events');
     $eventModel = JModelLegacy::getInstance('Event', 'EventgalleryModel');
     $recursive = $this->params->get('show_items_per_category_recursive', false);
     $user = JFactory::getUser();
     $usergroups = JUserHelper::getUserGroups($user->id);
     $entries = $model->getEntries(JRequest::getVar('start', 0), $entriesPerPage, $this->params->get('tags'), $this->params->get('sort_events_by'), $usergroups, $this->params->get('catid', null), $recursive);
     $this->pageNav = $model->getPagination();
     $this->entries = $entries;
     $this->eventModel = $eventModel;
     $this->_prepareDocument();
     parent::display($tpl);
 }
Example #26
0
 public function Authecticate()
 {
     global $dbObj, $common;
     $username = $common->replaceEmpty('username', '');
     $userpassword = $common->replaceEmpty('password', '');
     $result = array();
     if ($action = 'login') {
         $sql_username = "******" . $username . "' and block = '0' ";
         $rs_username = $dbObj->runQuery($sql_username);
         if ($rows_username = mysql_fetch_assoc($rs_username)) {
             $dbpassword = $rows_username['password'];
             if (JUserHelper::verifyPassword($userpassword, $rows_username['password'], $rows_username['id'])) {
                 $datelogged = date('Y-m-d H:i:s');
                 $sqlLog = "INSERT INTO ras_user_visit_log SET userID='" . $rows_username['id'] . "', useFrom = 'Android', dateLogged='" . $datelogged . "'";
                 $dbObj->runQuery($sqlLog);
                 $result[] = $rows_username;
                 echo json_encode(array('status' => '1', $result));
             } else {
                 $result[] = "0";
                 echo json_encode($result);
             }
         } else {
             $result[] = "No Record";
             echo json_encode($result);
         }
     }
     // action close
 }
	function tmpdir()
	{
		static $tmpdir=false;
		if ($tmpdir) return realpath($tmpdir);

		jimport('joomla.filesystem.file');
		jimport('joomla.user.helper');

		$tmp = md5(JUserHelper::genRandomPassword(16));
		$ssp = ini_get('session.save_path');
		$jtp = JPATH_SITE.'/tmp';

		// Try to find a writable directory
		$tmpdir = @is_writable('/tmp') ? '/tmp' : false;
//		$tmpdir = (!$tmpdir && is_writable($ssp)) ? $ssp : false;
		$tmpdir = (!$tmpdir && is_writable($jtp)) ? $jtp : false;

		if (!$tmpdir) {
			$temp=tempnam(JPATH_ROOT . '/tmp','');
			if (file_exists($temp)) {
				unlink($temp);
				$tmpdir = dirname($temp);
			}
		}
		return realpath($tmpdir);
	}
Example #28
0
 /**
  * Validate the elements data against the rule
  *
  * @param   string  $data           to check
  * @param   object  &$elementModel  element Model
  * @param   int     $pluginc        plugin sequence ref
  * @param   int     $repeatCounter  repeat group counter
  *
  * @return  bool  true if validation passes, false if fails
  */
 public function validate($data, &$elementModel, $pluginc, $repeatCounter)
 {
     $params = $this->getParams();
     $pluginc = trim((string) $pluginc);
     // As ornot is a radio button it gets json encoded/decoded as an object
     $ornot = (object) $params->get('userexists_or_not');
     $ornot = isset($ornot->{$pluginc}) ? $ornot->{$pluginc} : 'fail_if_exists';
     $user = JFactory::getUser();
     jimport('joomla.user.helper');
     $result = JUserHelper::getUserId($data);
     if ($user->get('guest')) {
         if (!$result) {
             if ($ornot == 'fail_if_exists') {
                 return true;
             }
         } else {
             if ($ornot == 'fail_if_not_exists') {
                 return true;
             }
         }
         return false;
     } else {
         if (!$result) {
             if ($ornot == 'fail_if_exists') {
                 return true;
             }
         } else {
             $user_field = (array) $params->get('userexists_user_field', array());
             $user_field = $user_field[$pluginc];
             $user_id = 0;
             if ((int) $user_field !== 0) {
                 $user_elementModel = FabrikWorker::getPluginManager()->getElementPlugin($user_field);
                 $user_fullName = $user_elementModel->getFullName(false, true, false);
                 $user_field = $user_elementModel->getFullName(false, false, false);
             }
             if (!empty($user_field)) {
                 // $$$ the array thing needs fixing, for now just grab 0
                 $formdata = $elementModel->getForm()->_formData;
                 $user_id = JArrayHelper::getValue($formdata, $user_fullName . '_raw', JArrayHelper::getValue($formdata, $user_fullName, ''));
                 if (is_array($user_id)) {
                     $user_id = JArrayHelper::getValue($user_id, 0, '');
                 }
             }
             if ($user_id != 0) {
                 if ($result == $user_id) {
                     return $ornot == 'fail_if_exists' ? true : false;
                 }
                 return false;
             } else {
                 // The connected user is editing his own data
                 if ($result == $user->get('id')) {
                     return $ornot == 'fail_if_exists' ? true : false;
                 }
                 return false;
             }
         }
         return false;
     }
 }
Example #29
0
 function display($tpl = null)
 {
     $user = User::getRoot();
     // If this is an auth_link account update, carry on, otherwise raise an error
     if (!is_object($user) || !array_key_exists('auth_link_id', $user) || !is_numeric($user->get('username')) || !$user->get('username') < 0) {
         App::abort('405', 'Method not allowed');
         return;
     }
     // Get and add the js and extra css to the page
     \Hubzero\Document\Assets::addComponentStylesheet('com_users', 'link.css');
     \Hubzero\Document\Assets::addComponentStylesheet('com_users', 'providers.css');
     \Hubzero\Document\Assets::addComponentScript('com_users', 'link');
     // Import a few things
     jimport('joomla.user.helper');
     // Look up a few things
     $hzal = \Hubzero\Auth\Link::find_by_id($user->get("auth_link_id"));
     $hzad = \Hubzero\Auth\Domain::find_by_id($hzal->auth_domain_id);
     $plugins = Plugin::byType('authentication');
     // Get the display name for the current plugin being used
     Plugin::import('authentication', $hzad->authenticator);
     $plugin = Plugin::byType('authentication', $hzad->authenticator);
     $pparams = new \Hubzero\Config\Registry($plugin->params);
     $refl = new ReflectionClass("plgAuthentication{$plugin->name}");
     $display_name = $pparams->get('display_name', $refl->hasMethod('onGetLinkDescription') ? $refl->getMethod('onGetLinkDescription')->invoke(NULL) : ucfirst($plugin->name));
     // Look for conflicts - first check in the hub accounts
     $profile_conflicts = \Hubzero\User\Profile\Helper::find_by_email($hzal->email);
     // Now check the auth_link table
     $link_conflicts = \Hubzero\Auth\Link::find_by_email($hzal->email, array($hzad->id));
     $conflict = array();
     if ($profile_conflicts) {
         foreach ($profile_conflicts as $p) {
             $user_id = JUserHelper::getUserId($p);
             $juser = User::getInstance($user_id);
             $auth_link = \Hubzero\Auth\Link::find_by_user_id($juser->id);
             $dname = is_object($auth_link) && $auth_link->auth_domain_name ? $auth_link->auth_domain_name : 'hubzero';
             $conflict[] = array("auth_domain_name" => $dname, "name" => $juser->name, "email" => $juser->email);
         }
     }
     if ($link_conflicts) {
         foreach ($link_conflicts as $l) {
             $juser = User::getInstance($l['user_id']);
             $conflict[] = array("auth_domain_name" => $l['auth_domain_name'], "name" => $juser->name, "email" => $l['email']);
         }
     }
     // Make sure we don't somehow have any duplicate conflicts
     $conflict = array_map("unserialize", array_unique(array_map("serialize", $conflict)));
     // @TODO: Could also check for high probability of name matches???
     // Get the site name
     $sitename = Config::get('sitename');
     // Assign variables to the view
     $this->assign('hzal', $hzal);
     $this->assign('hzad', $hzad);
     $this->assign('plugins', $plugins);
     $this->assign('display_name', $display_name);
     $this->assign('conflict', $conflict);
     $this->assign('sitename', $sitename);
     $this->assignref('juser', $user);
     parent::display($tpl);
 }
Example #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;
     }
 }