<commit_before><?php
/**
 * HUBzero CMS
 *
 * Copyright 2005-2011 Purdue University. All rights reserved.
 *
 * This file is part of: The HUBzero(R) Platform for Scientific Collaboration
 *
 * The HUBzero(R) Platform for Scientific Collaboration (HUBzero) is free
 * software: you can redistribute it and/or modify it under the terms of
 * the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * HUBzero is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright 2011 Purdue University. All rights reserved.
 * @license   http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

JLoader::import('Hubzero.Api.Controller');

/**
 * API controller for the time component
 */
class RegisterControllerApi extends Hubzero_Api_Controller
{
	/**
	 * Execute!
	 * 
	 * @return void
	 */
	function execute()
	{
		// Import some Joomla libraries
		JLoader::import('joomla.environment.request');
		JLoader::import('joomla.application.component.helper');
		
		$this->logFile = JPATH_ROOT . DS . 'site' . DS . 'com_register' . DS . 'premis_registrations.log';

		// Get the request type
		$this->format = JRequest::getVar('format', 'application/json');

		// Get a database object
		$this->db = JFactory::getDBO();
		
		// Debug mode
		$this->debug = true;

		// Switch based on entity type and action
		switch($this->segments[0])
		{
			// Registration
			case 'premisRegister': 		$this->premisRegister();			break;
			case 'premisUpdateProfile':	$this->premisUpdateProfile();		break;
			case 'premisDeleteProfile':	$this->premisDeleteProfile();		break;

			default:                    $this->method_not_found();         	break;
		}
	}

	/**
	 * Premis registration request handling API
	 * 
	 * @return 	OK on success
	 */
	private function premisRegisterApi()
	{
		$this->setMessageType($this->format);
		
		//get the userid and attempt to load user profile
		$userid = JFactory::getApplication()->getAuthn('user_id');
		$result = Hubzero_User_Profile::getInstance($userid);
		//make sure we have a user
		if ($result === false)	return $this->not_found();
		
	}
	
	/**
	 * Premis registration request handling
	 *
	 * @param		void 
	 * @return 		void
	 */
	private function premisRegister()
	{
		// Get the authentication info		
		if (!$this->premisAuthenticate())
		{
			if ($this->debug)
			{
				$debug = $this->premisError;
				$this->errorMessage(400, 'Unable to authenticate. ' . $debug); 
			}
			return;
		}
		
		// Get the POST data from request
		$user['fName'] = JRequest::getVar('fName', '', 'post');
		$user['lName'] = JRequest::getVar('lName', '', 'post');
		$user['email'] = JRequest::getVar('email', '', 'post');
		$user['casId'] = JRequest::getVar('casId', '', 'post');
		$user['premisId'] = JRequest::getVar('premisId', '', 'post');
		$user['password'] = JRequest::getVar('password', '', 'post');
		$user['premisEnrollmentId'] = JRequest::getVar('premisEnrollmentId', '', 'post');
		
		$courses['add'] = JRequest::getVar('addRegistration', '', 'post');
		$courses['drop'] = JRequest::getVar('dropRegistration', '', 'post');
		
		// Include helper
		require_once(JPATH_ROOT . DS . 'components' . DS . 'com_register' . DS . 'helpers' . DS . 'Premis.php');

		// Handle registration request
		$return = Hubzero_Register_Premis::doRegistration($user, $courses);
		
		// Check request status and display a corresponding message
		if ($return['status'] != 'ok')		
		{
			$this->errorMessage($return['code'], $return['message']);	
		}
		else {
			// Success message
			$this->successMessage($return['code'], $return['message']);	
		}
				
	}
		
	private function premisUpdateProfile()
	{
		// Get the authentication info		
		if (!$this->premisAuthenticate())
		{
			if ($this->debug)
			{
				$debug = $this->premisError;
				$this->errorMessage(400, 'Unable to authenticate. ' . $debug); 
			}
			return;
		}
		
		$user['email'] = JRequest::getVar('email', '', 'post');
		$user['fName'] = JRequest::getVar('fName', '', 'post');
		$user['lName'] = JRequest::getVar('lName', '', 'post');
		$user['password'] = JRequest::getVar('password', '', 'post');
		
		/* Testing
		$user['email'] = '<EMAIL>';
		$user['fName'] = 'Илья';
		$user['lName'] = 'Шунько';
		$user['password'] = ''; //<PASSWORD>
		*/
		
		require_once(JPATH_ROOT . DS . 'components' . DS . 'com_register' . DS . 'helpers' . DS . 'Premis.php');
		$return = Hubzero_Register_Premis::doProfileUpdate($user);			
	}
	
	private function premisDeleteProfile()
	{
		// Get the authentication info		
		if (!$this->premisAuthenticate())
		{
			if ($this->debug)
			{
				$debug = $this->premisError;
				$this->errorMessage(400, 'Unable to authenticate. ' . $debug); 
			}
			return;
		}
		
		$user['email'] = JRequest::getVar('email', '', 'post');<commit_msg>[COM_REGISTER] remove some testing code from comments<commit_after><?php
/**
 * HUBzero CMS
 *
 * Copyright 2005-2011 Purdue University. All rights reserved.
 *
 * This file is part of: The HUBzero(R) Platform for Scientific Collaboration
 *
 * The HUBzero(R) Platform for Scientific Collaboration (HUBzero) is free
 * software: you can redistribute it and/or modify it under the terms of
 * the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * HUBzero is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright 2011 Purdue University. All rights reserved.
 * @license   http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

JLoader::import('Hubzero.Api.Controller');

/**
 * API controller for the time component
 */
class RegisterControllerApi extends Hubzero_Api_Controller
{
	/**
	 * Execute!
	 * 
	 * @return void
	 */
	function execute()
	{
		// Import some Joomla libraries
		JLoader::import('joomla.environment.request');
		JLoader::import('joomla.application.component.helper');
		
		$this->logFile = JPATH_ROOT . DS . 'site' . DS . 'com_register' . DS . 'premis_registrations.log';

		// Get the request type
		$this->format = JRequest::getVar('format', 'application/json');

		// Get a database object
		$this->db = JFactory::getDBO();
		
		// Debug mode
		$this->debug = true;

		// Switch based on entity type and action
		switch($this->segments[0])
		{
			// Registration
			case 'premisRegister': 		$this->premisRegister();			break;
			case 'premisUpdateProfile':	$this->premisUpdateProfile();		break;
			case 'premisDeleteProfile':	$this->premisDeleteProfile();		break;

			default:                    $this->method_not_found();         	break;
		}
	}

	/**
	 * Premis registration request handling API
	 * 
	 * @return 	OK on success
	 */
	private function premisRegisterApi()
	{
		$this->setMessageType($this->format);
		
		//get the userid and attempt to load user profile
		$userid = JFactory::getApplication()->getAuthn('user_id');
		$result = Hubzero_User_Profile::getInstance($userid);
		//make sure we have a user
		if ($result === false)	return $this->not_found();
		
	}
	
	/**
	 * Premis registration request handling
	 *
	 * @param		void 
	 * @return 		void
	 */
	private function premisRegister()
	{
		// Get the authentication info		
		if (!$this->premisAuthenticate())
		{
			if ($this->debug)
			{
				$debug = $this->premisError;
				$this->errorMessage(400, 'Unable to authenticate. ' . $debug); 
			}
			return;
		}
		
		// Get the POST data from request
		$user['fName'] = JRequest::getVar('fName', '', 'post');
		$user['lName'] = JRequest::getVar('lName', '', 'post');
		$user['email'] = JRequest::getVar('email', '', 'post');
		$user['casId'] = JRequest::getVar('casId', '', 'post');
		$user['premisId'] = JRequest::getVar('premisId', '', 'post');
		$user['password'] = JRequest::getVar('password', '', 'post');
		$user['premisEnrollmentId'] = JRequest::getVar('premisEnrollmentId', '', 'post');
		
		$courses['add'] = JRequest::getVar('addRegistration', '', 'post');
		$courses['drop'] = JRequest::getVar('dropRegistration', '', 'post');
		
		// Include helper
		require_once(JPATH_ROOT . DS . 'components' . DS . 'com_register' . DS . 'helpers' . DS . 'Premis.php');

		// Handle registration request
		$return = Hubzero_Register_Premis::doRegistration($user, $courses);
		
		// Check request status and display a corresponding message
		if ($return['status'] != 'ok')		
		{
			$this->errorMessage($return['code'], $return['message']);	
		}
		else {
			// Success message
			$this->successMessage($return['code'], $return['message']);	
		}
				
	}
		
	private function premisUpdateProfile()
	{
		// Get the authentication info		
		if (!$this->premisAuthenticate())
		{
			if ($this->debug)
			{
				$debug = $this->premisError;
				$this->errorMessage(400, 'Unable to authenticate. ' . $debug); 
			}
			return;
		}
		
		$user['email'] = JRequest::getVar('email', '', 'post');
		$user['fName'] = JRequest::getVar('fName', '', 'post');
		$user['lName'] = JRequest::getVar('lName', '', 'post');
		$user['password'] = JRequest::getVar('password', '', 'post');
		
		require_once(JPATH_ROOT . DS . 'components' . DS . 'com_register' . DS . 'helpers' . DS . 'Premis.php');
		$return = Hubzero_Register_Premis::doProfileUpdate($user);			
	}
	
	private function premisDeleteProfile()
	{
		// Get the authentication info		
		if (!$this->premisAuthenticate())
		{
			if ($this->debug)
			{
				$debug = $this->premisError;
				$this->errorMessage(400, 'Unable to authenticate. ' . $debug); 
			}
			return;
		}
		
		$user['email'] = JRequest::getVar('email', '', 'post');
{'fraction_non_alphanumeric': 0.16208584337349397, 'fraction_numerical': 0.004894578313253012, 'mean_word_length': 3.6764964788732395, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6529838', 'n_tokens_mistral': 3804, 'n_tokens_neox': 3315, 'n_words': 864}