<commit_before><?php
/**
 * ownCloud - registration
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright <NAME> 2014
 */

namespace OCA\Registration\Controller;


use \OCP\IRequest;
use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Controller;

class RegistrationController extends Controller {

	public function __construct($appName, IRequest $request){
		parent::__construct($appName, $request);
	}

	/**
	 * @NoAdminRequired
	 * @NoCSRFRequired
	 * @PublicPage
	 */
	public function displayRegisterPage() {
		$params = array(
			'errormsg' => $this->request->getParam('errormsg'),
			'entered' => $this->request->getParam('entered')
		);
		return new TemplateResponse('registration', 'register', $params);
	}
}<commit_msg>Copy over the old sendEmail controller<commit_after><?php
/**
 * ownCloud - registration
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright <NAME> 2014
 */

namespace OCA\Registration\Controller;


use \OCP\IRequest;
use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Controller;

class RegistrationController extends Controller {

	public function __construct($appName, IRequest $request){
		parent::__construct($appName, $request);
	}

	/**
	 * @NoAdminRequired
	 * @NoCSRFRequired
	 * @PublicPage
	 */
	public function displayRegisterPage($errormsg, $entered) {
		$params = array(
			'errormsg' => $errormsg ? $errormsg : $this->request->getParam('errormsg'),
			'entered' => $entered ? $entered : $this->request->getParam('entered')
		);
		return new TemplateResponse('registration', 'register', $params);
	}

	/**
	 * @NoAdminRequired
	 * @NoCSRFRequired
	 * @PublicPage
	 */
	public function sendEmail() {
		// TODO: Check if user with this email already exists

		if ( !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
			$this->displayRegisterPage($l->t('Email address you entered is not valid'), true);
			return;
		}

		// FEATURE: allow only from specific email domain

		$token = self::savePendingRegistration($_POST['email']);
		if ( $token === false ) {
			$this->displayRegisterPage($l->t('There is already a pending registration with this email'), true);
		} elseif ( strlen($token) === 64 ) {
			$link = OC_Helper::linkToRoute('core_registration_register_form',
				array('token' => $token));
			$link = OC_Helper::makeURLAbsolute($link);
			$from = OCP\Util::getDefaultEmailAddress('register');
			$tmpl = new OC_Template('core/registration', 'email');
			$tmpl->assign('link', $link, false);
			$msg = $tmpl->fetchPage();
			try {
				OC_Mail::send($_POST['email'], 'ownCloud User', $l->t('Verify your ownCloud registration request'), $msg, $from, 'ownCloud');
			} catch (Exception $e) {
				OC_Template::printErrorPage( 'A problem occurs during sending the e-mail please contact your administrator.');
				return;
			}
			$this->displayRegisterPage('', true);
		}
	}
{'fraction_non_alphanumeric': 0.15017956252040482, 'fraction_numerical': 0.0039177277179236044, 'mean_word_length': 4.581056466302368, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 32, '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': '6596982', 'n_tokens_mistral': 1025, 'n_tokens_neox': 917, 'n_words': 235}