Browse Source

- Add browser detection

- Add HTML5 form validation
- Add JID verification
pull/5/head
Jaussoin Timothée 14 years ago
parent
commit
e9adc536ab
  1. 46
      loader.php
  2. 107
      system/Controller/ControllerMain.php
  3. 4
      system/Jabber.php
  4. 18
      system/User.php
  5. 8
      system/Widget/widgets/Vcard/Vcard.php
  6. 11
      system/Widget/widgets/Vcard/vcard.css
  7. 63
      themes/movim/css/login_form.css
  8. 7
      themes/movim/css/style2.css

46
loader.php

@ -36,6 +36,52 @@ require(LIB_PATH . "Tpl/TplPageBuilder.php");
require(LIB_PATH . "Widget/WidgetBase.php");
require(LIB_PATH . "Widget/WidgetWrapper.php");
// User agent detection
$useragent = $_SERVER['HTTP_USER_AGENT'];
if (preg_match('|MSIE ([0-9].[0-9]{1,2})|',$useragent,$matched)) {
$browser_version=$matched[1];
$browser = 'IE';
} elseif (preg_match('/Opera[\/ ]([0-9]{1}\.[0-9]{1}([0-9])?)/',$useragent,$matched)) {
$browser_version=$matched[1];
$browser = 'Opera';
} elseif(preg_match('|Firefox/([0-9\.]+)|',$useragent,$matched)) {
$browser_version=$matched[1];
$browser = 'Firefox';
} elseif(preg_match('|Safari/([0-9\.]+)|',$useragent,$matched)) {
$browser_version=$matched[1];
$browser = 'Safari';
} else {
$browser_version = 0;
$browser= 'other';
}
define('BROWSER_VERSION', $browser_version);
define('BROWSER', $browser);
$compatible = false;
switch($browser) {
case 'Firefox':
if($browser_version > 3.5)
$compatible = true;
break;
case 'IE':
if($browser_version > 8.0)
$compatible = true;
break;
case 'Safari': // Also Chrome-Chromium
if($browser_version > 522.0)
$compatible = true;
break;
case 'Opera':
if($browser_version > 9.0)
$compatible = true;
break;
}
define('BROWSER_COMP', $compatible);
// Starting session.
storage_load_driver(Conf::getServerConfElement('storageDriver'));

107
system/Controller/ControllerMain.php

@ -124,57 +124,96 @@ class ControllerMain extends ControllerBase
$this->page->menuAddLink('Movim | Human Network', 'http://www.movim.eu/');
if(Conf::getServerConfElement("accountCreation") == 1)
$this->page->menuAddLink(t('Account Creation'), '?q=account');
if($_GET['err'] == 'auth') {
$this->page->setContent(
'<div class="warning">'.
t('Changing these data can be dangerous and may compromise the connection to the Jabber server')
.'</div>');
}
switch ($_GET['err']) {
case 'noaccount':
$warning = '
<div class="warning">
Wrong username
</div> ';
break;
case 'invalidjid':
$warning = '
<div class="warning">
Invalid JID
</div> ';
break;
case 'failauth':
$warning = '
<div class="warning">
The XMPP authentification failed
</div> ';
break;
}
if(!BROWSER_COMP)
$browser_comp = '
<div class="warning">
'.t('Your web browser is too old to use with Movim.').'
</div> ';
$serverconf = Conf::getServerConf();
var_dump($serverconf);
$this->page->setContent(
'<div id="loginpage">'.
'<div id="quote">
<blockquote>'.
ob_start();
?>
<noscript>
<style type="text/css">
#loginpage {display:none;}
</style>
<div class="warning">
<?php echo t("You don't have javascript enabled. Good luck with that."); ?>
</div>
</noscript>
<div id="loginpage">
<?php echo $browser_comp; ?>
<div id="quote">
<blockquote>
"I'm free! — I'm free,<br />
And freedom tastes of reality,<br />
I'm free — I'm free,<br />
An' I'm waiting for you to follow me.<br />
</blockquote>
<cite>
<a href=\"http://wikipedia.org/wiki/Pete_Townshend\">Pete Townshend</a>, in
<a href=\"http://wikipedia.org/wiki/I'm_Free_(The_Who_song)\">\"I'm Free\"</a> on
<a href=\"http://wikipedia.org/wiki/Tommy_(album)\">Tommy</a> by
<a href=\"http://wikipedia.org/wiki/The_Who\">The Who</a>
<a href="http://wikipedia.org/wiki/Pete_Townshend">Pete Townshend</a>, in
<a href="http://wikipedia.org/wiki/I'm_Free_(The_Who_song)">"I'm Free"</a> on
<a href="http://wikipedia.org/wiki/Tommy_(album)">Tommy</a> by
<a href="http://wikipedia.org/wiki/The_Who">The Who</a>
</cite>
".
'</div>'.
'<form id="connectform" action="index.php" method="post">'.
'<input type="text" name="login" id="login"
value="'.t("My address").'" onfocus="myFocus(this);" onblur="myBlur(this);"/><br />'.
'<input type="password" name="pass" id="pass"
value="'.t("Password").'" onfocus="myFocus(this);" onblur="myBlur(this);"/><br />'.
</div>
<form id="connectform" action="index.php" method="post">
<?php echo $warning; ?>
<input type="email" name="login" id="login" autofocus
value="<?php echo t("My address"); ?>" onfocus="myFocus(this);" onblur="myBlur(this);"/><br />
<input type="password" name="pass" id="pass"
value="<?php echo t("Password"); ?> " onfocus="myFocus(this);" onblur="myBlur(this);"/><br />
'<a href="#" class="showoptions" onclick="getElementById(\'options\').style.display = \'block\';">'.t('Options').'</a>'.
<a href="#" class="showoptions" onclick="getElementById('options').style.display = 'block';"><?php echo t('Options'); ?></a>
'<fieldset id="options" style="display: none;">'.
'<label class="tiny">'.t('Bosh Host').'</label>
<fieldset id="options" style="display: none;">
<label class="tiny"><?php echo t('First Login'); ?></label>
<input type="checkbox" class="tiny" name="create" id="create"><br />
<hr />
<label class="tiny"><?php echo t('Bosh Host'); ?></label>
<input type="text" class="tiny" name="host" id="host"
value="'.$serverconf['defBoshHost'].'" onfocus="myFocus(this);" onblur="myBlur(this);"/><br />'.
value="<?php echo $serverconf['defBoshHost']; ?>" onfocus="myFocus(this);" onblur="myBlur(this);"/><br />
'<label class="tiny">'.t('Bosh Suffix').'</label>
<label class="tiny"><?php echo t('Bosh Suffix'); ?></label>
<input type="text" class="tiny" name="suffix" id="suffix"
value="'.$serverconf['defBoshSuffix'].'" onfocus="myFocus(this);" onblur="myBlur(this);"/><br />'.
value="<?php echo $serverconf['defBoshSuffix']; ?>" onfocus="myFocus(this);" onblur="myBlur(this);"/><br />
'<label class="tiny">'.t('Bosh Port').'</label>
<label class="tiny"><?php echo t('Bosh Port'); ?></label>
<input type="text" class="tiny" name="port" id="port"
value="'.$serverconf['defBoshPort'].'" onfocus="myFocus(this);" onblur="myBlur(this);"/><br />'.
'</fieldset>'.
'<input class="submit" type="submit" name="submit" value="'.t("Come in!").'"/>'.
'</form>'.
'</div>');
value="<?php echo $serverconf['defBoshPort']; ?>" onfocus="myFocus(this);" onblur="myBlur(this);"/><br />
</fieldset>
<input class="submit" type="submit" name="submit" value="<?php echo t("Come in!"); ?>"/>
</form>
</div>
<?php
$this->page->setContent(ob_get_contents());
ob_end_clean();
echo $this->page->build('page.tpl');
}

4
system/Jabber.php

@ -151,8 +151,8 @@ class Jabber
* @return void
*/
public function postAuth() {
//$this->jaxl->getRosterList();
//$this->jaxl->getVCard();
$this->jaxl->getRosterList();
$this->jaxl->getVCard();
}
/**

18
system/User.php

@ -29,7 +29,7 @@ class User {
&& isset($_POST['pass'])
&& $_POST['login'] != ''
&& $_POST['pass'] != '') {
$this->authenticate($_POST['login'], $_POST['pass'], $_POST['host'], $_POST['suffix'], $_POST['port']);
$this->authenticate($_POST['login'], $_POST['pass'], $_POST['host'], $_POST['suffix'], $_POST['port'], $_POST['create']);
}
}
@ -43,13 +43,21 @@ class User {
return (($this->username != '' && $this->password != '') || $sess->get('login'));
}
function authenticate($login,$pass, $boshhost, $boshsuffix, $boshport)
function authenticate($login,$pass, $boshhost, $boshsuffix, $boshport, $create)
{
try{
if(filter_var($login, FILTER_VALIDATE_EMAIL) == false) {
header('Location:'.BASE_URI.'index.php?q=disconnect&err=invalidjid');
exit();
}
$data = false;
if( !($data = Conf::getUserData($login)) ) {
Conf::createUserConf($login, $pass, $boshhost, $boshsuffix, $boshport);
$data = Conf::getUserData($login);
if( !($data = Conf::getUserData($login))) {
if($create == "on") {
Conf::createUserConf($login, $pass, $boshhost, $boshsuffix, $boshport);
$data = Conf::getUserData($login);
} else {
header('Location:'.BASE_URI.'index.php?q=disconnect&err=noaccount');
}
}
$this->xmppSession = Jabber::getInstance($login);

8
system/Widget/widgets/Vcard/Vcard.php

@ -58,12 +58,12 @@ class Vcard extends WidgetBase
<input type="text" name ="vCardNickname" class="content" value="'.$vcard["vCardNickname"].'">
</div>';
$html .= '<div class="element"><span>'.t('Date of Birth').' YYYY-MM-DD</span>
<input type="text" name ="vCardBDay" class="content" value="'.$vcard["vCardBDay"].'">
<input type="text" pattern="(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))" name ="vCardBDay" class="content" value="'.$vcard["vCardBDay"].'">
</div>';
$html .= '<br />
<div class="element"><span>'.t('Website').'</span>
<input type="text" name ="vCardUrl" class="content" value="'.$vcard["vCardUrl"].'">
<input type="url" name ="vCardUrl" class="content" value="'.$vcard["vCardUrl"].'">
</div>';
$html .= '<br />
@ -75,7 +75,7 @@ class Vcard extends WidgetBase
$html .= '<br />
<fieldset>
<legend>'.t('Geographic Position').'</legend>';
$html .= '<div class="warning">'.t('Renseigner votre position géographique peut fortement porter atteinte à votre vie privé, utilisez toujours cette option qu\'en cas de nécessité').'<a class="button tiny" style="float: right;" onclick="getPos(this);">Récupérer ma position</a></div>';
$html .= '<div class="warning">'.t('Renseigner votre position géographique peut fortement porter atteinte à votre vie privé, n\'utilisez toujours cette option qu\'en cas de nécessité').'<a class="button tiny" style="float: right;" onclick="getPos(this);">Récupérer ma position</a></div>';
$html .= '<div id="geolocation"></div>';
$html .= '<div class="element"><span>'.t('Latitude').'</span>
<input type="text" name="vCardLat" class="content" value="Latitude" readonly>
@ -97,7 +97,7 @@ class Vcard extends WidgetBase
$html .= '<br />';
$html .= $this->displayIf($vcard["vCardDesc"], t('About Me'));*/
$html .= '<hr />';
$html .= ' <input value="'.t('Submit').'" onclick="'.$submit.'" id="right" type="button"> ';
$html .= ' <input value="'.t('Submit').'" type="submit" onclick="'.$submit.'" id="right" type="button"> ';
$html .= '
</fieldset>
</form>';

11
system/Widget/widgets/Vcard/vcard.css

@ -11,19 +11,24 @@
border: 1px solid #CCC;
}
#vcard input[type=text], #vcard textarea {
#vcard input[type=text], #vcard input[type=url], #vcard textarea {
border: 1px solid transparent;
margin: -5px;
}
#vcard input[type=text]:hover, #vcard textarea:hover {
#vcard input[type=text]:hover, #vcard input[type=url]:hover, #vcard textarea:hover {
border-color: #DDD;
}
#vcard input[type=text]:focus, #vcard textarea:hover {
#vcard input[type=text]:focus, #vcard input[type=url]:focus, #vcard textarea:focus {
border-color: #CCC;
}
#vcard input:invalid, #vcard input:invalid:hover, #vcard input:invalid:focus {
border-color: #983A3A;
}
#vcard .element span {
font-weight: bold;
width: 170px;

63
themes/movim/css/login_form.css

@ -30,13 +30,25 @@
#connectform {
font-size: 17px;
padding: 10px;
padding: 0px 10px;
float: right;
min-height: 200px;
margin-top: 50px;
border-left: 1px solid #ccc;
}
#connectform hr {
margin: 0px;
height: 0px;
display: block;
clear: both;
}
#connectform .warning {
font-size: 12px;
margin: 5px;
}
#connectform label {
margin: 5px;
width: 80px;
@ -58,52 +70,3 @@
border: none;
}
/*#connect_form
{
width: auto;
margin: 0 auto;
margin-top: -5px;
padding: 9em 0.5em;
font-size: 17px;
background-repeat: no-repeat;
background-image: url(../img/bee.png);
background-position: center center;
}
#connect_form form
{
margin: 0 auto;
text-align: center;
background-color: rgba(255,255,255, 0.6);
padding: 0.5em;
width: 300px;
}
#connect_form form .showoption {
font-size: 12px;
float: left;
}
#connect_form form fieldset {
padding-top: 5px;
clear: both;
display: none;
}
#connect_form input
{
margin: 5px;
}
#connect_form input.submit {
clear: both;
float: none;
}
#connect_form #port {
width: 2em;
}
#connect_form #suffix {
width: 5em;
}*/

7
themes/movim/css/style2.css

@ -147,6 +147,11 @@ input:focus, select:focus, textarea:focus {
border: 1px solid #888888;
}
input:invalid, input:focus:invalid {
border-color: #983A3A;
-moz-box-shadow: none;
}
input[type=submit], input[type=reset], input[type=button], .button, .button:link, .button:visited {
cursor: pointer;
border: 1px solid black;
@ -269,6 +274,8 @@ label {
.valid {
background-color: #90DC89;
border: 1px solid #4ABB3F;
padding: 10px;
margin: 10px 0px;
color: #1C4D17;
}

Loading…
Cancel
Save