Browse Source

- Clean some old files

- Rewrite the Login widget errors handler
- Fix a little issue in the Menu
- Fix a little issue in the websocket handler
pull/16/head
Jaussoin Timothée 11 years ago
parent
commit
89f7854997
  1. 22
      app/assets/js/movim_websocket.js
  2. 141
      app/widgets/Login/Login.php
  3. 8
      app/widgets/Login/_login_error.tpl
  4. BIN
      app/widgets/Login/img/beaker.png
  5. BIN
      app/widgets/Login/img/envelope.png
  6. BIN
      app/widgets/Login/img/facebook.png
  7. BIN
      app/widgets/Login/img/jabber.png
  8. 15
      app/widgets/Login/locales.ini
  9. 13
      app/widgets/Login/login.css
  10. 41
      app/widgets/Login/login.tpl
  11. 1
      app/widgets/Menu/Menu.php
  12. 4
      app/widgets/Menu/_menu_list.tpl
  13. 9
      app/widgets/Subscribe/Subscribe.php
  14. 2
      app/widgets/Subscribe/subscribe.tpl

22
app/assets/js/movim_websocket.js

@ -80,17 +80,19 @@ var MovimWebsocket = {
},
send : function(widget, func, params) {
this.connection.send(
JSON.stringify(
{'func' : 'message', 'body' :
{
'widget' : widget,
'func' : func,
'params' : params
if(this.connection.readyState != 0) {
this.connection.send(
JSON.stringify(
{'func' : 'message', 'body' :
{
'widget' : widget,
'func' : func,
'params' : params
}
}
}
)
);
)
);
}
},
attach : function(func) {

141
app/widgets/Login/Login.php

@ -19,6 +19,7 @@
use Moxl\Xec\Action\Storage\Get;
use Moxl\Xec\Action\Roster\GetList;
use Respect\Validation\Validator;
class Login extends WidgetBase
{
@ -59,19 +60,14 @@ class Login extends WidgetBase
function display()
{
$submit = $this->call('ajaxLogin', "movim_parse_form('login')");
$submit = $this->call('ajaxLogin', "movim_form_to_json('login')");
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
$this->view->assign('submit', $submit);
$this->view->assign('info', $config->info);
if(isset($_GET['err'])) {
$this->view->assign('warnings', $this->displayWarning($_GET['err'], true));
} else {
$this->view->assign('warnings', '');
}
$this->view->assign('submit', $submit);
$this->view->assign('info', $config->info);
$this->view->assign('whitelist',$config->xmppwhitelist);
$pop = 0;
@ -85,64 +81,62 @@ class Login extends WidgetBase
$connected = $sd->getConnected();
$this->view->assign('connected', $connected);
$this->view->assign('gmail',
$this->__('account.gmail',
'<a href="#" onclick="fillExample(\'your.id@gmail.com \', \'\');">', '</a>'));
$this->view->assign('facebook',
$this->__('account.facebook',
'<a href="#" onclick="fillExample(\'your.id@chat.facebook.com \', \'\');">', '</a>'));
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
$whitelist = $config->xmppwhitelist;
if(isset($whitelist) && $whitelist!=''){
$this->view->assign('whitelist', $whitelist);
$this->view->assign('whitelist_display', true);
} else{
$this->view->assign('whitelist_display', false);
}
$this->view->assign('error', $this->prepareError());
}
$user = new User();
$color = $user->getConfig('color');
$this->view->assign('color', $color);
function showErrorBlock($error)
{
RPC::call('movim_fill', 'error', $this->prepareError($error));
RPC::call('movim_add_class', '#login_widget', 'error');
}
function prepareError($error = 'default')
{
$view = $this->tpl();
$key = 'error.'.$error;
$error_text = $this->__($key);
if($error_text == $key) {
$view->assign('error', $this->__('error.default'));
} else {
$view->assign('error', $error_text);
}
return $view->draw('_login_error', true);
}
function onMoxlError($error) {
RPC::call('movim_redirect', Route::urlize('disconnect', $error[1]));
}
function onSASLFailure($packet)
{
$title = $this->__('error.fail_auth');
switch($packet->content) {
case 'not-authorized':
$warning = $this->__('error.wrong_account');
$error = 'wrong_account';
break;
case 'invalid-mechanism':
$warning = $this->__('error.mechanism');
$error = 'mechanism';
break;
case 'malformed-request':
$warning = $this->__('error.mechanism');
$error = 'mechanism';
break;
case 'bad-protocol':
$warning = $this->__('error.fail_auth');
$error = 'fail_auth';
break;
case 'bad-auth':
$warning = $this->__('error.wrong_account');
$error = 'wrong_account';
break;
default :
$warning = $this->__('error.fail_auth');
$error = 'fail_auth';
break;
}
RPC::call('remoteUnregisterReload');
Notification::append('login', $title, $warning, null, 2);
$this->showErrorBlock($error);
}
/*
private function displayWarning($warning, $htmlonly = false)
{
if($warning != false) {
@ -255,7 +249,7 @@ class Login extends WidgetBase
exit;
}
}
}
}*/
function ajaxCheckLogin($jid)
{
@ -269,59 +263,53 @@ class Login extends WidgetBase
}
}
function ajaxLogin($element)
function ajaxLogin($form)
{
// We get the Server Configuration
$cd = new \Modl\ConfigDAO;
$config = $cd->get();
$warning = false;
// Empty input test
foreach($element as $value) {
if($value == NULL || $value == '') {
$warning = 'datamissing';
}
// 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;
}
$this->displayWarning($warning);
if(!$validate_password->validate($password)) {
$this->showErrorBlock('password_format');
return;
}
// Correct email test
if(!filter_var($element['login'], FILTER_VALIDATE_EMAIL))
$warning = 'invalidjid';
list($username, $host) = explode('@', $login);
$this->displayWarning($warning);
// Check whitelisted server
if(
$config->xmppwhitelist != '' &&!
in_array(
end(
explode('@', $element['login'])
),
$host,
explode(',',$config->xmppwhitelist)
)
)
$warning = 'serverunauthorized';
$this->displayWarning($warning);
// Correct XMPP account test
$login_arr = explode('@', $element['login']);
$user = $login_arr[0];
$host = $login_arr[1];
) {
$this->showErrorBlock('unauthorized');
return;
}
// We check if we already have an open session
$sd = new \Modl\SessionxDAO;
$here = $sd->checkConnected($user, $host);
$here = $sd->checkConnected($username, $host);
if($here) {
$title = $this->__('error.fail_auth');
$warning = $this->__('error.conflict');
Notification::append('login', $title, $warning, null, 2);
RPC::call('remoteUnregisterReload');
$this->showErrorBlock('conflict');
return;
}
// We try to get the domain
$dns = dns_get_record('_xmpp-client._tcp.'.$login_arr[1]);
if(isset($dns[0]['target']) && $dns[0]['target'] != null)
@ -330,11 +318,9 @@ class Login extends WidgetBase
$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);
$s->init($username, $password, $host, $domain);
\Moxl\Stanza\Stream::init($host);
}
@ -365,6 +351,5 @@ class Login extends WidgetBase
RPC::call('movim_fill', 'sessions', $sessionshtml->draw('_login_sessions', true));
RPC::call('Login.refresh');
RPC::commit();
}
}

8
app/widgets/Login/_login_error.tpl

@ -0,0 +1,8 @@
<section>
<h3>{$c->__('error.title')}</h3>
<br />
<h4 class="gray">{$error}</h4>
</section>
<div>
<span class="button flat oppose" onclick="remoteUnregister(); MovimWebsocket.attach(function() {movim_redirect('{$c->route('login')}')});">{$c->__('button.return')}</span>
</div>

BIN
app/widgets/Login/img/beaker.png

Before

Width: 22  |  Height: 22  |  Size: 316 B

BIN
app/widgets/Login/img/envelope.png

Before

Width: 22  |  Height: 22  |  Size: 336 B

BIN
app/widgets/Login/img/facebook.png

Before

Width: 22  |  Height: 22  |  Size: 259 B

BIN
app/widgets/Login/img/jabber.png

Before

Width: 22  |  Height: 22  |  Size: 616 B

15
app/widgets/Login/locales.ini

@ -1,22 +1,28 @@
error.username = 'Wrong username'
error.jid = 'Invalid JID'
error.mechanism = 'Authentication mechanism not supported by Movim'
error.empty_challenge = 'Empty Challenge from the server'
error.dns = 'XMPP Domain error, your account is not a correct Jabber ID'
error.data_missings = 'Some data are missing !'
error.wrong_password = 'Wrong password'
error.fail_auth = 'The XMPP authentification failed'
error.bosh_invalid = 'The current BOSH URL is invalid'
error.internal = 'Internal server error'
error.session = 'Session error'
error.account_created = 'Account successfully created'
error.wrong_account = 'Movim failed to authenticate. You entered wrong data'
error.xmpp_unauthorized = 'Your XMPP server is unauthorized'
error.mec_error = 'The server takes too much time to respond'
error.too_old = 'Your web browser is too old to use with Movim.'
error.websocket = 'Movim cannot talk with the server, please try again later (Websocket connection error)'
error.impossible = 'Impossible login'
error.title = 'Oops!'
error.default = 'Unknown error'
error.login_format = 'Invalid username format'
error.password_format = 'Invalid password format'
error.unauthorized = 'Your XMPP server is unauthorized'
error.conflict = 'A Movim session is already open on an other device'
error.wrong_account = 'Movim failed to authenticate. You entered wrong data'
error.mechanism = 'Authentication mechanism not supported by Movim'
error.fail_auth = 'The XMPP authentification failed'
account.facebook = 'You can login with Facebook (chat only) using %syour.id@chat.facebook.com%s and your password'
account.gmail = '%sGmail accounts are also compatible%s but are not fully supported'
@ -30,7 +36,6 @@ form.create_one = 'Create one !'
form.no_account = 'No account yet ?'
form.another_account = 'Another account'
whitelist.info = 'This server accept only connection with xmpp accounts from these servers :'
whitelist.info2 = "If you don't have such xmpp account, you can try %sanother public Movim%s client."
whitelist.info = 'You can login with accounts from theses servers'
connected = 'Connected'
population = 'Population'

13
app/widgets/Login/login.css

@ -25,11 +25,9 @@ body main {
display: none;
}
#login_widget.choose > div:first-child {
display: initial;
}
#login_widget:not(.choose) > div:last-child {
#login_widget.choose > div#sessions,
#login_widget.error > div#error,
#login_widget:not(.error):not(.choose) > div#form {
display: initial;
}
@ -49,6 +47,11 @@ body main {
#login_widget form ul input {
margin: 0;
display: block;
height: 5rem;
}
#login_widget .card {
padding: 1rem 2rem;
}
ul.admin {

41
app/widgets/Login/login.tpl

@ -6,7 +6,7 @@
<div id="login_widget">
<div id="sessions" class="dialog actions"></div>
<div class="dialog">
<div id="form" class="dialog">
<section>
<span class="info">{$c->__('connected')} {$connected} / {$pop}</span>
<h3>{$c->__('page.login')}</h3>
@ -51,6 +51,14 @@
</ul>
{/if}
{if="isset($whitelist) && $whitelist != ''"}
<ul class="thin simple card">
<li class="info">
<p>{$c->__('whitelist.info')} : {$whitelist}</p>
</li>
</ul>
{/if}
<ul class="thin simple">
<li class="new_account">
<span>{$c->__('form.no_account')}<br />
@ -62,6 +70,10 @@
</ul>
</section>
</div>
<div id="error" class="dialog actions">
{$error}
</div>
</div>
<div id="error_websocket" class="snackbar">
@ -69,30 +81,3 @@
</div>
{/if}
<!--<div class="clear"></div>-->
<!--
<div class="clear"></div>-->
<!--<ul id="loginhelp">
{if="$whitelist_display == true"}
<li id="whitelist">
<p>{$c->__('whitelist.info')}</p>
<p style="font-weight:bold; text-align:center; margin:0.5em;">{$whitelist}</p>
<p>{$c->__('whitelist.info2', '<a href="http://pod.movim.eu">', '</a>')}</p>
</li>
{else}
<li id="jabber">{$c->__('account.jabber')}
<a href="#" onclick="fillExample('demonstration@movim.eu', 'demonstration');">
{$c->__('account.demo')}
</a>
</li>
<li id="gmail">
{$gmail}
</li>
<li id="facebook">
{$facebook}
</li>
{/if}
</ul>-->

1
app/widgets/Menu/Menu.php

@ -130,6 +130,7 @@ class Menu extends WidgetCommon
$view->assign('items', $items);
$view->assign('page', $page);
$view->assign('paging', $this->_paging);
$html = $view->draw('_menu_list', true);

4
app/widgets/Menu/_menu_list.tpl

@ -6,7 +6,7 @@
{loop="$items"}
<li
tabindex="{$page*15+$key+1}"
tabindex="{$page*$paging+$key+1}"
class="condensed"
data-id="{$value->nodeid}"
data-server="{$value->origin}"
@ -50,7 +50,7 @@
</p>
</li>
{/loop}
{if="count($items) == 15"}
{if="count($items) == $paging"}
<li id="history" onclick="{$history} this.parentNode.removeChild(this);">
<span class="icon"><i class="md md-history"></i></span>
{$c->__('post.older')}

9
app/widgets/Subscribe/Subscribe.php

@ -38,10 +38,13 @@ class Subscribe extends WidgetBase {
$xml = requestURL('http://movim.eu/server-vcards.xml', 1);
if($xml) {
$xml = simplexml_load_string($xml);
$xml = (array)$xml->children();
if($xml) {
$xml = (array)$xml->children();
$this->view->assign('servers', $xml['vcard']);
$this->view->assign('servers', $xml['vcard']);
} else {
$this->view->assign('servers', false);
}
} else {
$this->view->assign('servers', false);
}

2
app/widgets/Subscribe/subscribe.tpl

@ -44,7 +44,7 @@
</span>
<span>{$c->__('subscribe.server_question')}</span>
<p>
{$c->__('subscribe.server_contact')} • <a href="http://movim.eu/">http://movim.eu/</a>
{$c->__('subscribe.server_contact')} • <a href="https://movim.eu/">https://movim.eu/</a>
</p>
</li>
</ul>

Loading…
Cancel
Save