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 { |
| 18 | login : function(username, password, callback){ |
| 19 | APIUtils.login(username, password, function(response, error){ |
| 20 | if(response && |
| 21 | response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS){ |
| 22 | sessionStorage.setItem('LOGIN_ID', username); |
| 23 | callback(true); |
| 24 | }else{ |
| 25 | callback(false, error); |
| 26 | } |
| 27 | }); |
| 28 | }, |
| 29 | isLoggedIn : function(){ |
| 30 | if(sessionStorage.getItem('LOGIN_ID') === null){ |
| 31 | return false; |
| 32 | } |
| 33 | return true; |
| 34 | }, |
| 35 | logout : function(callback){ |
| 36 | APIUtils.logout(function(response, error){ |
| 37 | if(response && |
| 38 | response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS){ |
| 39 | sessionStorage.removeItem('LOGIN_ID'); |
| 40 | callback(true); |
| 41 | }else{ |
| 42 | callback(false, error); |
| 43 | } |
| 44 | }); |
| 45 | } |
| 46 | }; |
| 47 | }]); |
| 48 | |
| 49 | })(window.angular); |