<commit_before><?php

require_once 'Swat/SwatUI.php';
require_once 'Site/pages/SitePage.php';

/**
 * Page for logging into an account
 *
 * @package   Site
 * @copyright 2006-2011 silverorange
 * @license   http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
 * @see       SiteAccount
 */
class SiteAccountLoginPage extends SitePage
{
	// {{{ protected properties

	/**
	 * @var string
	 */
	protected $ui_xml = 'Site/pages/account-login.xml';

	protected $ui;

	/**
	 * @var string
	 */
	protected $relocate_uri = 'account';

	// }}}

	// init phase
	// {{{ public function init()

	public function init()
	{
		parent::init();

		$this->ui = new SwatUI();
		$this->ui->loadFromXML($this->ui_xml);

		$login_form = $this->ui->getWidget('login_form');
		$login_form->action = $this->source;

		$create_form = $this->ui->getWidget('create_account_form');
		$create_form->action = 'account/edit';

		$this->initRelocateUri($login_form);
		$this->loggedInRelocate();

		$this->ui->init();
	}

	// }}}
	// {{{ protected function initRelocateUri()

	protected function initRelocateUri(SwatForm $form)
	{
		$relocate_uri = null;

		$get_uri = SiteApplication::initVar('relocate', null,
			SiteApplication::VAR_GET);

		// only use relative URIs
		if (!preg_match('#^(?:[a-zA-Z]+:)?//#', $get_uri))
			$relocate_uri = $get_uri;

		if ($relocate_uri === null)
			$relocate_uri = $form->getHiddenField('relocate_uri');

		if ($relocate_uri !== null)
			$this->relocate_uri = $relocate_uri;

		$form->addHiddenField('relocate_uri', $this->relocate_uri);
	}

	// }}}
	// {{{ protected function loggedInRelocate()

	protected function loggedInRelocate()
	{
		// go to details page if already logged in
		if ($this->app->session->isLoggedIn())
			$this->app->relocate($this->relocate_uri);
	}

	// }}}

	// process phase
	// {{{ public function process()

	public function process()
	{
		parent::process();

		$form = $this->ui->getWidget('login_form');

		$form->process();

		if ($form->isProcessed() && !$form->hasMessage()) {
			$email = $this->ui->getWidget('email_address')->value;
			$password = $this->ui->getWidget('password')->value;

			if ($this->app->session->login($email, $password)) {
				$this->postLoginProcess();
				$this->app->relocate($this->relocate_uri);
			} else {
				$message = new SwatMessage(Site::_('Login Incorrect'),
					SwatMessage::WARNING);

				$message->secondary_content = sprintf(
					'<ul><li>%s</li><li>%s</li></ul>',
					Site::_('Please check the spelling on your email '.
						'address or password.'),
					sprintf(Site::_('Password is case-sensitive. Make sure '.
						'your %sCaps Lock%s key is off.'),
						'<kbd>', '</kbd>'));

				$message->content_type = 'text/xml';
				$this->ui->getWidget('message_display')->add($message);
			}
		}
	}
<commit_msg>Remove use of deprecated constant.<commit_after><?php

require_once 'Swat/SwatUI.php';
require_once 'Site/pages/SitePage.php';

/**
 * Page for logging into an account
 *
 * @package   Site
 * @copyright 2006-2011 silverorange
 * @license   http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
 * @see       SiteAccount
 */
class SiteAccountLoginPage extends SitePage
{
	// {{{ protected properties

	/**
	 * @var string
	 */
	protected $ui_xml = 'Site/pages/account-login.xml';

	protected $ui;

	/**
	 * @var string
	 */
	protected $relocate_uri = 'account';

	// }}}

	// init phase
	// {{{ public function init()

	public function init()
	{
		parent::init();

		$this->ui = new SwatUI();
		$this->ui->loadFromXML($this->ui_xml);

		$login_form = $this->ui->getWidget('login_form');
		$login_form->action = $this->source;

		$create_form = $this->ui->getWidget('create_account_form');
		$create_form->action = 'account/edit';

		$this->initRelocateUri($login_form);
		$this->loggedInRelocate();

		$this->ui->init();
	}

	// }}}
	// {{{ protected function initRelocateUri()

	protected function initRelocateUri(SwatForm $form)
	{
		$relocate_uri = null;

		$get_uri = SiteApplication::initVar('relocate', null,
			SiteApplication::VAR_GET);

		// only use relative URIs
		if (!preg_match('#^(?:[a-zA-Z]+:)?//#', $get_uri))
			$relocate_uri = $get_uri;

		if ($relocate_uri === null)
			$relocate_uri = $form->getHiddenField('relocate_uri');

		if ($relocate_uri !== null)
			$this->relocate_uri = $relocate_uri;

		$form->addHiddenField('relocate_uri', $this->relocate_uri);
	}

	// }}}
	// {{{ protected function loggedInRelocate()

	protected function loggedInRelocate()
	{
		// go to details page if already logged in
		if ($this->app->session->isLoggedIn())
			$this->app->relocate($this->relocate_uri);
	}

	// }}}

	// process phase
	// {{{ public function process()

	public function process()
	{
		parent::process();

		$form = $this->ui->getWidget('login_form');

		$form->process();

		if ($form->isProcessed() && !$form->hasMessage()) {
			$email = $this->ui->getWidget('email_address')->value;
			$password = $this->ui->getWidget('password')->value;

			if ($this->app->session->login($email, $password)) {
				$this->postLoginProcess();
				$this->app->relocate($this->relocate_uri);
			} else {
				$message = new SwatMessage(
					Site::_('Login Incorrect'),
					'warning'
				);

				$message->secondary_content = sprintf(
					'<ul><li>%s</li><li>%s</li></ul>',
					Site::_(
						'Please check the spelling on your email '.
						'address or password.'
					),
					sprintf(
						Site::_(
							'Password is case-sensitive. Make sure '.
							'your %sCaps Lock%s key is off.'
						),
						'<kbd>',
						'</kbd>'
					)
				);

				$message->content_type = 'text/xml';
				$this->ui->getWidget('message_display')->add($message);
			}
		}
	}

{'fraction_non_alphanumeric': 0.19270098730606489, 'fraction_numerical': 0.003526093088857546, 'mean_word_length': 3.560289389067524, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, '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': '2958230', 'n_tokens_mistral': 2281, 'n_tokens_neox': 1942, 'n_words': 358}