Skip to content

Instantly share code, notes, and snippets.

@amaanr
Created May 23, 2013 15:23
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 amaanr/5636881 to your computer and use it in GitHub Desktop.
Save amaanr/5636881 to your computer and use it in GitHub Desktop.
App.LoginController = Ember.Controller.extend({
email: null,
password: null,
message: null,
submit: function() {
Ember.$.ajax({
url: "sessions.json",
type: "POST",
data: {
user: {
email: this.get('email'),
password: this.get('password'),
remember_me: 1
}
},
context: this,
success: function(json) {
this.send('userDidLogin', App.store.load(App.User, json.user));
this.reset();
this.transitionToRoute('index');
},
error: function(xhr) {
var json = $.parseJSON(xhr.responseText);
this.set('message', json.message);
}
});
},
reset: function() {
this.set('message', null);
this.set('password', null);
this.set('email', null);
}
});
App.RegisterController = Ember.Controller.extend({
email: null,
password: null,
errors: null,
submit: function() {
this.set('errors', null);
Ember.$.ajax({
url: "registrations.json",
type: "POST",
data: {
registration: {
email: this.get('email'),
password: this.get('password')
}
},
context: this,
success: function(json) {
Ember.run(this, function() {
var user = App.store.load(App.User, json.user);
this.send('userDidLogin', user);
});
this.reset();
this.transitionToRoute('index');
},
error: function(xhr) {
var json = $.parseJSON(xhr.responseText);
this.set('errors', json.errors);
}
});
},
reset: function() {
this.set('email', null);
this.set('password', null);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment