A free, self-hostable news aggregator…
Issue #235: refactorisation code Persona
Marien Fressinaud5a2a5ee37480
diff --git a/app/controllers/indexController.php b/app/controllers/indexController.phpindex 15b0b1d18..76fd2cc75 100755--- a/app/controllers/indexController.php+++ b/app/controllers/indexController.php@@ -194,7 +194,7 @@ class indexController extends ActionController {$url = 'https://verifier.login.persona.org/verify';$assert = Request::param ('assertion');$params = 'assertion=' . $assert . '&audience=' .- urlencode (Url::display () . ':80');+ urlencode (Url::display (null, 'php', true));$ch = curl_init ();$options = array (CURLOPT_URL => $url,diff --git a/app/layout/layout.phtml b/app/layout/layout.phtmlindex b3e6d85aa..f958acb46 100644--- a/app/layout/layout.phtml+++ b/app/layout/layout.phtml@@ -27,8 +27,6 @@<?php $this->render (); ?></div>-<?php $this->partial ('persona'); ?>-<?php if (isset ($this->notification)) { ?><div class="notification <?php echo $this->notification['type']; ?>"><?php echo $this->notification['content']; ?>diff --git a/app/layout/persona.phtml b/app/layout/persona.phtmldeleted file mode 100644index f25e4c3fd..000000000--- a/app/layout/persona.phtml+++ /dev/null@@ -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 } ?>diff --git a/app/views/javascript/main.phtml b/app/views/javascript/main.phtmlindex c5a14ad06..04b4a7337 100644--- a/app/views/javascript/main.phtml+++ b/app/views/javascript/main.phtml@@ -17,4 +17,13 @@'go_website:"', $s['go_website'], '",','prev_entry:"', $s['prev_entry'], '",','next_entry:"', $s['next_entry'], '"',- "};\n";+ "}";++ $mail = Session::param ('mail', 'null');+ if ($mail != 'null') {+ $mail = '"' . $mail . '"';+ }+ echo ',url_freshrss="', _url ('index', 'index'), '",',+ 'url_login="', _url ('index', 'login'), '",',+ 'url_logout="', _url ('index', 'logout'), '",',+ 'current_user_mail=', $mail, ';';diff --git a/public/scripts/main.js b/public/scripts/main.jsindex f4bffcca8..663f311c3 100644--- a/public/scripts/main.js+++ b/public/scripts/main.js@@ -504,6 +504,63 @@ function init_load_more() {}//</endless_mode>+//<persona>+function init_persona() {+ $('a.signin').click(function() {+ navigator.id.request();+ return false;+ });++ $('a.signout').click(function() {+ navigator.id.logout();+ return false;+ });++ navigator.id.watch({+ loggedInUser: current_user_mail,++ 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: url_login,+ 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_freshrss;+ }+ },+ 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: url_logout,+ success: function(res, status, xhr) {+ location.href = url_freshrss;+ },+ error: function(res, status, xhr) {+ //alert("logout failure" + res);+ }+ });+ }+ });+}+//</persona>+function init_all() {if (!(window.$ && window.shortcut && window.shortcuts && ((!full_lazyload) || $.fn.lazyload))) {if (window.console) {@@ -522,6 +579,7 @@ function init_all() {init_notifications();init_actualize();init_load_more();+ init_persona();if (window.console) {console.log('Init done.');}