Issue #235: refactorisation code Persona
Le code pour la connexion via Persona a été bougée dans le fichier main.js avec le reste du code JS Ça ne marche toujours pas sous Firefox car il essaye d'initialiser navigator.id.watch avant que le fichier login.persona.org/include.js ne soit chargé L'url est correctement écrite côté serveur pour permettre à Persona d'indiquer au site que la connexion s'est bien passéepull/322/head
parent
fb6259f375
commit
5a2a5ee374
5 changed files with 69 additions and 72 deletions
@ -1,68 +0,0 @@ |
||||
<?php if (login_is_conf ($this->conf)) { ?> |
||||
|
||||
<?php |
||||
$mail = Session::param ('mail', 'null'); |
||||
if ($mail != 'null') { |
||||
$mail = '\'' . $mail . '\''; |
||||
} |
||||
?> |
||||
|
||||
<script type="text/javascript"> |
||||
url = "<?php echo Url::display (); ?>"
|
||||
login_url = "<?php echo Url::display (array ('a' => 'login')); ?>";
|
||||
logout_url = "<?php echo Url::display (array ('a' => 'logout')); ?>";
|
||||
currentUser = <?php echo $mail; ?>;
|
||||
|
||||
$('a.signin').click(function() { |
||||
navigator.id.request(); |
||||
return false; |
||||
}); |
||||
|
||||
$('a.signout').click(function() { |
||||
navigator.id.logout(); |
||||
return false; |
||||
}); |
||||
|
||||
navigator.id.watch({ |
||||
loggedInUser: currentUser, |
||||
onlogin: function(assertion) { |
||||
// A user has logged in! Here you need to: |
||||
// 1. Send the assertion to your backend for verification and to create a session. |
||||
// 2. Update your UI. |
||||
$.ajax ({ |
||||
type: 'POST', |
||||
url: login_url, |
||||
data: {assertion: assertion}, |
||||
success: function(res, status, xhr) { |
||||
var res_obj = jQuery.parseJSON(res); |
||||
|
||||
if (res_obj.status == 'failure') { |
||||
//alert (res_obj.reason); |
||||
} else if (res_obj.status == 'okay') { |
||||
location.href = url; |
||||
} |
||||
}, |
||||
error: function(res, status, xhr) { |
||||
alert("login failure : " + res); |
||||
} |
||||
}); |
||||
}, |
||||
onlogout: function() { |
||||
// A user has logged out! Here you need to: |
||||
// Tear down the user's session by redirecting the user or making a call to your backend. |
||||
// Also, make sure loggedInUser will get set to null on the next page load. |
||||
// (That's a literal JavaScript null. Not false, 0, or undefined. null.) |
||||
$.ajax ({ |
||||
type: 'POST', |
||||
url: logout_url, |
||||
success: function(res, status, xhr) { |
||||
location.href = url; |
||||
}, |
||||
error: function(res, status, xhr) { |
||||
//alert("logout failure" + res); |
||||
} |
||||
}); |
||||
} |
||||
}); |
||||
</script> |
||||
<?php } ?> |
Loading…
Reference in new issue