<commit_before><?php

/**
 * This file helps the administrator setting registration settings and policy
 * as well as allow the administrator to register new members themselves.
 *
 * @name      ElkArte Forum
 * @copyright ElkArte Forum contributors
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
 *
 * This file contains code covered by:
 * copyright:	2011 Simple Machines (http://www.simplemachines.org)
 * license:		BSD, See included LICENSE.TXT for terms and conditions.
 *
 * @version 1.1 beta 4
 *
 */

use ElkArte\Errors\ErrorContext;

/**
 * ManageRegistration admin controller: handles the registration pages
 *
 * - allow admins (or moderators with moderate_forum permission)
 * to register a new member,
 * - to see and edit the registration agreement,
 * - to set up reserved words for forum names.
 *
 * @package Registration
 */
class ManageRegistration_Controller extends Action_Controller
{
	/**
	 * Entrance point for the registration center, it checks permissions and forwards
	 * to the right method based on the subaction.
	 *
	 * - Accessed by ?action=admin;area=regcenter.
	 * - Requires either the moderate_forum or the admin_forum permission.
	 *
	 * @uses Login language file
	 * @uses Register template.
	 * @see Action_Controller::action_index()
	 */
	public function action_index()
	{
		global $context, $txt;

		// Loading, always loading.
		loadLanguage('Login');
		loadTemplate('Register');
		loadJavascriptFile('register.js');

		$subActions = array(
			'register' => array(
				'controller' => $this,
				'function' => 'action_register',
				'permission' => 'moderate_forum',
			),
			'agreement' => array(
				'controller' => $this,
				'function' => 'action_agreement',
				'permission' => 'admin_forum',
			),
			'reservednames' => array(
				'controller' => $this,
				'function' => 'action_reservednames',
				'permission' => 'admin_forum',
			),
			'settings' => array(
				'controller' => $this,
				'function' => 'action_registerSettings_display',
				'permission' => 'admin_forum',
			),
		);

		// Action controller
		$action = new Action('manage_registrations');

		// Next create the tabs for the template.
		$context[$context['admin_menu_name']]['tab_data'] = array(
			'title' => $txt['registration_center'],
			'help' => 'registrations',
			'description' => $txt['admin_settings_desc'],
			'tabs' => array(
				'register' => array(
					'description' => $txt['admin_register_desc'],
				),
				'agreement' => array(
					'description' => $txt['registration_agreement_desc'],
				),
				'reservednames' => array(
					'description' => $txt['admin_reserved_desc'],
				),
				'settings' => array(
					'description' => $txt['admin_settings_desc'],
				)
			)
		);

		// Work out which to call... call integrate_sa_manage_registrations
		$subAction = $action->initialize($subActions, 'register');

		// Final bits
		$context['page_title'] = $txt['maintain_title'];
		$context['sub_action'] = $subAction;

		// Call the right function for this sub-action.
		$action->dispatch($subAction);
	}

	/**
	 * This function allows the admin to register a new member by hand.
	 *
	 * - It also allows assigning a primary group to the member being registered.
	 * - Accessed by ?action=admin;area=regcenter;sa=register
	 * - Requires the moderate_forum permission.
	 *
	 * @uses Register template, admin_register sub-template.
	 */
	public function action_register()
	{
		global $txt, $context, $scripturl, $user_info;

		if (!empty($this->_req->post->regSubmit))
		{
			checkSession();
			validateToken('admin-regc');

			// @todo move this to a filter/sanitation class
			foreach ($this->_req->post as $key => $value)
				if (!is_array($value))
					$this->_req->post[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $value));

			// Generate a password
			if (empty($this->_req->post->password) || !is_string($this->_req->post->password) || trim($this->_req->post->password) === '')
			{
				require_once(SUBSDIR . '/Auth.subs.php');
				mt_srand(time() + 1277);
				$password = generateValidationCode();
			}
			else
			{
				$password = $this->_req->post->password;
			}

			$regOptions = array(
				'interface' => 'admin',
				'username' => $this->_req->post->user,
				'email' => $this->_req->post->email,
				'password' => <PASSWORD>,
				'password_check' => $password,
				'check_reserved_name' => true,
				'check_password_strength' => true,<commit_msg>! left over from old days<commit_after><?php

/**
 * This file helps the administrator setting registration settings and policy
 * as well as allow the administrator to register new members themselves.
 *
 * @name      ElkArte Forum
 * @copyright ElkArte Forum contributors
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
 *
 * This file contains code covered by:
 * copyright:	2011 Simple Machines (http://www.simplemachines.org)
 * license:		BSD, See included LICENSE.TXT for terms and conditions.
 *
 * @version 1.1 beta 4
 *
 */

use ElkArte\Errors\ErrorContext;

/**
 * ManageRegistration admin controller: handles the registration pages
 *
 * - allow admins (or moderators with moderate_forum permission)
 * to register a new member,
 * - to see and edit the registration agreement,
 * - to set up reserved words for forum names.
 *
 * @package Registration
 */
class ManageRegistration_Controller extends Action_Controller
{
	/**
	 * Entrance point for the registration center, it checks permissions and forwards
	 * to the right method based on the subaction.
	 *
	 * - Accessed by ?action=admin;area=regcenter.
	 * - Requires either the moderate_forum or the admin_forum permission.
	 *
	 * @uses Login language file
	 * @uses Register template.
	 * @see Action_Controller::action_index()
	 */
	public function action_index()
	{
		global $context, $txt;

		// Loading, always loading.
		loadLanguage('Login');
		loadTemplate('Register');
		loadJavascriptFile('register.js');

		$subActions = array(
			'register' => array(
				'controller' => $this,
				'function' => 'action_register',
				'permission' => 'moderate_forum',
			),
			'agreement' => array(
				'controller' => $this,
				'function' => 'action_agreement',
				'permission' => 'admin_forum',
			),
			'reservednames' => array(
				'controller' => $this,
				'function' => 'action_reservednames',
				'permission' => 'admin_forum',
			),
			'settings' => array(
				'controller' => $this,
				'function' => 'action_registerSettings_display',
				'permission' => 'admin_forum',
			),
		);

		// Action controller
		$action = new Action('manage_registrations');

		// Next create the tabs for the template.
		$context[$context['admin_menu_name']]['tab_data'] = array(
			'title' => $txt['registration_center'],
			'help' => 'registrations',
			'description' => $txt['admin_settings_desc'],
			'tabs' => array(
				'register' => array(
					'description' => $txt['admin_register_desc'],
				),
				'agreement' => array(
					'description' => $txt['registration_agreement_desc'],
				),
				'reservednames' => array(
					'description' => $txt['admin_reserved_desc'],
				),
				'settings' => array(
					'description' => $txt['admin_settings_desc'],
				)
			)
		);

		// Work out which to call... call integrate_sa_manage_registrations
		$subAction = $action->initialize($subActions, 'register');

		// Final bits
		$context['page_title'] = $txt['maintain_title'];
		$context['sub_action'] = $subAction;

		// Call the right function for this sub-action.
		$action->dispatch($subAction);
	}

	/**
	 * This function allows the admin to register a new member by hand.
	 *
	 * - It also allows assigning a primary group to the member being registered.
	 * - Accessed by ?action=admin;area=regcenter;sa=register
	 * - Requires the moderate_forum permission.
	 *
	 * @uses Register template, admin_register sub-template.
	 */
	public function action_register()
	{
		global $txt, $context, $scripturl, $user_info;

		if (!empty($this->_req->post->regSubmit))
		{
			checkSession();
			validateToken('admin-regc');

			// @todo move this to a filter/sanitation class
			foreach ($this->_req->post as $key => $value)
				if (!is_array($value))
					$this->_req->post[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $value));

			// Generate a password
			if (empty($this->_req->post->password) || !is_string($this->_req->post->password) || trim($this->_req->post->password) === '')
			{
				require_once(SUBSDIR . '/Auth.subs.php');
				$password = generateValidationCode();
			}
			else
			{
				$password = $this->_req->post->password;
			}

			$regOptions = array(
				'interface' => 'admin',
				'username' => $this->_req->post->user,
				'email' => $this->_req->post->email,
				'password' => <PASSWORD>,
				'password_check' => <PASSWORD>,
				'check_reserved_name' => true,
				'check_password_strength' => true,
{'fraction_non_alphanumeric': 0.1511996378451788, 'fraction_numerical': 0.0022634676324128564, 'mean_word_length': 3.7080447522642515, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 132, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3099609', 'n_tokens_mistral': 3140, 'n_tokens_neox': 2641, 'n_words': 688}