Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 1 | /** |
| 2 | * userModel |
| 3 | * |
| 4 | * @module app/common/services/userModel |
| 5 | * @exports userModel |
| 6 | * @name userModel |
| 7 | |
| 8 | * @version 0.0.1 |
| 9 | */ |
| 10 | |
| 11 | window.angular && (function (angular) { |
| 12 | 'use strict'; |
| 13 | |
| 14 | angular |
| 15 | .module('app.common.services') |
| 16 | .service('userModel', ['APIUtils',function(APIUtils){ |
| 17 | return { |
Michael Davis | dfad5d5 | 2017-07-20 14:53:46 -0500 | [diff] [blame^] | 18 | <<<<<<< HEAD |
Iftekharul Islam | bb5058e | 2017-03-29 13:54:26 -0500 | [diff] [blame] | 19 | fakeLogin: function(callback){ |
| 20 | sessionStorage.setItem('LOGIN_ID', 'FAKE_ID'); |
| 21 | }, |
Michael Davis | dfad5d5 | 2017-07-20 14:53:46 -0500 | [diff] [blame^] | 22 | ======= |
| 23 | >>>>>>> 4c1a3dd... Major update to code structure |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 24 | 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 Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 47 | }else{ |
| 48 | callback(false, error); |
| 49 | } |
| 50 | }); |
| 51 | } |
| 52 | }; |
| 53 | }]); |
| 54 | |
| 55 | })(window.angular); |