Sha256: 5f1c99ffc02fcaf8498519096a9fc52b701bc32189cd93ce618999c4d8ef4e7c

Contents?: true

Size: 1.15 KB

Versions: 8

Compression:

Stored size: 1.15 KB

Contents

//= require 'jquery.exists'
//= require 'cms/namespace'

Cms.User = function() {
};

// Find the current user and then take action based on whether the current user is authenticated or not.
// @todo - Avoid repeated AJAX calls to find the user if this is involved multiple times.
//
// @param [ObjectLiteral] options
// @option options [Function] :authenticated Call for authenticated users.
// @option options [Function] :guest (Optional) Call for guests.
//
// @example  Cms.User.current({
//    authenticated: function(user){ alert("Hello " + user.first_name);
// }); 
Cms.User.current = function(handler) {
  $.getJSON('/cms/user.json', function(user) {
//    console.log("current_user", user);
    if (user.is_logged_in) {
      handler.authenticated(user);
    } else if (handler.guest) {
      handler.guest(user);
    }
  });
};

// Default Handler for login portlet. Hide the form, show 'Hello $full_name'
jQuery(function($){
  if ($('.login-portlet').exists()) {
    Cms.User.current({
        authenticated: function(user) {
          $('.authenticated').show().find('.user-name').html(user.full_name);
          $('.guest').hide();
        }
      }
    );
  }
});

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
browsercms-artirix-4.0.4 app/assets/javascripts/cms/user.js
browsercms-artirix-4.0.3.3 app/assets/javascripts/cms/user.js
browsercms-artirix-4.0.3.2 app/assets/javascripts/cms/user.js
browsercms-artirix-4.0.3.1 app/assets/javascripts/cms/user.js
browsercms-artirix-4.0.3 app/assets/javascripts/cms/user.js
browsercms-artirix-4.0.2 app/assets/javascripts/cms/user.js
browsercms-artirix-4.0.1.1 app/assets/javascripts/cms/user.js
browsercms-artirix-4.0.0.rc1.art4 app/assets/javascripts/cms/user.js