//Service : forgotpassword
$config	= JFactory::getConfig();
$post = JRequest::get ('post');  
global $HTTP_RAW_POST_DATA;
 
$post = json_decode($HTTP_RAW_POST_DATA, true);    

//$post['email_id'] = "vishal@harmistechnology.com";


		$query = 'Select id from #__users where email="'.$post["email_id"].'"';
		$db->setQuery($query);
		$userId = $db->loadResult();
		if (empty($userId)) {
			$arr = array('success' => 0, 'message' => "Invalid Email Address" ); 
 			echo json_encode($arr);exit;
		}
		$user = JUser::getInstance($userId);
		 
		if ($user->block) {
			$arr = array('success' => 0, 'message' => "User is Blocked" ); 
 			echo json_encode($arr);exit;
		}
		
		$token = JApplication::getHash(JUserHelper::genRandomPassword());
		$salt = JUserHelper::getSalt('crypt-md5');
		$hashedToken = md5($token.$salt).':'.$salt;

		$user->activation = $hashedToken;
		
		if (!$user->save(true)) {
			$arr = array('success' => 0, 'message' => "Faild Reset Request" ); 
 			echo json_encode($arr);exit;
		}
		
		 
		$link = 'index.php?option=com_users&view=reset&layout=confirm';
		
		$data = array();
		
		$data['fromname']	= $config->get('fromname');
		$data['mailfrom']	= $config->get('mailfrom');
		$data['sitename']	= $config->get('sitename');
		$data['link_text']	= JRoute::_($link, true, '-1');
		
		$data['token']		= $token;
		 
		$subject = 'Your Wild Discovery password reset request';
		
		$bodymessage = 'Hello,<br /><br />A request has been made to reset your Wild Discovery account password. To reset your
						password, you will need to submit this verification code in order to verify that the
						request was legitimate.<br /><br />
						The verification code is '.$data['token'].'<br /><br />
						Click on the URL below to enter the verification code and proceed with resetting
						your password.<br /><br />
						'.$data['link_text'].'<br /><br />
						Thank you.';
						
		$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $user->email, $subject, $bodymessage,true);
		// Check for an error.
		if ($return !== true) {
			$arr = array('success' => 0, 'message' => "Mail Sending Is Falid" ); 
 			echo json_encode($arr);exit;
		}else{
			$arr = array('success' => 1, 'message' => "An email has been sent to your email address for Password Reset" ); 
 			echo json_encode($arr);exit;
		}
		exit;