blob: 60f718e43f18df80630e79805fc29217b9292782 [file] [log] [blame]
Iftekharul Islam99d199f2017-03-24 15:28:25 -05001/**
2 * userModel
3 *
4 * @module app/common/services/userModel
5 * @exports userModel
6 * @name userModel
7
8 * @version 0.0.1
9 */
10
11window.angular && (function (angular) {
12 'use strict';
13
14 angular
15 .module('app.common.services')
16 .service('userModel', ['APIUtils',function(APIUtils){
17 return {
Michael Davisdfad5d52017-07-20 14:53:46 -050018<<<<<<< HEAD
Iftekharul Islambb5058e2017-03-29 13:54:26 -050019 fakeLogin: function(callback){
20 sessionStorage.setItem('LOGIN_ID', 'FAKE_ID');
21 },
Michael Davisdfad5d52017-07-20 14:53:46 -050022=======
23>>>>>>> 4c1a3dd... Major update to code structure
Iftekharul Islam99d199f2017-03-24 15:28:25 -050024 login : function(username, password, callback){
25 APIUtils.login(username, password, function(response, error){
26 if(response &&
27 response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS){
28 sessionStorage.setItem('LOGIN_ID', username);
29 callback(true);
30 }else{
31 callback(false, error);
32 }
33 });
34 },
35 isLoggedIn : function(){
36 if(sessionStorage.getItem('LOGIN_ID') === null){
37 return false;
38 }
39 return true;
40 },
41 logout : function(callback){
42 APIUtils.logout(function(response, error){
43 if(response &&
44 response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS){
45 sessionStorage.removeItem('LOGIN_ID');
46 callback(true);
Iftekharul Islam99d199f2017-03-24 15:28:25 -050047 }else{
48 callback(false, error);
49 }
50 });
51 }
52 };
53 }]);
54
55})(window.angular);