blob: f82c1f12341054f45405754baeee215f47e703c3 [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 Islam99d199f2017-03-24 15:28:25 -050018 login : function(username, password, callback){
19 APIUtils.login(username, password, function(response, error){
Ed Tanousbbcf6702017-10-06 13:53:06 -070020 if(response &&
21 (response.status == APIUtils.API_RESPONSE.SUCCESS_STATUS
22 || response.status === undefined)){
Iftekharul Islam99d199f2017-03-24 15:28:25 -050023 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 Islam1acb4122017-11-02 13:20:32 -050041 sessionStorage.removeItem(APIUtils.HOST_SESSION_STORAGE_KEY);
Iftekharul Islam99d199f2017-03-24 15:28:25 -050042 callback(true);
Iftekharul Islamec6bcd12017-09-06 10:49:07 -050043 }else if(response.status == APIUtils.API_RESPONSE.ERROR_STATUS){
44 callback(false);
Iftekharul Islam99d199f2017-03-24 15:28:25 -050045 }else{
46 callback(false, error);
47 }
48 });
49 }
50 };
51 }]);
52
Ed Tanousbbcf6702017-10-06 13:53:06 -070053})(window.angular);