/components/com_jfusionplugins/mantis/user.php
PHP | 231 lines | 134 code | 34 blank | 63 comment | 18 complexity | 2b9ad341467622d25ef27ebe471b6925 MD5 | raw file
Possible License(s): Apache-2.0
- <?php
- /**
- * @package JFusion_mantis
- * @version 1.0.7
- * @author JFusion development team
- * @copyright Copyright (C) 2008 JFusion. All rights reserved.
- * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
- */
-
- // no direct access
- defined('_JEXEC' ) or die('Restricted access' );
-
- /**
- * load the JFusion framework
- */
- require_once(JPATH_ADMINISTRATOR .DS.'components'.DS.'com_jfusion'.DS.'models'.DS.'model.abstractuser.php');
- require_once(JPATH_ADMINISTRATOR .DS.'components'.DS.'com_jfusion'.DS.'models'.DS.'model.jplugin.php');
-
- /**
- * JFusion plugin class for mantis
- * @package JFusion_mantis
- */
- class JFusionUser_mantis extends JFusionUser {
-
- function &getUser($userinfo)
- {
- // get the username
- if (is_object($userinfo)){
- $username = $userinfo->username;
- } else {
- $username = $userinfo;
- }
- // initialise some objects
- $params = JFusionFactory::getParams($this->getJname());
- $db = JFusionFactory::getDatabase($this->getJname());
-
- $query = 'SELECT id as userid,username, realname as name, email, password, enabled FROM #__user_table WHERE username='. $db->Quote($username);
- $db->setQuery($query );
- $result = $db->loadObject();
-
-
-
-
- $result->activation = 0;
- $result->block = 0;
-
- return $result;
- }
-
- function getJname()
- {
- return 'mantis';
- }
-
- function deleteUser($userinfo)
- {
- //setup status array to hold debug info and errors
- $status = array();
- $status['debug'] = array();
- $status['error'] = array();
-
- $db = JFusionFactory::getDatabase($this->getJname());
-
- $query = 'DELETE FROM #__user_table WHERE username = '.$db->quote($userinfo->username);
- $db->setQuery($query);
- if (!$db->query()) {
- $status['error'][] = JText::_('USER_DELETION_ERROR') . ' ' . $db->stderr();
- } else {
- $status['error'] = false;
- $status['debug'][] = JText::_('USER_DELETION'). ' ' . $userinfo->username;
- }
- return $status;
- }
-
- function destroySession($userinfo, $options){
- // $params = JFusionFactory::getParams($this->getJname());
- // setcookie($params->get('cookie_name'), '',0,$params->get('cookie_path'),$params->get('cookie_domain'),$params->get('secure'),$params->get('httponly'));
- return JFusionJplugin::destroySession($userinfo, $options,$this->getJname());
- }
-
- function createSession($userinfo, $options) {
- /*
- // initialise some objects
- $params = JFusionFactory::getParams($this->getJname());
- $db = JFusionFactory::getDatabase($this->getJname());
-
- $cookie_expires = $params->get('cookie_expires');
- if ($cookie_expires) {
- $expires = 60*60*24*365;
- } else {
- $expires = 60 * $cookie_expires;
- }
- $expires = $expires+time();
- $query = 'SELECT cookie_string FROM #__user_table WHERE username='.$db->Quote($userinfo->username);
- $db->setQuery($query);
- $result = $db->loadObject();
- setcookie($params->get('cookie_name'), $result->cookie_string ,$expires,$params->get('cookie_path'),$params->get('cookie_domain'),$params->get('secure'),$params->get('httponly'));
- */
- return JFusionJplugin::createSession($userinfo, $options,$this->getJname());
- }
-
- function filterUsername($username) {
- //no username filtering implemented yet
- return $username;
- }
-
- function updatePassword($userinfo, &$existinguser, &$status)
- {
- if (isset($userinfo->password_clear)) {
- $existinguser->password = md5( $userinfo->password_clear );
- } else {
- $existinguser->password = $userinfo->password;
- }
- $db = JFusionFactory::getDatabase($this->getJname());
- $query = 'UPDATE #__user_table SET password = ' . $db->quote($existinguser->password). ' WHERE id = ' . $existinguser->userid;
- $db = JFusionFactory::getDatabase($this->getJname());
- $db->setQuery($query );
- if (!$db->query()) {
- $status['error'][] = JText::_('PASSWORD_UPDATE_ERROR') . $db->stderr();
- } else {
- $status['debug'][] = JText::_('PASSWORD_UPDATE') . ' ' . substr($existinguser->password,0,6) . '********';
- }
- }
-
- function updateEmail($userinfo, &$existinguser, &$status)
- {
- //we need to update the email
- $db = JFusionFactory::getDatabase($this->getJname());
- $query = 'UPDATE #__user_table SET email = ' . $db->quote($userinfo->email) . ' WHERE id = ' . $existinguser->userid;
- $db->setQuery($query);
- if (!$db->query()) {
- $status['error'][] = JText::_('EMAIL_UPDATE_ERROR') . $db->stderr();
- } else {
- $status['debug'][] = JText::_('EMAIL_UPDATE'). ': ' . $existinguser->email . ' -> ' . $userinfo->email;
- }
- }
-
- function createUser($userinfo, &$status)
- {
- //we need to create a new SMF user
- $db = JFusionFactory::getDatabase($this->getJname());
- $params = JFusionFactory::getParams($this->getJname());
- $source_path = $params->get('source_path');
-
- //prepare the user variables
- $user = new stdClass;
- $user->id = NULL;
- $user->username = $userinfo->username;
- $user->realname = $userinfo->name;
- $user->email = $userinfo->email;
- $user->date_created = $user->last_visit = date('Y-m-t H:i:s',time());
-
- if (isset($userinfo->password_clear)) {
- $user->password = md5( $userinfo->password_clear );
- } else {
- $user->password = $userinfo->password;
- }
-
- $t_seed = $user->email . $user->username;
- $user->cookie_string = JFusionUser_mantis::auth_generate_unique_cookie_string( $t_seed );
-
- if ($userinfo->activation) {
- $user->enabled = 0;
- } else {
- $user->enabled = 1;
- }
-
- $user->access_level = $params->get('usergroup', 10);
-
- //now append the new user data
- if (!$db->insertObject('#__user_table', $user, 'id' )) {
- //return the error
- $status['error'] = JText::_('USER_CREATION_ERROR'). ': ' . $db->stderr();
- return $status;
- } else {
- //return the good news
- $status['debug'][] = JText::_('USER_CREATION');
- $status['userinfo'] = $this->getUser($userinfo->username);
- return $status;
- }
- }
-
- /**
- * Generate a string to use as the identifier for the login cookie
- * It is not guaranteed to be unique and should be checked
- * The string returned should be 64 characters in length
- * @return string 64 character cookie string
- * @access public
- */
- function auth_generate_cookie_string() {
- $t_val = mt_rand( 0, mt_getrandmax() ) + mt_rand( 0, mt_getrandmax() );
- $t_val = md5( $t_val ) . md5( time() );
-
- return substr( $t_val, 0, 64 );
- }
-
- /**
- * Generate a UNIQUE string to use as the identifier for the login cookie
- * The string returned should be 64 characters in length
- * @return string 64 character cookie string
- * @access public
- */
- function auth_generate_unique_cookie_string() {
- do {
- $t_cookie_string = $this->auth_generate_cookie_string();
- }
- while( !$this->auth_is_cookie_string_unique( $t_cookie_string ) );
-
- return $t_cookie_string;
- }
-
- /**
- * Return true if the cookie login identifier is unique, false otherwise
- * @param string $p_cookie_string
- * @return bool indicating whether cookie string is unique
- * @access public
- */
- function auth_is_cookie_string_unique( $p_cookie_string ) {
- $db = JFusionFactory::getDatabase($this->getJname());
-
- $query = 'SELECT count(*) from #__user_table WHERE cookie_string='.$p_cookie_string;
- $db->setQuery($query );
-
- if( $db->loadResult() > 0 ) {
- return false;
- } else {
- return true;
- }
- }
- }
-