Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Dec 6th, 2018 54 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. var App = Em.Application.create();
  2.  
  3. App.ApplicationController = Em.Controller.extend();
  4. App.ApplicationView = Em.View.extend({ templateName: 'application' });
  5.  
  6. App.HomeController = Em.Controller.extend();
  7. App.HomeView = Em.View.extend({ templateName: 'home' });
  8.  
  9. App.AuthController = Em.Controller.extend({
  10.  
  11.   authenticated: false,
  12.   failedAttempts: 0,
  13.  
  14.   authenticate: function() {
  15.     if (this.credentialsValid()) {
  16.       this.set('authenticated', true);
  17.     } else {
  18.       this.incrementProperty('failedAttempts');
  19.     }
  20.   },
  21.  
  22.   credentialsValid: function() {
  23.     return this.get('email') === 'jamie@jgwhite.co.uk'
  24.         && this.get('password') === 'ilovejam';
  25.   },
  26.  
  27.   authenticatedDidChange: function() {
  28.     if (this.get('authenticated')) {
  29.       this.get('target').send('becomeAuthenticated');
  30.     }
  31.   }.observes('authenticated')
  32.  
  33. });
  34. App.AuthView = Em.View.extend({
  35.   tagName: 'form',
  36.   templateName: 'auth'
  37. });
  38.  
  39. App.TextField = Em.TextField.extend({
  40.   attributeBindings: ['type', 'value', 'size', 'autofocus']
  41. })
  42.  
  43. App.Router = Em.Router.extend({
  44.   root: Em.Route.extend({
  45.  
  46.     // The unknown default state; neither authenticated nor unauthenticated.
  47.     // The router knows to enter this state by default, then the unknown
  48.     // state can decide whether to enter authenticated or unauthenticated mode.
  49.     default: Em.Route.extend({
  50.       route: '/',
  51.  
  52.       enter: function(router) {
  53.         var authenticated = router.get('authController').get('authenticated');
  54.         // It's not at all obvious why this works :(
  55.         Em.run.next(function() {
  56.           if (authenticated) {
  57.             router.transitionTo('authenticated');
  58.           } else {
  59.             router.transitionTo('unauthenticated');
  60.           }
  61.         })
  62.       }
  63.     }),
  64.  
  65.     authenticated: Em.Route.extend({
  66.       initialState: 'home',
  67.  
  68.       home: Em.Route.extend({
  69.         route: '/home',
  70.         connectOutlets: function(router) {
  71.           router.get('applicationController').connectOutlet('home');
  72.         }
  73.       })
  74.  
  75.     }),
  76.  
  77.     unauthenticated: Em.Route.extend({
  78.       initialState: 'auth',
  79.  
  80.       auth: Em.Route.extend({
  81.         route: '/auth',
  82.         connectOutlets: function(router) {
  83.           router.get('applicationController').connectOutlet('auth');
  84.         }
  85.       }),
  86.  
  87.       authenticate: function(router) {
  88.         router.get('authController').authenticate();
  89.       },
  90.  
  91.       becomeAuthenticated: function(router) {
  92.         router.transitionTo('authenticated');
  93.       }
  94.  
  95.     })
  96.  
  97.   })
  98. });
  99.  
  100. App.initialize();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top