Skip to content

Instantly share code, notes, and snippets.

@robwormald
Forked from anonymous/gist:a95a23564c6d9f07e48b
Last active August 29, 2015 14:04
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 robwormald/1bf9d99be36ef24f788e to your computer and use it in GitHub Desktop.
Save robwormald/1bf9d99be36ef24f788e to your computer and use it in GitHub Desktop.
var myApp = angular.module('myApp');
myApp.service('Auth', function($http) {
this.onLoginSuccess = function(loginResponse){
TokenHandler.setToken(loginResponse.data.token);
return ({success:1, msg: "Logged in refreshing ....", type:"success"})
},
this.onLoginFailure = function(loginError){
return ({success:0, msg: "LError Loggin in", type:"danger"})
}
this.login = function(user_name, pass) {
var Auth = this;
return $http({
url: 'http://127.0.0.1:8000/api-token-auth/',
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
data: {
username: user_name,
password: pass,
}
}).then(Auth.onLoginResponse,Auth.onLoginError);
},
this.logOut = function() {}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment