<commit_before><?php

use Moxl\Xec\Action\Disco\Request;
use Moxl\Xec\Action\Register\Set;

class AccountNext extends WidgetBase {
    function load()
    {
        $this->addjs('accountnext.js');
        $this->addcss('accountnext.css');

        $this->registerEvent('register_get_handle', 'onForm');
        $this->registerEvent('register_set_handle', 'onRegistered');
        $this->registerEvent('register_set_errorconflict', 'onRegisterError', 'accountnext');
        $this->registerEvent('register_set_errornotacceptable', 'onRegisterNotAcceptable', 'accountnext');
        $this->registerEvent('register_get_errorserviceunavailable', 'onServiceUnavailable', 'accountnext');
    }

    function display()
    {
        $host = $this->get('s');

        $this->view->assign('init', $this->call('ajaxInit', "'".$host."'"));
        $this->view->assign('getsubscriptionform', $this->call('ajaxGetForm', "'".$host."'"));
        $this->view->assign('host', $host);
    }

    function onForm($package)
    {
        $form = $package->content;

        if($package->from == 'movim.eu') {
            $movimview = $this->tpl();
            $movimview->assign('submitdata', $this->call('ajaxRegister', "movim_form_to_json('data')"));
            $html = $movimview->draw('_accountnext_movim', true);

            RPC::call('movim_fill', 'subscription_form', $html);
        } else {
            $xtf = new \XMPPtoForm();
            if(!empty($form->x)){
                switch($form->x->attributes()->xmlns) {
                    case 'jabber:x:data' :
                        $formview = $this->tpl();

                        $formh = $xtf->getHTML($form->x->asXML());
                        $formview->assign('submitdata', $this->call('ajaxRegister', "movim_form_to_json('data')"));

                        $formview->assign('formh', $formh);
                        $html = $formview->draw('_accountnext_form', true);

                        RPC::call('movim_fill', 'subscription_form', $html);
                        break;
                    case 'jabber:x:oob' :
                        $oobview = $this->tpl();
                        $oobview->assign('url', (string)$form->x->url);

                        $html = $oobview->draw('_accountnext_oob', true);

                        RPC::call('movim_fill', 'subscription_form', $html);
                        break;
                }

            } else{
                $formh = $xtf->getHTML($form->asXML());
            }
        }
    }

    function onRegistered($packet)
    {
        $data = $packet->content;

        $view = $this->tpl();
        $view->assign('url', (string)$form->x->url);

        $html = $view->draw('_accountnext_registered', true);

        RPC::call('movim_fill', 'subscribe', $html);
        RPC::call('setUsername', $data->username->value);
    }

    function onRegisterError($package)
    {
        $error = $package->content;
        Notification::append(null, $error);
    }

    function onRegisterNotAcceptable()
    {
        Notification::append(null, $this->__('error.not_acceptable'));
    }

    function onServiceUnavailable()
    {
        Notification::append(null, $this->__('error.service_unavailable'));
        RPC::call('remoteUnregister');
        RPC::call('movim_redirect', $this->route('account'));
    }

    function ajaxGetForm($host)
    {
        $domain = \Moxl\Utils::getDomain($host);

        // We create a new session or clear the old one
        $s = Sessionx::start();
        $s->init(null, null, $host, $domain);

        \Moxl\Stanza\Stream::init($host);
    }

    function ajaxRegister($form)
    {
        $s = new Set;
        $s->setData($form)->request();
    }
}<commit_msg>Add a password validation in AccountNext<commit_after><?php

use Moxl\Xec\Action\Disco\Request;
use Moxl\Xec\Action\Register\Set;

class AccountNext extends WidgetBase {
    function load()
    {
        $this->addjs('accountnext.js');
        $this->addcss('accountnext.css');

        $this->registerEvent('register_get_handle', 'onForm');
        $this->registerEvent('register_set_handle', 'onRegistered');
        $this->registerEvent('register_set_errorconflict', 'onRegisterError', 'accountnext');
        $this->registerEvent('register_set_errornotacceptable', 'onRegisterNotAcceptable', 'accountnext');
        $this->registerEvent('register_get_errorserviceunavailable', 'onServiceUnavailable', 'accountnext');
    }

    function display()
    {
        $host = $this->get('s');

        $this->view->assign('init', $this->call('ajaxInit', "'".$host."'"));
        $this->view->assign('getsubscriptionform', $this->call('ajaxGetForm', "'".$host."'"));
        $this->view->assign('host', $host);
    }

    function onForm($package)
    {
        $form = $package->content;

        if($package->from == 'movim.eu') {
            $movimview = $this->tpl();
            $movimview->assign('submitdata', $this->call('ajaxRegister', "movim_form_to_json('data')"));
            $html = $movimview->draw('_accountnext_movim', true);

            RPC::call('movim_fill', 'subscription_form', $html);
        } else {
            $xtf = new \XMPPtoForm();
            if(!empty($form->x)){
                switch($form->x->attributes()->xmlns) {
                    case 'jabber:x:data' :
                        $formview = $this->tpl();

                        $formh = $xtf->getHTML($form->x->asXML());
                        $formview->assign('submitdata', $this->call('ajaxRegister', "movim_form_to_json('data')"));

                        $formview->assign('formh', $formh);
                        $html = $formview->draw('_accountnext_form', true);

                        RPC::call('movim_fill', 'subscription_form', $html);
                        break;
                    case 'jabber:x:oob' :
                        $oobview = $this->tpl();
                        $oobview->assign('url', (string)$form->x->url);

                        $html = $oobview->draw('_accountnext_oob', true);

                        RPC::call('movim_fill', 'subscription_form', $html);
                        break;
                }

            } else{
                $formh = $xtf->getHTML($form->asXML());
            }
        }
    }

    function onRegistered($packet)
    {
        $data = $packet->content;

        $view = $this->tpl();
        $view->assign('url', (string)$form->x->url);

        $html = $view->draw('_accountnext_registered', true);

        RPC::call('movim_fill', 'subscribe', $html);
        RPC::call('setUsername', $data->username->value);
    }

    function onRegisterError($package)
    {
        $error = $package->content;
        Notification::append(null, $error);
    }

    function onRegisterNotAcceptable()
    {
        Notification::append(null, $this->__('error.not_acceptable'));
    }

    function onServiceUnavailable()
    {
        Notification::append(null, $this->__('error.service_unavailable'));
        RPC::call('remoteUnregister');
        RPC::call('movim_redirect', $this->route('account'));
    }

    function ajaxGetForm($host)
    {
        $domain = \Moxl\Utils::getDomain($host);

        // We create a new session or clear the old one
        $s = Sessionx::start();
        $s->init(null, null, $host, $domain);

        \Moxl\Stanza\Stream::init($host);
    }

    function ajaxRegister($form)
    {
        if(isset($form->re_password)
        && $form->re_password->value != $form->password->value) {
            Notification::append(null, $this->__('account.password_not_same'));
            return;
        }

        $s = new Set;
        $s->setData($form)->request();
    }
}
{'fraction_non_alphanumeric': 0.17575836479625048, 'fraction_numerical': 0.0, 'mean_word_length': 2.206176961602671, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 121, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '116727', 'n_tokens_mistral': 2335, 'n_tokens_neox': 2235, 'n_words': 321}