本文整理汇总了PHP中JUserHelper类的典型用法代码示例。如果您正苦于以下问题:PHP JUserHelper类的具体用法?PHP JUserHelper怎么用?PHP JUserHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JUserHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLogin
/** 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;
}
}
示例2: createCoupon
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);
}
示例3: createUser
/**
* 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;
}
示例4: onUserAfterLogin
/**
* 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;
}
示例5: getInstance
/**
* 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];
}
示例6: action
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);
}
}
示例7: ajaxSaveRow
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>";
}
}
示例8: authenticate
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=' . $db->q($username)));
$result = $db->loadObject();
$parts = explode(':', $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;
}
示例9: _owner
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;
}
示例10: generateToken
/**
* 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;
}
示例11: display
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);
}
示例12: tmpdir
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);
}
示例13: Authecticate
public function Authecticate()
{
global $dbObj, $common;
$username = $common->replaceEmpty('username', '');
$userpassword = $common->replaceEmpty('password', '');
$result = array();
if ($action = 'login') {
$sql_username = "SELECT * from ras_users where 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
}
示例14: isAdmin
/**
* 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;
}
示例15: createNewUser
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;
}
}