{ "version": 3, "sources": ["../ui/app/mn_auth/mn_auth_service.js"], "sourcesContent": ["/*\nCopyright 2015-Present Couchbase, Inc.\n\nUse of this software is governed by the Business Source License included in\nthe file licenses/BSL-Couchbase.txt. As of the Change Date specified in that\nfile, in accordance with the Business Source License, use of this software will\nbe governed by the Apache License, Version 2.0, included in the file\nlicenses/APL2.txt.\n*/\n\nimport angular from \"angular\";\nimport uiRouter from \"@uirouter/angularjs\";\nimport mnPools from \"../components/mn_pools.js\";\nimport _ from \"lodash\";\n\nexport default 'mnAuthService';\n\nangular\n .module('mnAuthService', [mnPools, uiRouter])\n .factory('mnAuthService', [\"mnPools\", \"$http\", \"$uibModalStack\", \"$window\", \"$q\", mnAuthServiceFactory]);\n\nfunction mnAuthServiceFactory(mnPools, $http, $uibModalStack, $window, $q) {\n var mnAuthService = {\n login: login,\n logout: _.once(logout),\n whoami: whoami,\n canUseCertForAuth: canUseCertForAuth\n };\n\n return mnAuthService;\n\n function whoami() {\n return $http({\n method: 'GET',\n cache: true,\n url: '/whoami'\n }).then(function (resp) {\n return resp.data;\n });\n }\n\n function canUseCertForAuth() {\n return $http({\n method: 'GET',\n url: '/_ui/canUseCertForAuth'\n }).then(function (r) {\n return r.data;\n });\n }\n\n function login(user, useCertForAuth) {\n var config = {\n method: 'POST',\n url: '/uilogin'\n }\n\n if (useCertForAuth) {\n config.params = {\n use_cert_for_auth: 1\n };\n } else {\n user = user || {};\n config.data = {\n user: user.username,\n password: user.password\n };\n }\n\n return $http(config).then(function (resp) {\n return mnPools.get().then(function (cachedPools) {\n mnPools.clearCache();\n return mnPools.get().then(function (newPools) {\n if (cachedPools.implementationVersion !== newPools.implementationVersion) {\n return $q.reject({status: 410});\n } else {\n return resp;\n }\n });\n }).then(function (resp) {\n localStorage.setItem(\"mnLogIn\",\n Number(localStorage.getItem(\"mnLogIn\") || \"0\") + 1);\n return resp;\n })\n });\n }\n\n function logout() {\n $uibModalStack.dismissAll(\"uilogout\");\n return $http({\n method: 'POST',\n url: \"/uilogout\"\n }).then(function () {\n $window.location.reload();\n }, function () {\n $window.location.reload();\n });\n }\n}\n"], "mappings": "wOAeA,GAAO,yBAAQ,gBAEf,UACG,OAAO,gBAAiB,CAAC,iBAAS,oBAClC,QAAQ,gBAAiB,CAAC,UAAW,QAAS,iBAAkB,UAAW,KAAM,uBAEpF,8BAA8B,QAAS,MAAO,eAAgB,QAAS,GAAI,CACzE,GAAI,eAAgB,CAClB,MACA,OAAQ,eAAE,KAAK,QACf,OACA,mBAGF,MAAO,eAEP,iBAAkB,CAChB,MAAO,OAAM,CACX,OAAQ,MACR,MAAO,GACP,IAAK,YACJ,KAAK,SAAU,KAAM,CACtB,MAAO,MAAK,OAIhB,4BAA6B,CAC3B,MAAO,OAAM,CACX,OAAQ,MACR,IAAK,2BACJ,KAAK,SAAU,EAAG,CACnB,MAAO,GAAE,OAIb,eAAe,KAAM,eAAgB,CACnC,GAAI,QAAS,CACX,OAAQ,OACR,IAAK,YAGP,MAAI,gBACF,OAAO,OAAS,CACd,kBAAmB,GAGrB,MAAO,MAAQ,GACf,OAAO,KAAO,CACZ,KAAM,KAAK,SACX,SAAU,KAAK,WAIZ,MAAM,QAAQ,KAAK,SAAU,KAAM,CACxC,MAAO,SAAQ,MAAM,KAAK,SAAU,YAAa,CAC/C,eAAQ,aACD,QAAQ,MAAM,KAAK,SAAU,SAAU,CAC5C,MAAI,aAAY,wBAA0B,SAAS,sBAC1C,GAAG,OAAO,CAAC,OAAQ,MAEnB,SAGV,KAAK,SAAU,MAAM,CACtB,oBAAa,QAAQ,UACA,OAAO,aAAa,QAAQ,YAAc,KAAO,GAC/D,UAKb,iBAAkB,CAChB,sBAAe,WAAW,YACnB,MAAM,CACX,OAAQ,OACR,IAAK,cACJ,KAAK,UAAY,CAClB,QAAQ,SAAS,UAChB,UAAY,CACb,QAAQ,SAAS,YAzEd", "names": [] }