Skip to content

Instantly share code, notes, and snippets.

@kelso
Last active December 19, 2015 13:19
Show Gist options
  • Save kelso/5961645 to your computer and use it in GitHub Desktop.
Save kelso/5961645 to your computer and use it in GitHub Desktop.
Syncin.LoginController = Ember.Controller.extend({
login: function() {
var data = {
username: this.get('username'),
password: this.get('password')
}
var self = this;
self.set('errorMessage', null);
Ember.$.post('/api/v1/sessions', data).then(function(response){
self.set('errorMessage', response.message)
if (response.success) {
alert("success token is" + response.token);
self.controller.set('loggedIn', true);
}
else {
alert("wrong username or password");
}
})
},
logout: function() {
this.set('loggedIn', false);
alert("You are logged out.");
},
reset: function() {
this.set("username", "");
this.set("password", "");
this.set("errorMessage", "");
}
});
class Api::V1::SessionsController < ApplicationController
respond_to :json
def create
username = params[:username]
password = params[:password]
if username == "admin" && password == "123456"
render :json => {:success => true, :token => "abcdefgh"}
else
render :json => {:success => false, :message => "Invalid username or password"}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment