<commit_before><?php

namespace Core\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

use Zend\Authentication\AuthenticationService;
use Zend\Authentication\Result;

use Core\Model\User;
use Core\Model\UsersTable;

class AuthController extends AbstractActionController
{
	public function registerAction()
	{
		// Fetch the authentication service
		$auth = new AuthenticationService();

		// Check if the user is logged in
		if ($auth->hasIdentity()) {
			$this->flashMessenger()->addSuccessMessage("You are logged in!");
			return $this->redirect()->toRoute('home');
		}

		// Create the form
		$form = new \Core\Form\RegistrationForm();
		$form->setAttribute('action', $this->url()->fromRoute('register'));
		
		// Process POST requests
		$request = $this->getRequest();

        if ($request->isPost()) {
			// Setup the form data and input filter
			$form->setData($request->getPost());
			$form->setInputFilter(
				new \Core\Form\RegistrationFilter($this->getServiceLocator())
			);

			// Check if the form is valid
			if ($form->isValid()) {
				// Get the data from the form
				$data = $form->getData();

				// Create the password salt
				$data['password_salt'] = '';
				
				for ($i = 0; $i < 32; $i++) {
					$data['password_salt'] .= chr(rand(33, 126));
				}

				// Encrypt the password
				$data['password'] = md5($data['password'] . $data['password_salt']);

				// Create the user
				$user = new User();
				$user->exchangeArray($data);

				// Add the user to the database
				$usersTable = $this->getServiceLocator()->get('Core\Model\UsersTable');
				$usersTable->saveUser($user);

				// Update the user and redirect
				$this->flashMessenger()->addSuccessMessage("Registered");

				return $this->redirect()->toRoute('login');
			}
		}

		// Display the form
		$view = new ViewModel(array(
			'form' => $form
		));
		
		$view->setTemplate('auth/register');<commit_msg>Fixed Registration<commit_after><?php

namespace Core\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

use Zend\Authentication\AuthenticationService;
use Zend\Authentication\Result;

use Core\Model\User;
use Core\Model\UsersTable;

class AuthController extends AbstractActionController
{
	public function registerAction()
	{
		// Fetch the authentication service
		$auth = new AuthenticationService();

		// Check if the user is logged in
		if ($auth->hasIdentity()) {
			$this->flashMessenger()->addSuccessMessage("You are logged in!");
			return $this->redirect()->toRoute('home');
		}

		// Create the form
		$form = new \Core\Form\RegistrationForm();
		$form->setAttribute('action', $this->url()->fromRoute('register'));
		
		// Process POST requests
		$request = $this->getRequest();

        if ($request->isPost()) {
			// Setup the form data and input filter
			$form->setData($request->getPost());
			$form->setInputFilter(
				new \Core\Form\RegistrationFilter($this->getServiceLocator())
			);

			// Check if the form is valid
			if ($form->isValid()) {
				// Get the data from the form
				$data = $form->getData();

				// Create the password salt
				$data['password_salt'] = '';
				
				for ($i = 0; $i < 32; $i++) {
					$data['password_salt'] .= chr(rand(33, 126));
				}

				// Encrypt the password
				$data['password'] = md5($data['password'] . $data['password_salt']);
				
				// Set the default usergroup
				$data['usergroup'] = 2;  // Registered Users

				// Create the user
				$user = new User();
				$user->exchangeArray($data);

				// Add the user to the database
				$usersTable = $this->getServiceLocator()->get('Core\Model\UsersTable');
				$usersTable->saveUser($user);

				// Update the user and redirect
				$this->flashMessenger()->addSuccessMessage("You have successfully registered!");

				return $this->redirect()->toRoute('login');
			}
		}

		// Display the form
		$view = new ViewModel(array(
			'form' => $form
		));
		
		$view->setTemplate('auth/register');
{'fraction_non_alphanumeric': 0.1632040050062578, 'fraction_numerical': 0.004755944931163955, 'mean_word_length': 3.4798206278026904, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 55, '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': '5312879', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1160, 'n_words': 289}