<commit_before><?php

/*
 * Copyright (c) 2013, Flaming Code
 * 
 */

namespace FlamingUser\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\Form\FormInterface;

use FlamingUser\Service\UserService;
use FlamingBase\Stdlib\StringTool;

/**
 * AuthController
 *
 * @author <NAME> <<EMAIL>>
 * @copyright (c) 2013, Flaming Code
 * @link http://github.com/FlamingCode/FlamingUser for the canonical source repository
 * @license http://opensource.org/licenses/GPL-2.0 GPL-2.0
 */
class AuthController extends AbstractActionController
{
	/**
	 *
	 * @var UserService
	 */
	protected $userService;

	/**
	 *
	 * @var FormInterface
	 */
	protected $loginForm;

	/**
	 *
	 * @var FormInterface
	 */
	protected $forgotPasswordForm;

	/**
	 *
	 * @var FormInterface
	 */
	protected $changePasswordForm;

	protected $successRoute;

	protected $failureRoute;

	protected $logoutRoute;

	protected $failedLoginMessage;

	/**
	 * Login form
	 */
	public function loginAction()
	{
		$request = $this->getRequest();
		$form = $this->getLoginForm();

		if (!$request->isPost()) {
			return array(
				'form' => $form,
				'query' => $this->params()->fromQuery()
			);
		}

		$form->setData($request->getPost());

		if (!$form->isValid()) {
			$this->flashMessenger()->addErrorMessage($this->getFailedLoginMessage());
			return $this->redirect()->toRoute($this->getFailureRoute(), array(), array('query' => $this->params()->fromQuery()));
		}

		return $this->authenticateAction();
	}

	/**
	 * Logout and clear the identity
	 */
	public function logoutAction()
	{
		$this->getUserService()->logout();
		
		if ($url = $this->params()->fromQuery('r', false))
			return $this->redirect()->toUrl($url);

		return $this->redirect()->toRoute($this->getLogoutRoute());
	}

	/**
	 * General-purpose authentication action
	 */
	public function authenticateAction()
	{
		$request = $this->getRequest();
		if ($this->authentication()->hasIdentity())
			return $this->redirect()->toRoute($this->getSuccessRoute());
		else if (!$request->isPost())
			return $this->redirect()->toRoute($this->getFailureRoute());

		$data = $request->getPost();
		if (!$this->getUserService()->login($data['email'], $data['password'],
		    (bool) $data['remember_me'])) {
			$this->flashMessenger()->addErrorMessage($this->getFailedLoginMessage());
			return $this->redirect()->toRoute($this->getFailureRoute());
		}
		
		if ($url = $this->params()->fromQuery('r', false))
			return $this->redirect()->toUrl($url);

		return $this->redirect()->toRoute($this->getSuccessRoute());
	}
<commit_msg>Fixed error where if not post request to authenticate action would not carry over query params when redirecting to login action<commit_after><?php

/*
 * Copyright (c) 2013, Flaming Code
 * 
 */

namespace FlamingUser\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\Form\FormInterface;

use FlamingUser\Service\UserService;
use FlamingBase\Stdlib\StringTool;

/**
 * AuthController
 *
 * @author <NAME> <<EMAIL>>
 * @copyright (c) 2013, Flaming Code
 * @link http://github.com/FlamingCode/FlamingUser for the canonical source repository
 * @license http://opensource.org/licenses/GPL-2.0 GPL-2.0
 */
class AuthController extends AbstractActionController
{
	/**
	 *
	 * @var UserService
	 */
	protected $userService;

	/**
	 *
	 * @var FormInterface
	 */
	protected $loginForm;

	/**
	 *
	 * @var FormInterface
	 */
	protected $forgotPasswordForm;

	/**
	 *
	 * @var FormInterface
	 */
	protected $changePasswordForm;

	protected $successRoute;

	protected $failureRoute;

	protected $logoutRoute;

	protected $failedLoginMessage;

	/**
	 * Login form
	 */
	public function loginAction()
	{
		$request = $this->getRequest();
		$form = $this->getLoginForm();

		if (!$request->isPost()) {
			return array(
				'form' => $form,
				'query' => $this->params()->fromQuery()
			);
		}

		$form->setData($request->getPost());

		if (!$form->isValid()) {
			$this->flashMessenger()->addErrorMessage($this->getFailedLoginMessage());
			return $this->redirect()->toRoute($this->getFailureRoute(), array(), array('query' => $this->params()->fromQuery()));
		}

		return $this->authenticateAction();
	}

	/**
	 * Logout and clear the identity
	 */
	public function logoutAction()
	{
		$this->getUserService()->logout();
		
		if ($url = $this->params()->fromQuery('r', false))
			return $this->redirect()->toUrl($url);

		return $this->redirect()->toRoute($this->getLogoutRoute());
	}

	/**
	 * General-purpose authentication action
	 */
	public function authenticateAction()
	{
		$request = $this->getRequest();
		if ($this->authentication()->hasIdentity())
			return $this->redirect()->toRoute($this->getSuccessRoute());
		else if (!$request->isPost())
			return $this->redirect()->toRoute($this->getFailureRoute(), array(), array('query' => $this->params()->fromQuery()));

		$data = $request->getPost();
		if (!$this->getUserService()->login($data['email'], $data['password'],
		    (bool) $data['remember_me'])) {
			$this->flashMessenger()->addErrorMessage($this->getFailedLoginMessage());
			return $this->redirect()->toRoute($this->getFailureRoute(), array(), array('query' => $this->params()->fromQuery()));
		}
		
		if ($url = $this->params()->fromQuery('r', false))
			return $this->redirect()->toUrl($url);

		return $this->redirect()->toRoute($this->getSuccessRoute());
	}

{'fraction_non_alphanumeric': 0.19157659336563548, 'fraction_numerical': 0.004472605292582929, 'mean_word_length': 4.415741675075681, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 125, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4220618', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1620, 'n_words': 312}