Ok, I managed to do it, in fact it was way simpler than I thought !
And this just proves how wonderfull ModX is.
So, for anyone looking to do the same, here is how I do it :
First, I use Mootools 1.2 with Request lib. You have to include it in your page.
You also have to include the following javascript code :
window.addEvent('domready', function() {
var reqlogin = new Request.JSON({url:'connectors/security/login.php', method:'post',
onSuccess: function(resultatjson) {
if(resultatjson.success) {
window.location.reload(true);
} else {
$('mtamessage').set('text', resultatjson.message);
}
},
//Our request will most likely succeed, but just in case, we'll add an
//onFailure method which will let the user know what happened.
onFailure: function(resultatjson) {
$('mtamessage').set('text', 'The request failed.');
}
});
var reqlogout = new Request.JSON({url:'connectors/security/logout.php',
onSuccess: function(resultatjson) {
window.location.reload(true);
},
//Our request will most likely succeed, but just in case, we'll add an
//onFailure method which will let the user know what happened.
onFailure: function() {
$('mtamessage').set('text', 'The request failed.');
}
});
if($defined($('LoginRequest')))
$('LoginRequest').addEvent('click', function(evt) {
new Event(evt).stop();
reqlogin.send('username='+($('mtausername').value)+'&password='+($('mtaPassword').value)+'&login_context=web&rememberme='+($('mtaremember').checked));
});
if($defined($('LogoutRequest')))
$('LogoutRequest').addEvent('click', function(evt) {
new Event(evt).stop();
reqlogout.send();
});
});
Then, using the Personalize snippet, I have the following chunks :
yesChunk :
Logged : [[+username]]
<div id="mtamessage" style="color:red"></div>
<form method="POST">
<button type="submit" id="LogoutRequest" value="logout">Logout</button>
</form>
noChunk :
<strong>Log In : </strong>
<form method="post">
<div id="mtamessage" style="color:red"></div>
<label id="mtausernameLabel" for="mtausername">Username
<input id="mtausername" type="text" name="username" />
</label>
<label id="mtaPasswordLabel" for="mtaPassword">Password
<input id="mtaPassword" type="password" name="password" />
</label>
<input id="mtacontext" type="hidden" name="login_context" value="web"/>
<label id="mtarememberLabel" for="mtaremember">Remember me
<input id="mtaremember" type="checkbox" name="rememberme"/>
</label>
<button type="submit" id="LoginRequest" value="login">Login</button>
</form>
Now, it seems you can’t use the same session on the Web context and in admin mode, so you have to logout, then login in the manager to be able to use it. I think it would be best if the session was unique, but that’s not a great deal anyway.