Beispiel #1
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>";
     }
 }
 /**
  * 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;
 }
Beispiel #3
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;
 }
Beispiel #4
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);
     }
 }
Beispiel #5
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;
 }
Beispiel #6
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;
 }
	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);
	}
Beispiel #8
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);
 }
Beispiel #9
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;
 }
Beispiel #10
0
 /**
  * Manupulates posted form data for insertion into database
  *
  * @param   mixed  $val   this elements posted form data
  * @param   array  $data  posted form data
  *
  * @return  mixed
  */
 public function storeDatabaseFormat($val, $data)
 {
     jimport('joomla.user.helper');
     $salt = JUserHelper::genRandomPassword(32);
     $crypt = JUserHelper::getCryptedPassword($val, $salt);
     $val = $crypt . ':' . $salt;
     return $val;
 }
Beispiel #11
0
 function hashPassword($password)
 {
     require_once JPATH_BASE . '/includes/defines.php';
     require_once JPATH_LIBRARIES . '/joomla/user/helper.php';
     $salt = JUserHelper::genRandomPassword(32);
     $crypt = JUserHelper::getCryptedPassword($password, $salt);
     return "{$crypt}:{$salt}";
 }
Beispiel #12
0
 /**
  * Automatically sets the activation token for the user.
  *
  * @return LibUsersDomainEntityUser
  */
 public function requiresActivation()
 {
     jimport('joomla.user.helper');
     $token = JUtility::getHash(JUserHelper::genRandomPassword());
     $salt = JUserHelper::getSalt();
     $hashedToken = sha1($token . $salt) . ':' . $salt;
     $this->activation = $hashedToken;
     return $this;
 }
Beispiel #13
0
 public static function get_format_departure_code($tsmart_departure_id, $day)
 {
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('departure.tsmart_departure_id')->from('#__tsmart_departure AS departure')->where('departure.tsmart_departure_id=' . (int) $tsmart_departure_id)->innerJoin('#__tsmart_products AS product ON product.tsmart_product_id=departure.tsmart_product_id')->innerJoin('#__tsmart_products_en_gb AS products_en_gb ON products_en_gb.tsmart_product_id=product.tsmart_product_id')->select('products_en_gb.product_name AS product_name')->innerJoin('#__tsmart_service_class AS service_class ON service_class.tsmart_service_class_id=departure.tsmart_service_class_id')->select('service_class.service_class_name');
     $db->setQuery($query);
     $departure_item = $db->loadObject();
     $departure_code = strtoupper(substr($departure_item->product_name, 0, 2) . substr($departure_item->service_class_name, 0, 2) . "SD" . JUserHelper::genRandomPassword(2) . $day->format('dm-y'));
     return $departure_code;
 }
 public static function generatePassword($text, $is_cripted = false)
 {
     $password = $text;
     if ($is_cripted == false) {
         return $password;
     }
     jimport('joomla.user.helper');
     $salt = JUserHelper::genRandomPassword(8);
     $crypt = JUserHelper::getCryptedPassword($password, $salt);
     $password = $crypt . ":" . $salt;
     return $password;
 }
Beispiel #15
0
 /**
  * Function post for create user record.
  *
  * @return void
  */
 public function post()
 {
     $error_messages = array();
     $fieldname = array();
     $response = null;
     $validated = true;
     $userid = null;
     $data = array();
     $app = JFactory::getApplication();
     $data['username'] = $app->input->get('username', '', 'STRING');
     $data['password'] = $app->input->get('password', '', 'STRING');
     $data['name'] = $app->input->get('name', '', 'STRING');
     $data['email'] = $app->input->get('email', '', 'STRING');
     global $message;
     jimport('joomla.user.helper');
     $authorize = JFactory::getACL();
     $user = clone JFactory::getUser();
     $user->set('username', $data['username']);
     $user->set('password', $data['password']);
     $user->set('name', $data['name']);
     $user->set('email', $data['email']);
     // Password encryption
     $salt = JUserHelper::genRandomPassword(32);
     $crypt = JUserHelper::getCryptedPassword($user->password, $salt);
     $user->password = "******";
     // User group/type
     $user->set('id', '');
     $user->set('usertype', 'Registered');
     if (JVERSION >= '1.6.0') {
         $userConfig = JComponentHelper::getParams('com_users');
         // Default to Registered.
         $defaultUserGroup = $userConfig->get('new_usertype', 2);
         $user->set('groups', array($defaultUserGroup));
     } else {
         $user->set('gid', $authorize->get_group_id('', 'Registered', 'ARO'));
     }
     $date =& JFactory::getDate();
     $user->set('registerDate', $date->toSql());
     // True on success, false otherwise
     if (!$user->save()) {
         $message = "not created because of " . $user->getError();
         return false;
     } else {
         $message = "created of username-" . $user->username . " and send mail of details please check";
     }
     // #$this->plugin->setResponse($user->id);
     $userid = $user->id;
     // Result message
     $result = array('user id ' => $userid, 'message' => $message);
     $result = $userid ? $result : $message;
     $this->plugin->setResponse($result);
 }
Beispiel #16
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;
 }
 public function activate($token)
 {
     $config = JFactory::getConfig();
     $userParams = $this->getUserParams();
     JPluginHelper::importPlugin('user');
     $userId = $this->getUserId($token);
     if (!$userId) {
         $this->setError(JText::_('COM_USERS_ACTIVATION_TOKEN_NOT_FOUND'));
         return false;
     }
     $user = JFactory::getUser($userId);
     $usermail = JSFactory::getModel('usermailactivation', 'jshop');
     $uri = JURI::getInstance();
     $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
     $data = $user->getProperties();
     $data['fromname'] = $config->get('fromname');
     $data['mailfrom'] = $config->get('mailfrom');
     $data['sitename'] = $config->get('sitename');
     $data['siteurl'] = JUri::base();
     // Admin activation is on and user is verifying their email
     if ($userParams->get('useractivation') == 2 && !$user->getParam('activate', 0)) {
         $data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword());
         $data['activate'] = $base . JRoute::_('index.php?option=com_jshopping&controller=user&task=activate&token=' . $data['activation'], false);
         $user->set('activation', $data['activation']);
         $user->setParam('activate', 1);
         $usermail->setData($data);
         if (!$usermail->sendToAdmin()) {
             $this->setError($usermail->getError());
             return false;
         }
     } elseif ($userParams->get('useractivation') == 2 && $user->getParam('activate', 0)) {
         $user->set('activation', '');
         $user->set('block', '0');
         $user->setParam('activate', 0);
         $usermail->setData($data);
         if (!$usermail->send()) {
             $this->setError($usermail->getError());
             return false;
         }
     } else {
         $user->set('activation', '');
         $user->set('block', '0');
     }
     if (!$user->save()) {
         $this->setError(JText::sprintf('COM_USERS_REGISTRATION_ACTIVATION_SAVE_FAILED', $user->getError()));
         $user = false;
     }
     JDispatcher::getInstance()->trigger('onAfterUserActivate', array(&$this, &$token, &$user));
     return $user;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->target_dir = $input->getOption('base');
     $this->app = Bootstrapper::getApplication($this->target_dir);
     if (!$input->hasOption('pass')) {
         require_once JPATH_BASE . '/libraries/joomla/user/helper.php';
         $pass = \JUserHelper::genRandomPassword(14);
     } else {
         $pass = $input->getOption('pass');
     }
     $this->groups = $this->getGroups();
     $group = $this->groups[$input->getOption('group')];
     $this->userParams = (object) array('name' => $input->getOption('name'), 'user' => $input->getOption('user'), 'pass' => $pass, 'email' => $input->getOption('email'), 'group' => $group->id);
 }
Beispiel #19
0
 /**
  * Generate token here to standardize the token generation
  * @condition if the user_id is provided it will be assign to the user directly
  * @see assignToken()
  * @return String generated token
  */
 public function generateToken($user_id = null)
 {
     $salt = JUserHelper::genRandomPassword(50);
     $crypt = JUserHelper::getCryptedPassword($user_id, $salt);
     $token = $crypt . ':' . $salt;
     if ($user_id != NULL) {
         if ($this->assignToken($user_id, $token)) {
             return true;
         } else {
             return false;
         }
     } else {
         return $token;
     }
 }
 /**
  * If the user is trying to access the custom admin folder set the necessary cookies and redirect them to the
  * administrator page.
  */
 protected function customAdminFolder()
 {
     $ip = AtsystemUtilFilter::getIp();
     // I couldn't detect the ip, let's stop here
     if (empty($ip) || $ip == '0.0.0.0') {
         return;
     }
     // Some user agents don't set a UA string at all
     if (!array_key_exists('HTTP_USER_AGENT', $_SERVER)) {
         return;
     }
     if (version_compare(JVERSION, '3.2.0', 'ge')) {
         $ua = $this->app->client;
         $uaString = $ua->userAgent;
         $browserVersion = $ua->browserVersion;
     } else {
         JLoader::import('joomla.environment.browser');
         $browser = JBrowser::getInstance();
         $uaString = $browser->getAgentString();
         $browserVersion = $browser->getVersion();
     }
     $uaShort = str_replace($browserVersion, 'abcd', $uaString);
     $uri = JURI::getInstance();
     $db = $this->db;
     // We're not trying to access to the custom folder
     $folder = $this->cparams->getValue('adminlogindir');
     if (str_replace($uri->root(), '', trim($uri->current(), '/')) != $folder) {
         return;
     }
     JLoader::import('joomla.user.helper');
     if (version_compare(JVERSION, '3.2.1', 'ge')) {
         $hash = JUserHelper::hashPassword($ip . $uaShort);
     } else {
         $hash = md5($ip . $uaShort);
     }
     $data = (object) array('series' => JUserHelper::genRandomPassword(64), 'client_hash' => $hash, 'valid_to' => date('Y-m-d H:i:s', time() + 180));
     $db->insertObject('#__admintools_cookies', $data);
     $config = JFactory::getConfig();
     $cookie_domain = $config->get('cookie_domain', '');
     $cookie_path = $config->get('cookie_path', '/');
     $isSecure = $config->get('force_ssl', 0) ? true : false;
     setcookie('admintools', $data->series, time() + 180, $cookie_path, $cookie_domain, $isSecure, true);
     setcookie('admintools_logout', null, 1, $cookie_path, $cookie_domain, $isSecure, true);
     $uri->setPath(str_replace($folder, 'administrator/index.php', $uri->getPath()));
     $this->app->redirect($uri->toString());
 }
Beispiel #21
0
 /**
  * Takes the new password and saves it to the database.
  * It will only save the password if the user has the
  * correct user id and token stored in her session.
  *
  * @since	1.5
  * @param	string	New Password
  * @param	string	New Password
  * @return	bool	True on success/false on failure
  */
 function completeReset($password1, $password2)
 {
     jimport('joomla.user.helper');
     global $mainframe;
     // Make sure that we have a pasword
     if (!$password1) {
         $this->setError(JText::_('MUST_SUPPLY_PASSWORD'));
         return false;
     }
     // Verify that the passwords match
     if ($password1 != $password2) {
         $this->setError(JText::_('PASSWORDS_DO_NOT_MATCH_LOW'));
         return false;
     }
     // Get the necessary variables
     $db =& JFactory::getDBO();
     $id = $mainframe->getUserState($this->_namespace . 'id');
     $token = $mainframe->getUserState($this->_namespace . 'token');
     $salt = JUserHelper::genRandomPassword(32);
     $crypt = JUserHelper::getCryptedPassword($password1, $salt);
     $password = $crypt . ':' . $salt;
     // Get the user object
     $user = new JUser($id);
     // Fire the onBeforeStoreUser trigger
     JPluginHelper::importPlugin('user');
     $dispatcher =& JDispatcher::getInstance();
     $dispatcher->trigger('onBeforeStoreUser', array($user->getProperties(), false));
     // Build the query
     $query = 'UPDATE #__users' . ' SET password = '******' , activation = ""' . ' WHERE id = ' . (int) $id . ' AND activation = ' . $db->Quote($token) . ' AND block = 0';
     $db->setQuery($query);
     // Save the password
     if (!($result = $db->query())) {
         $this->setError(JText::_('DATABASE_ERROR'));
         return false;
     }
     // Update the user object with the new values.
     $user->password = $password;
     $user->activation = '';
     $user->password_clear = $password1;
     // Fire the onAfterStoreUser trigger
     $dispatcher->trigger('onAfterStoreUser', array($user->getProperties(), false, $result, $this->getError()));
     // Flush the variables from the session
     $mainframe->setUserState($this->_namespace . 'id', null);
     $mainframe->setUserState($this->_namespace . 'token', null);
     return true;
 }
Beispiel #22
0
 public function addUser($values, $source = 'subscribe')
 {
     $userComponent = 'com_users';
     $config = EB::config();
     $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['name'];
     $mainframe = JFactory::getApplication();
     $jConfig = EasyBlogHelper::getJConfig();
     $authorize = JFactory::getACL();
     $document = JFactory::getDocument();
     $user = clone JFactory::getUser();
     $pwdClear = $username . '123';
     $newUsertype = $usersConfig->get('new_usertype', 2);
     $userArr = array('username' => $username, 'name' => $fullname, 'email' => $email, 'password' => $pwdClear, 'password2' => $pwdClear, 'groups' => array($newUsertype), 'gid' => '0', 'id' => '0');
     if (!$user->bind($userArr, 'usertype')) {
         return $user->getError();
     }
     $date = EB::date();
     $user->set('registerDate', $date->toSql());
     //check if user require to activate the acct
     $useractivation = $usersConfig->get('useractivation');
     if ($useractivation == '1' || $useractivation == '2') {
         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');
     // Get the user id.
     $userId = $user->id;
     $this->sendMail($user, $password);
     return $userId;
 }
Beispiel #23
0
 public function doEmailVerificationAndBlocking()
 {
     $task = $this->input->getCmd('task');
     if ($task == 'activate') {
         $activationKey = $this->input->get('activation', null, 'raw');
         if (is_null($activationKey)) {
             $activationKey = $this->input->get('token', null, 'raw');
         }
         $user_id = $this->getUserId($activationKey);
     } else {
         // Code for temporary user id
         $mySess = JFactory::getSession();
         $tmpUser = $mySess->get('tmpUser', 0, 'default');
         $user_id = $tmpUser->id;
     }
     //invalid request, joomla will handle it
     if (!$user_id) {
         return;
     }
     // do we need approval
     if ($this->isApprovalRequired($user_id) == false) {
         return;
     }
     // --- mark & block the user
     $user = JUser::getInstance($user_id);
     $user->setParam(self::PARAM_EMAIL_VERIFIED, '1');
     $user->set('block', '1');
     jimport('joomla.user.helper');
     // Work for both Joomla 3 and Joomla 2.5 series
     $newActivationKey = JVERSION >= '3.0' ? JApplication::getHash(JUserHelper::genRandomPassword()) : JUtility::getHash(JUserHelper::genRandomPassword());
     //$newActivationKey=JUtility::getHash( JUserHelper::genRandomPassword());
     // generate new activation
     // save new activation key by which our admin can enable user
     $user->set('activation', $newActivationKey);
     //$this->activation =  $newActivationKey;
     if (!$user->save()) {
         // JError::raiseWarning('', JText::_( $user->getError()));
         $this->app->redirect('index.php', JText::_('PLG_XIAA_USER_SAVE_ERROR'));
     }
     // send an email to admin  with a ativation link and profile of user.
     $this->sendMessage($user_id, self::MESSAGE_APPROVAL);
     // show message to user
     // XITODO : redirect to given menu page
     $this->app->redirect('index.php', JText::_('PLG_XIAA_USER_EMAIL_VERIFIED_AND_ADMIN_WILL_APPROVE_YOUR_ACCOUNT'));
 }
Beispiel #24
0
 /**
  * Function to encrypt user pro password
  *
  * @access	public static
  * @param	$id - id of the event
  * @return	list array of access levels, approval and event access status
  *
  * @since	3.4.0
  */
 public static function encryptPassword()
 {
     $params = JComponentHelper::getParams('com_icagenda');
     $icsys = $params->get('icsys', 'core');
     if ($icsys == 'pro') {
         jimport('joomla.user.helper');
         $crypt1 = JUserHelper::genRandomPassword(2);
         $crypt2 = JUserHelper::genRandomPassword(2);
         $salt_8 = JUserHelper::genRandomPassword(8);
         $salt_16 = JUserHelper::genRandomPassword(16);
         $salt_32 = JUserHelper::genRandomPassword(32);
         $password = $params->get('password', '');
         $is_crypted = substr_count($password, '$');
         if ($is_crypted != 3 && strlen($password) != 0) {
             $encoded = base64_encode($password);
             if (strlen($encoded) > 32) {
                 $salt1 = $salt_16;
                 $salt2 = $salt_8;
             } elseif (strlen($encoded) < 32 && strlen($encoded) > 16) {
                 $salt1 = $salt_16;
                 $salt2 = $salt_8;
             } else {
                 $salt1 = $salt_32;
                 $salt2 = $salt_16;
             }
             $pass_encoded = '$' . $crypt1 . '$' . $crypt2 . '$' . $salt1 . '.' . $encoded . '/' . $salt2;
             //				$_pass = str_replace('/', '.', $pass_encoded);
             //				$pass_ex = explode('.', $_pass);
             //				$decoded = base64_decode($encoded);
             $password = $pass_encoded;
             // Get the params and set the new values
             $params->set('password', $password);
             // Get a new database query instance
             $db = JFactory::getDBO();
             $query = $db->getQuery(true);
             // Build the query
             $query->update('#__extensions AS a');
             $query->set('a.params = ' . $db->quote((string) $params));
             $query->where('a.element = "com_icagenda"');
             // Execute the query
             $db->setQuery($query);
             $db->query();
         }
     }
 }
Beispiel #25
0
 public function import()
 {
     $this->start = $this->state->get('start', 0);
     $sugarTableConnection = new mysqli(".", "root", "2bornot2b", "admin_mem99");
     if (!$sugarTableConnection) {
         $this->error = 'could not connect to db.';
     }
     $sql = ' SELECT c.*,cc.*, ea.email_address FROM admin_mem99.s4kpe_coach c ' . ' LEFT JOIN admin_mem99.s4kpe_coach_cstm cc on cc.id_c = c.id ' . ' LEFT JOIN admin_mem99.email_addr_bean_rel eabr  on eabr.bean_id = c.id and bean_module = "s4kpe_coach" ' . ' LEFT JOIN admin_mem99.email_addresses ea on ea.id = eabr.email_address_id ' . ' LIMIT ' . $this->start . ',200';
     $resource = mysqli_query($sugarTableConnection, $sql);
     if ($resource->num_rows > 0) {
         $this->start = $this->start + $resource->num_rows;
         while ($row = $resource->fetch_object()) {
             $coachTable = new Sp4kTablesBase('#__sp4k_coach_items');
             $coach = new stdClass();
             $coach->created = strtotime($row->date_entered);
             $coach->state = !$row->deleted;
             $coach->status = '';
             $coach->title = $row->salutation;
             $coach->name = $row->first_name . ' ' . $row->last_name;
             $coach->phone = $row->phone_mobile;
             $coach->driving = $row->driving_c;
             $coach->city = $row->city_c;
             $coach->kitholder = $row->kitholder_c;
             $coach->role = $row->coachinglevel_c;
             $coach->reserve = $row->subsbench_c;
             $coach->dotw1 = $row->monday_c;
             $coach->dotw2 = 0;
             $coach->dotw3 = 0;
             $coach->dotw4 = 0;
             $coach->dotw5 = 0;
             $coach->dotw6 = $row->saturday_c;
             $coach->dotw7 = $row->sunday_c;
             $coach->sugar_coach_id = $row->id;
             if (isset($row->email_address) && $row->email_address != '' && trim($row->first_name . ' ' . $row->last_name) != '' && !JUserHelper::getUserId(strtolower($row->email_address))) {
                 $coach->juser_id = $this->addJoomlaUser(strtolower($row->email_address), trim($row->first_name . ' ' . $row->last_name), strtolower($row->email_address), JUserHelper::genRandomPassword());
             } else {
                 $coach->juser_id = 0;
             }
             $coachTable->save($coach);
         }
     } else {
         $this->continue = false;
     }
 }
Beispiel #26
0
 /**
  * before creating the person node, create the user object.
  *
  * @return bool
  */
 protected function _beforeEntityInsert(KCommandContext $context)
 {
     $viewer = get_viewer();
     $firstUser = !(bool) $this->getService('repos://site/users')->getQuery(true)->fetchValue('id');
     jimport('joomla.user.helper');
     $user = clone JFactory::getUser();
     $user->set('id', 0);
     $user->set('name', $this->name);
     $user->set('username', $this->username);
     $user->set('email', $this->email);
     if (!$this->getPassword()) {
         $this->setPassword(JUserHelper::genRandomPassword(32));
     }
     if ($this->getPassword()) {
         $user->set('password', $this->getPassword(true));
         $user->set('password_clear', $this->getPassword());
     }
     $date =& JFactory::getDate();
     $user->set('registerDate', $date->toMySQL());
     $user->set('lastvisitDate', '0000-00-00 00:00:00');
     // if this is the first user being added or
     // (viewer is a super admin and she is adding another super admin)
     if ($firstUser || $viewer->superadmin() && $this->userType == ComPeopleDomainEntityPerson::USERTYPE_SUPER_ADMINISTRATOR) {
         $user->set('usertype', ComPeopleDomainEntityPerson::USERTYPE_SUPER_ADMINISTRATOR);
     } elseif ($viewer->admin() && $this->userType == ComPeopleDomainEntityPerson::USERTYPE_ADMINISTRATOR) {
         $user->set('usertype', ComPeopleDomainEntityPerson::USERTYPE_ADMINISTRATOR);
     } else {
         $user->set('usertype', ComPeopleDomainEntityPerson::USERTYPE_REGISTERED);
     }
     //create an activation token
     //@todo we need a global token generator to handle creation and destruction of tokens
     $user->set('activation', JUtility::getHash(JUserHelper::genRandomPassword()));
     $user->set('block', '1');
     if (!$user->save()) {
         throw new RuntimeException('Unexpected error when saving user');
         return false;
     }
     $this->userId = $user->id;
     $this->userType = $user->usertype;
     $this->enabled = $user->block ? 0 : 1;
     return true;
 }
Beispiel #27
0
 public function import()
 {
     $this->start = $this->state->get('start', 0);
     $sugarTableConnection = new mysqli(".", "root", "2bornot2b", "admin_mem99");
     if (!$sugarTableConnection) {
         $this->error = 'could not connect to db.';
     }
     $selectSugarParentsTableSql = ' SELECT p.*,emails.email_address ' . ' FROM admin_mem99.s4kpe_parent AS p  ' . ' LEFT JOIN `email_addr_bean_rel` eabr on eabr.bean_module = "s4kpe_parent" and eabr.bean_id = p.id and primary_address = 1 ' . ' LEFT JOIN `email_addresses` emails on emails.id = eabr.email_address_id and eabr.deleted = 0 ' . ' group by p.id ' . ' LIMIT ' . $this->start . ',200';
     $resource = mysqli_query($sugarTableConnection, $selectSugarParentsTableSql);
     if ($resource->num_rows > 0) {
         $this->start = $this->start + $resource->num_rows;
         while ($row = $resource->fetch_assoc()) {
             $newParent['created'] = strtotime($row['date_entered']);
             $newParent['createdby_sugar_id'] = $row['created_by'];
             $newParent['status'] = !$row['deleted'];
             $newParent['f_name'] = $row['first_name'];
             $newParent['l_name'] = $row['last_name'];
             $newParent['phone_home'] = $row['phone_home'];
             $newParent['phone_work'] = $row['phone_work'];
             $newParent['phone_mobile'] = $row['phone_mobile'];
             $newParent['address_street1'] = $row['primary_address_street'];
             $newParent['address_street2'] = '';
             $newParent['address_city'] = $row['primary_address_city'];
             $newParent['address_state'] = $row['primary_address_state'];
             $newParent['address_postalcode'] = $row['primary_address_postalcode'];
             $newParent['address_country'] = $row['primary_address_country'];
             $newParent['whmcs_id'] = $row['whmcs_id'];
             $newParent['sms'] = (int) $row['receive_sms'];
             $newParent['sugar_id'] = $row['id'];
             if (isset($row['email_address']) && $row['email_address'] != '' && trim($row['first_name'] . ' ' . $row['last_name']) != '' && !JUserHelper::getUserId($row['email_address'])) {
                 $newParent['juser_id'] = $this->addJoomlaUser(strtolower($row['email_address']), $row['first_name'] . ' ' . $row['last_name'], strtolower($row['email_address']), JUserHelper::genRandomPassword());
             } else {
                 $newParent['juser_id'] = 0;
             }
             $parentTable = new Sp4kTablesBase('#__sp4k_parent_items');
             $parentTable->save($newParent);
         }
     } else {
         $this->continue = false;
     }
 }
Beispiel #28
0
 public function update()
 {
     if (!isset($this->item->account_id)) {
         $account = Sp4kAppsAccountApp::getInstance(new Registry(['created' => time()]))->getItem()->update();
         $this->item->account_id = $account->id;
     }
     if ($this->item->juser_id == null || $this->item->juser_id == 0) {
         if (isset($this->item->email) && $this->item->email != '' && trim($this->item->f_name . ' ' . $this->item->l_name) != '' && !JUserHelper::getUserId($this->item->email)) {
             $this->item->juser_id = $this->addJoomlaUser(strtolower($this->item->email), $this->item->f_name . ' ' . $this->item->l_name, strtolower($this->item->email), JUserHelper::genRandomPassword());
         } else {
             $this->item->juser_id = 0;
         }
     }
     if ($this->state->get('children', false)) {
         foreach ($this->state->get('children') as $child) {
             $childAppItem = Sp4kAppsChildApp::getInstance(new Registry($child))->getItem();
             $childAppItem->account_id = $account->id;
             $childAppItem->update();
         }
     }
     $this->item->update();
 }
 /**
  * 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
  */
 public function createUser(&$params, $output)
 {
     require_once JPATH_BASE . '/libraries/joomla/user/helper.php';
     require_once JPATH_BASE . '/libraries/joomla/user/user.php';
     require_once JPATH_BASE . '/libraries/cms/component/helper.php';
     $salt = \JUserHelper::genRandomPassword(32);
     $password_clear = $params->pass;
     $crypted = \JUserHelper::getCryptedPassword($password_clear, $salt);
     $password = $crypted . ':' . $salt;
     $instance = \JUser::getInstance();
     $instance->set('id', 0);
     $instance->set('name', $params->name);
     $instance->set('username', $params->user);
     $instance->set('password', $password);
     $instance->set('password_clear', $password_clear);
     $instance->set('email', $params->email);
     $instance->set('groups', array($params->group));
     $instance->set('block', 0);
     if (!$instance->save()) {
         // Return exception for instance
     } else {
         $output->writeln("Your Joomla user has been created. You can login using the credentials {$params->user} / {$password_clear}");
     }
 }
Beispiel #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;
     }
 }