<?php
/**
 * @package    VP Advanced User
 * @author     Abhishek Das <info@virtueplanet.com>
 * @copyright  Copyright (C) 2012-2019 VirtuePlanet Services LLP. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 * @link       https://www.virtueplanet.com
 */

defined('_JEXEC') or die;

/**
 * Authenticate view class.
 *
 * @since  1.0
 */
class VPAdvancedUserViewAuthenticate extends JViewLegacy
{
	protected $params;
	
	protected $myparams;

	protected $state;

	protected $user;
	
	protected $success;
	
	protected $message;
	
	protected $errors;
	
	protected $reload;
	
	/**
	 * Method to display the view.
	 *
	 * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
	 *
	 * @return  mixed  A string if successful, otherwise a Error object.
	 *
	 * @since   1.5
	 */
	public function display($tpl = null)
	{
		// Get the view data.
		$this->user     = JFactory::getUser();
		$this->config   = $this->get('HybridConfig');
		$this->state    = $this->get('State');
		$this->params   = $this->state->get('params');
		$this->myparams = $this->state->get('myparams');
		$this->success  = $this->state->get('status');
		$this->message  = $this->state->get('message');
		$this->reload   = $this->state->get('reload');
		$this->errors   = $this->get('Errors');
		
		foreach($this->errors as $key => &$error)
		{
			if($error == $this->message)
			{
				unset($this->errors[$key]);
				break;
			}
		}

		if(!in_array($this->success, array(true, false), true))
		{
			throw new Exception(JText::_('JGLOBAL_AUTH_ACCESS_DENIED'), 403);
		}
		
		JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
		
		$this->prepareDocument();

		parent::display($tpl);
	}

	/**
	 * Prepares the document
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	protected function prepareDocument()
	{
		$this->document->setTitle(JText::_('COM_VPADVANCEDUSER_AUTHENTICATION_ENDPOINT'));
		$this->document->setMetadata('robots', 'NOINDEX, NOFOLLOW, NOARCHIVE, NOSNIPPET');
	}
}
