123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- Meteor._debug("Loading lib/drupalsso");
- if (Meteor.isClient) {
- var stream = new Meteor.Stream(CHANNEL_NAME);
- }
- DrupalSSO = function () {
-
- if (!(this instanceof DrupalSSO)) {
- return new DrupalSSO();
- }
-
- var that = this;
- this.settings = {
- client: {}
- };
- this.state = {
- anonymousName: 'anome',
- cookieName: 'SESS___4___8__12__16__20__24__28__32',
-
- online: undefined
- };
- var user = {
- uid: 0,
- name: 'undefined name',
- roles: ['anonymous user']
- };
- var userDep = new Tracker.Dependency();
- this.getUserId = function () {
- userDep.depend();
- return user.uid;
- };
- this.getUserName = function () {
- userDep.depend();
- return user.name;
- };
- this.getUserRoles = function () {
- userDep.depend();
- return user.roles;
- };
-
- this.updateUser = function (cookies) {
- if (Meteor.isClient) {
- Meteor._debug('Setting up once on ' + CHANNEL_NAME);
-
- stream.once(EVENT_NAME, function (e) {
- that.updateUser(document.cookie);
- });
- }
- Meteor.call('drupal-sso.whoami', cookies, function (err, res) {
- if (err) {
- throw new Meteor.Error('whoami', err);
- }
- _.extend(user, res);
- userDep.changed();
- });
- };
-
- this.getSessionCookie = function (cookieBlob) {
- cookieBlob = '; ' + cookieBlob;
- var cookieName = that.state.cookieName;
- var cookieValue;
- var cookies = cookieBlob.split('; ' + cookieName + "=");
- if (cookies.length == 2) {
- cookieValue = cookies.pop().split(';').shift();
- }
- return cookieValue;
- };
-
- this.initServerState = function (settings) {
- that.settings['drupal-sso'] = settings['drupal-sso'];
- };
-
-
- _.extend(that.settings.client, Meteor.settings.public);
-
- Meteor.call('drupal-sso.initState', function (err, res) {
- if (err) {
- throw new Meteor.Error('init-state', err);
- }
- _.extend(that.state, res);
- if (Meteor.isClient) {
- that.updateUser(document.cookie);
- }
- });
- };
|