Commit 0ad2a4c6 authored by Evren Kutar's avatar Evren Kutar

login service & session

parent f8661091
/**
* Created by evren kutar on 12/05/15.
*/
"use strict";
// TODO: login url cheange with correct one
angular.factory('LoginService', function ($http, Session) {
var loginService = {};
loginService.login = function (credentials) {
return $http
.post('http://127.0.0.1:8000/login', credentials)
.then(function (res) {
Session.create(res.data.id, res.data.user.id,
res.data.user.role);
return res.data.user;
});
};
authService.isAuthenticated = function () {
return !!Session.userId;
};
authService.isAuthorized = function (authorizedRoles) {
if (!angular.isArray(authorizedRoles)) {
authorizedRoles = [authorizedRoles];
}
return (authService.isAuthenticated() &&
authorizedRoles.indexOf(Session.userRole) !== -1);
};
return authService;
});
// TODO: initial service not working!!
angular.service('Session', function () {
this.create = function (sessionId, userId, userRole) {
this.id = sessionId;
this.userId = userId;
this.userRole = userRole;
};
this.destroy = function () {
this.id = null;
this.userId = null;
this.userRole = null;
};
});
\ No newline at end of file
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