function ajaxLogin($form) { // We get the Server Configuration $cd = new \Modl\ConfigDAO(); $config = $cd->get(); // First we check the form $validate_login = Validator::email()->length(6, 40); $validate_password = Validator::string()->length(4, 40); $login = $form->login->value; $password = $form->pass->value; if (!$validate_login->validate($login)) { $this->showErrorBlock('login_format'); return; } if (!$validate_password->validate($password)) { $this->showErrorBlock('password_format'); return; } list($username, $host) = explode('@', $login); // Check whitelisted server if ($config->xmppwhitelist != '' && !in_array($host, explode(',', $config->xmppwhitelist))) { $this->showErrorBlock('unauthorized'); return; } // We check if we already have an open session $sd = new \Modl\SessionxDAO(); $here = $sd->getHash(sha1($username . $password . $host)); if ($here) { RPC::call('Login.setCookie', $here->session); RPC::call('movim_redirect', Route::urlize('main')); $this->showErrorBlock('conflict'); return; } // We try to get the domain $domain = \Moxl\Utils::getDomain($host); // We launch the XMPP socket RPC::call('register', $host); // We create a new session or clear the old one $s = Sessionx::start(); $s->init($username, $password, $host, $domain); \Moxl\Stanza\Stream::init($host); }
private function doLogin($login, $password) { // We get the Server Configuration $cd = new \Modl\ConfigDAO(); $config = $cd->get(); // First we check the form $validate_login = Validator::email()->length(1, 254); $validate_password = Validator::stringType()->length(1, 128); if (!$validate_login->validate($login)) { $this->showErrorBlock('login_format'); return; } if (!$validate_password->validate($password)) { $this->showErrorBlock('password_format'); return; } list($username, $host) = explode('@', $login); // Check whitelisted server if ($config->xmppwhitelist != '' && !in_array($host, explode(',', $config->xmppwhitelist))) { $this->showErrorBlock('unauthorized'); return; } // We check if we already have an open session $sd = new \Modl\SessionxDAO(); $here = $sd->getHash(sha1($username . $password . $host)); if ($here) { //if($s->get('hash') == sha1($username.$password.$host)) { RPC::call('Login.setCookie', $here->session); RPC::call('MovimUtils.redirect', Route::urlize('main')); $this->showErrorBlock('conflict'); return; } $s = Session::start(); // We create a new session or clear the old one $s->set('password', $password); $s->set('username', $username); $s->set('host', $host); $s->set('jid', $login); $s->set('hash', sha1($username . $password . $host)); $s = Sessionx::start(); $s->init($username, $password, $host); // We launch the XMPP socket RPC::call('register', $host); \Moxl\Stanza\Stream::init($host); }