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