persona.phtml 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php if (login_is_conf ($this->conf)) { ?>
  2. <?php
  3. $mail = Session::param ('mail', 'null');
  4. if ($mail != 'null') {
  5. $mail = '\'' . $mail . '\'';
  6. }
  7. ?>
  8. <script type="text/javascript">
  9. url = "<?php echo Url::display (); ?>"
  10. login_url = "<?php echo Url::display (array ('a' => 'login')); ?>";
  11. logout_url = "<?php echo Url::display (array ('a' => 'logout')); ?>";
  12. currentUser = <?php echo $mail; ?>;
  13. $('a.signin').click(function() {
  14. navigator.id.request();
  15. return false;
  16. });
  17. $('a.signout').click(function() {
  18. navigator.id.logout();
  19. return false;
  20. });
  21. navigator.id.watch({
  22. loggedInUser: currentUser,
  23. onlogin: function(assertion) {
  24. // A user has logged in! Here you need to:
  25. // 1. Send the assertion to your backend for verification and to create a session.
  26. // 2. Update your UI.
  27. $.ajax ({
  28. type: 'POST',
  29. url: login_url,
  30. data: {assertion: assertion},
  31. success: function(res, status, xhr) {
  32. var res_obj = jQuery.parseJSON(res);
  33. if (res_obj.status == 'failure') {
  34. //alert (res_obj.reason);
  35. } else if (res_obj.status == 'okay') {
  36. location.href = url;
  37. }
  38. },
  39. error: function(res, status, xhr) {
  40. alert("login failure : " + res);
  41. }
  42. });
  43. },
  44. onlogout: function() {
  45. // A user has logged out! Here you need to:
  46. // Tear down the user's session by redirecting the user or making a call to your backend.
  47. // Also, make sure loggedInUser will get set to null on the next page load.
  48. // (That's a literal JavaScript null. Not false, 0, or undefined. null.)
  49. $.ajax ({
  50. type: 'POST',
  51. url: logout_url,
  52. success: function(res, status, xhr) {
  53. location.href = url;
  54. },
  55. error: function(res, status, xhr) {
  56. //alert("logout failure" + res);
  57. }
  58. });
  59. }
  60. });
  61. </script>
  62. <?php } ?>