<commit_before><?php

use Difra\Ajaxer;
use Difra\Libs\Cookies;
use Difra\Locales;
use Difra\Param\AjaxCheckbox;
use Difra\Param\AjaxString;
use Difra\Param\AnyString;
use Difra\Plugins\Users;
use Difra\Param;
use Difra\Plugins\Users\Register;
use Difra\Plugins\Users\UsersException;
use Difra\View;

/**
 * Class RegisterController
 */
class RegisterController extends Difra\Controller
{
    /**
     * Registration form (page)
     */
    public function indexAction()
    {
        $this->root->appendChild($this->xml->createElement('register'));
    }

    /**
     * Authorized user (already registered)
     */
    public function indexActionAuth()
    {
        // TODO: log
        View::redirect('/');
    }

    /**
     * Registration form (ajax)
     */
    public function indexAjaxAction()
    {
        $this->root->appendChild($this->xml->createElement('register'));
        Ajaxer::display(\Difra\View::render($this->xml, 'auth-ajax', true));
    }

    /**
     * Authorized user (error)
     */
    public function indexAjaxActionAuth()
    {
        // TODO: message
        Ajaxer::reload();
        // TODO: log
    }

    /**
     * Registration form submit (registration page version)
     * @param AjaxCheckbox $accept
     * @param AjaxCheckbox $redirect
     * @param AjaxString|null $email
     * @param AjaxString|null $password1
     * @param AjaxString|null $password2
     * @param AjaxString|null $login
     * @param AjaxString|null $capcha
     * @throws Exception
     */
    public function submitAjaxAction(
        AjaxCheckbox $accept,
        AjaxCheckbox $redirect,
        AjaxString $email = null,
        AjaxString $password1 = null,
        AjaxString $password2 = null,
        AjaxString $login = null,
        AjaxString $capcha = null
    ) {
        $register = new Users\Register();
        $register->setEmail($email);
        $register->setLogin($login);
        $register->setPassword1($password1);
        $register->setPassword2($<PASSWORD>);
        $register->setCaptcha($capcha);

        if (!$register->validate()) {
            $register->callAjaxerEvents();
            return;
        }

        // EULA
        if (!$accept->val() and \Difra\Config::getInstance()->getValue('auth', 'eula')) {
            $this->root->appendChild($this->xml->createElement('eula'));
            Ajaxer::display(View::render($this->xml, 'auth-ajax', true));
            return;
        }

        $register->register();

        if ($redirect) {
            Cookies::getInstance()->notify(
                Locales::get('auth/register/complete-' . Users::getActivationMethod())
            );
            View::redirect('/');
        } else {
            Ajaxer::notify(
                Locales::get('auth/register/complete-' . Users::getActivationMethod())
            );
            Ajaxer::close();
        }
    }

    /**
     * Authorized user (error)
     */
    public function submitAjaxActionAuth()
    {
        // TODO: handle registered user
        // TODO: log
    }

    /**
     * Activation link
     * @param AnyString $code
     */
    public function activateAction(AnyString $code)
    {
        try {
            Register::activate($code->val());
            Cookies::getInstance()->notify(Locales::get('auth/activate/done'));
        } catch (UsersException $error) {
            Cookies::getInstance()->notify(
                Locales::get('auth/activate/' . $error->getMessage()),
                true
            );
        }
        \Difra\View::redirect('/');
    }
}<commit_msg>Plugins/Users: Added afterActivate() method to RegisterController<commit_after><?php

use Difra\Ajaxer;
use Difra\Libs\Cookies;
use Difra\Locales;
use Difra\Param\AjaxCheckbox;
use Difra\Param\AjaxString;
use Difra\Param\AnyString;
use Difra\Plugins\Users;
use Difra\Param;
use Difra\Plugins\Users\Register;
use Difra\Plugins\Users\UsersException;
use Difra\View;

/**
 * Class RegisterController
 */
class RegisterController extends \Difra\Controller
{
    /**
     * Registration form (page)
     */
    public function indexAction()
    {
        $this->root->appendChild($this->xml->createElement('register'));
    }

    /**
     * Authorized user (already registered)
     */
    public function indexActionAuth()
    {
        // TODO: log
        View::redirect('/');
    }

    /**
     * Registration form (ajax)
     */
    public function indexAjaxAction()
    {
        $this->root->appendChild($this->xml->createElement('register'));
        Ajaxer::display(\Difra\View::render($this->xml, 'auth-ajax', true));
    }

    /**
     * Authorized user (error)
     */
    public function indexAjaxActionAuth()
    {
        // TODO: message
        Ajaxer::reload();
        // TODO: log
    }

    /**
     * Registration form submit (registration page version)
     * @param AjaxCheckbox $accept
     * @param AjaxCheckbox $redirect
     * @param AjaxString|null $email
     * @param AjaxString|null $password1
     * @param AjaxString|null $password2
     * @param AjaxString|null $login
     * @param AjaxString|null $capcha
     * @throws Exception
     */
    public function submitAjaxAction(
        AjaxCheckbox $accept,
        AjaxCheckbox $redirect,
        AjaxString $email = null,
        AjaxString $password1 = null,
        AjaxString $password2 = null,
        AjaxString $login = null,
        AjaxString $capcha = null
    ) {
        $register = new Users\Register();
        $register->setEmail($email);
        $register->setLogin($login);
        $register->setPassword1($<PASSWORD>);
        $register->setPassword2($<PASSWORD>);
        $register->setCaptcha($capcha);

        if (!$register->validate()) {
            $register->callAjaxerEvents();
            return;
        }

        // EULA
        if (!$accept->val() and \Difra\Config::getInstance()->getValue('auth', 'eula')) {
            $this->root->appendChild($this->xml->createElement('eula'));
            Ajaxer::display(View::render($this->xml, 'auth-ajax', true));
            return;
        }

        $register->register();

        if ($redirect) {
            Cookies::getInstance()->notify(
                Locales::get('auth/register/complete-' . Users::getActivationMethod())
            );
            View::redirect('/');
        } else {
            Ajaxer::notify(
                Locales::get('auth/register/complete-' . Users::getActivationMethod())
            );
            Ajaxer::close();
        }
    }

    /**
     * Authorized user (error)
     */
    public function submitAjaxActionAuth()
    {
        // TODO: handle registered user
        // TODO: log
    }

    /**
     * Activation link
     * @param AnyString $code
     */
    public function activateAction(AnyString $code)
    {
        try {
            Register::activate($code->val());
            $this->afterActivate();
        } catch (UsersException $error) {
            Cookies::getInstance()->notify(
                Locales::get('auth/activate/' . $error->getMessage()),
                true
            );
            \Difra\View::redirect('/');
        }
    }

    /**
     * Redefine this method if you want custom actions after activation
     */
    protected function afterActivate()
    {
        Cookies::getInstance()->notify(Locales::get('auth/activate/done'));
        \Difra\View::redirect('/');
    }
}
{'fraction_non_alphanumeric': 0.1443480618053673, 'fraction_numerical': 0.0017619951206288968, 'mean_word_length': 2.125370605675561, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '6330096', 'n_tokens_mistral': 2147, 'n_tokens_neox': 2091, 'n_words': 390}