Commit 395231f1 authored by Evren Kutar's avatar Evren Kutar

if login case change path to dashboard and create session object

parent 054e0b5a
...@@ -61,10 +61,10 @@ login.controller('LoginCtrl', function ($scope, $http, $location, $rootScope, AU ...@@ -61,10 +61,10 @@ login.controller('LoginCtrl', function ($scope, $http, $location, $rootScope, AU
$scope.$broadcast('schemaFormValidate'); $scope.$broadcast('schemaFormValidate');
if (form.$valid){ if (form.$valid){
var credentials = {email: form.email.modelValue, password: form.password.modelValue}; var credentials = {email: form.email.$modelValue, password: form.password.$modelValue};
console.log(form);
var loginResponse = LoginService.login(credentials); var loginResponse = LoginService.login(credentials);
console.log(loginResponse.value); console.log(loginResponse);
} }
else { else {
console.log("not valid"); console.log("not valid");
......
...@@ -10,21 +10,24 @@ login.factory('LoginService', function ($http, $rootScope, $location, Session) { ...@@ -10,21 +10,24 @@ login.factory('LoginService', function ($http, $rootScope, $location, Session) {
var loginService = {}; var loginService = {};
loginService.login = function (credentials) { loginService.login = function (credentials) {
// TODO: change this getParams var to service to use app-wide
var getParams = "?";
for (var k in credentials){
getParams += k+"="+credentials[k]+"&";
}
return $http return $http
.post('http://127.0.0.1:8000/login', credentials) .get('http://127.0.0.1:8000/login' + getParams)
.then(function (res) { .then(function (res) {
if (res.data.success){
$rootScope.loggedInUser = true;
$location.path("/dashboard");
Session.create(res.data.id, res.data.user.id, Session.create(res.data.id, res.data.user.id,
res.data.user.role); res.data.user.role);
return res.data.user; return res.data.user;
}
}); });
}; };
loginService.changePath = function () {
$rootScope.loggedInUser = true;
$location.path("/dashboard");
};
loginService.isAuthenticated = function () { loginService.isAuthenticated = function () {
return !!Session.userId; return !!Session.userId;
}; };
......
...@@ -55,9 +55,7 @@ describe('zaerp.login module', function () { ...@@ -55,9 +55,7 @@ describe('zaerp.login module', function () {
it('should get login success', it('should get login success',
inject(function(LoginService, $httpBackend) { inject(function(LoginService, $httpBackend) {
// 204 because of access control allow origin $httpBackend.expectGET('http://127.0.0.1:8000/login?email=test@test.com&password=password&')
$httpBackend.expectPOST('http://127.0.0.1:8000/login', {email: "test@test.com", password: "password"})
.respond(204, {'id': 1, 'user': {'id': 12, 'role': 'admin'}}); .respond(204, {'id': 1, 'user': {'id': 12, 'role': 'admin'}});
var cred = {email: 'test@test.com', password: 'password'}; var cred = {email: 'test@test.com', password: 'password'};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment