1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/movim_ynh.git synced 2024-09-03 19:46:19 +02:00
movim_ynh/sources/app/widgets/LoginAnonymous/LoginAnonymous.php
2015-12-15 11:54:49 +01:00

59 lines
1.4 KiB
PHP

<?php
use Respect\Validation\Validator;
class LoginAnonymous extends WidgetBase
{
function load()
{
$this->addjs('loginanonymous.js');
$this->registerEvent('session_start_handle', 'onStart');
}
function onStart($packet)
{
$session = \Sessionx::start();
$session->load();
if($session->mechanism == 'ANONYMOUS') {
RPC::call('Rooms.anonymousJoin');
}
}
function display()
{
}
function ajaxLogin($username)
{
$validate_user = Validator::stringType()->length(4, 40);
if(!$validate_user->validate($username)) {
Notification::append(null, $this->__('login_anonymous.bad_username'));
return;
}
// We get the Server Configuration
$cd = new \Modl\ConfigDAO;
$config = $cd->get();
$host = 'anonymous.jappix.com';
$password = 'AmISnowden?';
// We try to get the domain
$domain = \Moxl\Utils::getDomain($host);
// We launch the XMPP socket
RPC::call('register', $host);
// We set the username in the session
$s = Session::start();
$s->set('username', $username);
// We create a new session or clear the old one
$s = Sessionx::start();
$s->init($username, $password, $host, $domain);
\Moxl\Stanza\Stream::init($host);
}
}