aboutsummaryrefslogtreecommitdiff
path: root/p/scripts/persona.js
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-01-31 14:45:37 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-01-31 14:45:37 +0100
commita97bbd9bd54c5fa56d54b3c214cf4e8af96af8b2 (patch)
tree6e83890bc1b3814a12c3b7bedc0d5944f30f507b /p/scripts/persona.js
parent42fd539a1b14f883077048a35864b4294b6efe94 (diff)
parente91b72b63cd11ae3c4f59e48439e93955242c673 (diff)
Merge branch 'dev'
Conflicts: CHANGELOG README.fr.md README.md app/Controllers/feedController.php app/Controllers/indexController.php app/i18n/en.php app/i18n/fr.php app/views/helpers/view/normal_view.phtml app/views/stats/index.phtml app/views/stats/repartition.phtml constants.php p/scripts/main.js
Diffstat (limited to 'p/scripts/persona.js')
-rw-r--r--p/scripts/persona.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/p/scripts/persona.js b/p/scripts/persona.js
new file mode 100644
index 000000000..36aeeaf56
--- /dev/null
+++ b/p/scripts/persona.js
@@ -0,0 +1,76 @@
+"use strict";
+
+function init_persona() {
+ if (!(navigator.id && window.$)) {
+ if (window.console) {
+ console.log('FreshRSS (Persona) waiting for JS…');
+ }
+ window.setTimeout(init_persona, 100);
+ return;
+ }
+
+ $('a.signin').click(function() {
+ navigator.id.request();
+ return false;
+ });
+
+ $('a.signout').click(function() {
+ navigator.id.logout();
+ return false;
+ });
+
+ navigator.id.watch({
+ loggedInUser: context['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) {
+ if (res.status === 'failure') {
+ openNotification(res.reason, 'bad');
+ } else if (res.status === 'okay') {
+ location.href = url['index'];
+ }
+ },
+ error: function(res, status, xhr) {
+ // alert(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['index'];
+ },
+ error: function(res, status, xhr) {
+ // alert(res);
+ }
+ });
+ }
+ });
+}
+
+if (document.readyState && document.readyState !== 'loading') {
+ if (window.console) {
+ console.log('FreshRSS (Persona) immediate init…');
+ }
+ init_persona();
+} else if (document.addEventListener) {
+ document.addEventListener('DOMContentLoaded', function () {
+ if (window.console) {
+ console.log('FreshRSS (Persona) waiting for DOMContentLoaded…');
+ }
+ init_persona();
+ }, false);
+}