auth.js 707 B

1234567891011121314151617181920212223242526272829303132
  1. import Ember from 'ember';
  2. export default Ember.Service.extend({
  3. isAnonymous: Ember.computed.not('isAuthenticated'),
  4. logout: function() {
  5. Ember.$('#hidden-logout-form').submit();
  6. },
  7. // Utils for triggering 403 error
  8. _throw: function(message) {
  9. throw {
  10. status: 403,
  11. responseJSON: {
  12. detail: message
  13. }
  14. };
  15. },
  16. denyAuthenticated: function(message) {
  17. if (this.get('isAuthenticated')) {
  18. this._throw(message || gettext('This page is not available to signed in users.'));
  19. }
  20. },
  21. denyAnonymous: function(message) {
  22. if (this.get('isAnonymous')) {
  23. this._throw(message || gettext('This page is not available to guests.'));
  24. }
  25. }
  26. });