blob: 2c9de650de4bc9c0f57a0d78b4cbb0acfc2f217d [file] [log] [blame]
Iftekharul Islam99d199f2017-03-24 15:28:25 -05001/**
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 {
Iftekharul Islambb5058e2017-03-29 13:54:26 -050018 fakeLogin: function(callback){
19 sessionStorage.setItem('LOGIN_ID', 'FAKE_ID');
20 },
Iftekharul Islam99d199f2017-03-24 15:28:25 -050021 login : function(username, password, callback){
22 APIUtils.login(username, password, function(response, error){
Ed Tanousbbcf6702017-10-06 13:53:06 -070023 if(response &&
24 (response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS
25 || response.status === undefined)){
Iftekharul Islam99d199f2017-03-24 15:28:25 -050026 sessionStorage.setItem('LOGIN_ID', username);
27 callback(true);
28 }else{
29 callback(false, error);
30 }
31 });
32 },
33 isLoggedIn : function(){
34 if(sessionStorage.getItem('LOGIN_ID') === null){
35 return false;
36 }
37 return true;
38 },
39 logout : function(callback){
40 APIUtils.logout(function(response, error){
41 if(response &&
42 response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS){
43 sessionStorage.removeItem('LOGIN_ID');
Iftekharul Islam1acb4122017-11-02 13:20:32 -050044 sessionStorage.removeItem(APIUtils.HOST_SESSION_STORAGE_KEY);
Iftekharul Islam99d199f2017-03-24 15:28:25 -050045 callback(true);
Iftekharul Islamec6bcd12017-09-06 10:49:07 -050046 }else if(response.status == APIUtils.API_RESPONSE.ERROR_STATUS){
47 callback(false);
Iftekharul Islam99d199f2017-03-24 15:28:25 -050048 }else{
49 callback(false, error);
50 }
51 });
52 }
53 };
54 }]);
55
Ed Tanousbbcf6702017-10-06 13:53:06 -070056})(window.angular);