1/**
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 {
18                fakeLogin: function(callback){
19                    sessionStorage.setItem('LOGIN_ID', 'FAKE_ID');
20                },
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);
44                        }else{
45                            callback(false, error);
46                        }
47                    });
48                }
49            };
50        }]);
51
52})(window.angular);