summaryrefslogtreecommitdiff
path: root/p/scripts/persona.js
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-07 16:37:10 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-07 16:37:10 +0200
commit1252b3dd867e59917cf303f0c39c7da938b8ce32 (patch)
tree4997fc8d5b6d5451d1869104546060b9eadb6fb1 /p/scripts/persona.js
parent6009990935a2d06c252073f6b51ea5378536ef52 (diff)
Authentication system moved + Persona comes back!
AuthController is dedicated to auhentication. Persona is back, greater than ever! See https://github.com/marienfressinaud/FreshRSS/issues/655
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);
+}