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 { |
Iftekharul Islam | bb5058e | 2017-03-29 13:54:26 -0500 | [diff] [blame] | 18 | fakeLogin: function(callback){ |
| 19 | sessionStorage.setItem('LOGIN_ID', 'FAKE_ID'); |
| 20 | }, |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 21 | login : function(username, password, callback){ |
| 22 | APIUtils.login(username, password, function(response, error){ |
| 23 | if(response && |
| 24 | response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS){ |
| 25 | sessionStorage.setItem('LOGIN_ID', username); |
| 26 | callback(true); |
| 27 | }else{ |
| 28 | callback(false, error); |
| 29 | } |
| 30 | }); |
| 31 | }, |
| 32 | isLoggedIn : function(){ |
| 33 | if(sessionStorage.getItem('LOGIN_ID') === null){ |
| 34 | return false; |
| 35 | } |
| 36 | return true; |
| 37 | }, |
| 38 | logout : function(callback){ |
| 39 | APIUtils.logout(function(response, error){ |
| 40 | if(response && |
| 41 | response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS){ |
| 42 | sessionStorage.removeItem('LOGIN_ID'); |
| 43 | callback(true); |
Iftekharul Islam | ec6bcd1 | 2017-09-06 10:49:07 -0500 | [diff] [blame^] | 44 | }else if(response.status == APIUtils.API_RESPONSE.ERROR_STATUS){ |
| 45 | callback(false); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 46 | }else{ |
| 47 | callback(false, error); |
| 48 | } |
| 49 | }); |
| 50 | } |
| 51 | }; |
| 52 | }]); |
| 53 | |
| 54 | })(window.angular); |