persona.phtml 1.8 KB

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