Created
September 18, 2013 23:45
-
-
Save alonextou/6617331 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.AuthController = Ember.Controller.extend({ | |
user: null, | |
isAdmin: false, | |
isGuest: true, | |
actions: { | |
login: function() { | |
console.log('logging in'); | |
var self = this; | |
var response = $.Deferred(); | |
$.ajax({ | |
url: '/api/users/login', | |
type: 'POST', | |
data: { | |
username: this.get('username'), | |
password: this.get('password') | |
} | |
}).done(function(data) { | |
console.log(data); | |
self.set('isGuest', false); | |
self.transitionToRoute('index'); | |
response.resolve(); | |
}).fail(function(xhr, status, error) { | |
console.log(xhr.responseText); | |
response.reject(); | |
}); | |
}, | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Router.map(function() { | |
this.route('login'); | |
}); | |
App.LoginRoute = Ember.Route.extend({ | |
setupController: function(controller, model) { | |
this.controllerFor('auth').set('model', model); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment