blob: a3fc277df7c745d78638d0b5767bc5dc0235dc03 [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){
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');
Iftekharul Islam1acb4122017-11-02 13:20:32 -050043 sessionStorage.removeItem(APIUtils.HOST_SESSION_STORAGE_KEY);
Iftekharul Islam99d199f2017-03-24 15:28:25 -050044 callback(true);
Iftekharul Islamec6bcd12017-09-06 10:49:07 -050045 }else if(response.status == APIUtils.API_RESPONSE.ERROR_STATUS){
46 callback(false);
Iftekharul Islam99d199f2017-03-24 15:28:25 -050047 }else{
48 callback(false, error);
49 }
50 });
51 }
52 };
53 }]);
54
55})(window.angular);