* * @version 1.0 * @date 07 December 2011 * * Copyright (C)2010 MOVIM project * * See COPYING for licensing information. */ class Login extends WidgetBase { function WidgetLoad() { $this->addcss('login.css'); $this->addjs('login.js'); $this->registerEvent('config', 'onConfig'); $this->registerEvent('moxlerror', 'onMoxlError'); $submit = $this->genCallAjax('ajaxLogin', "movim_parse_form('login')"); $this->view->assign('submit', $submit); $this->view->assign('conf', \system\Conf::getServerConf($submit)); $this->view->assign('submit_event', 'document.getElementById(\'submitb\').click(); '.$submit.' loginButtonSet(\''.t('Connecting...').'\', true); localStorage.username = document.querySelector(\'#login\').value; this.onclick=null;'); $sd = new modl\SessionxDAO(); $sd->clean(); if(isset($_GET['err'])) { $this->view->assign('warnings', $this->displayWarning($_GET['err'], true)); } else { $this->view->assign('warnings', ''); } $pop = 0; foreach(scandir(USERS_PATH) as $f) if(is_dir(USERS_PATH.'/'.$f)) $pop++; $this->view->assign('pop', $pop-2); $sd = new modl\SessionxDAO(); $connected = $sd->getConnected(); $this->view->assign('connected', $connected); $this->view->assign('gmail', t('%sGmail accounts are also compatible%s but are not fully supported', '', '')); $this->view->assign('facebook', t('You can login with Facebook (chat only) using %syour.id@chat.facebook.com%s and your password', '', '')); $conf = \system\Conf::getServerConf(); $whitelist = $conf['xmppWhiteList']; if(isset($whitelist) && $whitelist!=''){ $this->view->assign('whitelist', $whitelist); $this->view->assign('whitelist_display', true); } else{ $this->view->assign('whitelist_display', false); } } function onMoxlError($error) { RPC::call('movim_redirect', Route::urlize('disconnect', $error[1])); } function onConfig(array $data) { $this->user->setConfig($data); } private function displayWarning($warning, $htmlonly = false) { if($warning != false) { switch ($warning) { case 'noaccount': $warning = '
'.t('Wrong username').'
'; break; case 'invalidjid': $warning = '
'.t('Invalid JID').'
'; break; case 'errormechanism': $warning = '
'.t('Authentication mechanism not supported by Movim').'
'; break; case 'errorchallenge': $warning = '
'.t('Empty Challenge from the server').'
'; break; case 'dnsdomain': $warning = '
'.t('XMPP Domain error, your account is not a correct Jabber ID').'
'; break; case 'datamissing': $warning = '
'.t('Some data are missing !').'
'; break; case 'wrongpass': $warning = '
'.t('Wrong password').'
'; break; case 'failauth': $warning = '
'.t('The XMPP authentification failed').'
'; break; case 'bosherror': $warning = '
'.t('The current BOSH URL in invalid').'
'; break; case 'internal': $warning = '
'.t('Internal server error').'
'; break; case 'session': $warning = '
'.t('Session error').'
'; break; case 'acccreated': $warning = '
'.t('Account successfully created').'
'; break; case 'wrongaccount': $warning = '
'.t('Movim failed to authenticate. You entered wrong data').'
'; break; case 'serverunauthorized': $warning = '
'.t('Your XMPP server is unauthorized').'
'; case 'mecerror': $warning = '
'.t('The server takes too much time to respond').'
'; break; default: $warning = '
'.$warning.'
'; break; } if($htmlonly) return $warning; else { RPC::call('movim_fill', 'warning', $warning); RPC::call('loginButtonSet', t("Come in!")); RPC::commit(); exit; } } } function ajaxLogin($element) { // We get the Server Configuration $serverconfig = \system\Conf::getServerConf(); $warning = false; // Empty input test foreach($element as $value) { if($value == NULL || $value == '') { $warning = 'datamissing'; } } $this->displayWarning($warning); // Correct email test if(!filter_var($element['login'], FILTER_VALIDATE_EMAIL)) $warning = 'invalidjid'; $this->displayWarning($warning); // Check whitelisted server if( $serverconfig['xmppWhiteList'] != '' &&! in_array( end( explode('@', $element['login']) ), explode(',',$serverconfig['xmppWhiteList']) ) ) $warning = 'serverunauthorized'; $this->displayWarning($warning); // Correct XMPP account test $login_arr = explode('@', $element['login']); $user = $login_arr[0]; $host = $login_arr[1]; $dns = dns_get_record('_xmpp-client._tcp.'.$login_arr[1]); if(isset($dns[0]['target']) && $dns[0]['target'] != null) $domain = $dns[0]['target']; else { $domain = $host; } $this->displayWarning($warning); // We create a new session or clear the old one $s = Sessionx::start(); $s->init($user, $element['pass'], $host, $domain); // We save the loaded widgets list in the database $wrapper = WidgetWrapper::getInstance(false); $sess = Session::start(APP_NAME); $sess->set('registered_events', $wrapper->register_events()); // BOSH + XMPP connexion test $warning = moxl\login(); if($warning != 'OK') { RPC::call('movim_redirect', Route::urlize('login', $warning)); RPC::commit(); } else { $pd = new modl\PresenceDAO(); $pd->clearPresence($element['login']); RPC::call('movim_redirect', Route::urlize('main')); RPC::commit(); } } function ajaxGetConfig() { $s = new moxl\StorageGet(); $s->setXmlns('movim:prefs') ->request(); $evt = new \Event(); $evt->runEvent('nostream'); } }