Skip to content

Instantly share code, notes, and snippets.

@alonextou
Created September 18, 2013 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alonextou/6617331 to your computer and use it in GitHub Desktop.
Save alonextou/6617331 to your computer and use it in GitHub Desktop.
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();
});
},
}
});
<div class="container">
<form class="form-signin" {{action "login" on="submit"}}>
<input type="text" class="form-control" placeholder="Email address" autofocus>
<input type="password" class="form-control" placeholder="Password">
<label class="checkbox">
<input type="checkbox" value="remember-me">
Remember me
</label>
<button class="btn btn-lg btn-primary btn-block" type="submit">
Sign in
</button>
</form>
</div>
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