{"version":3,"sources":["AuthService.js","AuthService_primero.js"],"names":["global","render","AuthService","constructor","domain","this","globales","ip","fetch","bind","login","getProfile","tokenGoo","username","password","sucursal","descrip_sucursal","method","body","JSON","stringify","then","res","token","setToken","localStorage","setItem","notificaciones","pendientes_alumno","matricula","cuotas","toda_factura","usuario","like","parse","LIKES","Promise","resolve","get_render","set_render","r","loggedIn","_this","async","reject","getToken","bol","Request","get","set","end","err","undefined","tmp","text","idToken","getItem","getglobal","logout","removeItem","decode","error","url","options","headers","_checkStatus","response","json","status","Error","statusText","jwt","require","AuthService_primero","mensaje","ver","verify","decoded"],"mappings":"+MAAA,+EAIA,IAAIA,EACAC,EAEW,MAAMC,EAEjBC,YAAYC,GACRC,KAAKD,OAASA,GAAUE,IAASC,GACjCF,KAAKG,MAAQH,KAAKG,MAAMC,KAAKJ,MAC7BA,KAAKK,MAAQL,KAAKK,MAAMD,KAAKJ,MAC7BA,KAAKM,WAAaN,KAAKM,WAAWF,KAAKJ,KAC3C,CAEJK,MAAME,EAASC,EAAUC,EAAUC,EAAUC,GAEzC,OAAOX,KAAKG,MAAM,GAAGH,KAAKD,uBAAwB,CAC1Ca,OAAQ,OACRC,KAAMC,KAAKC,UAAU,CACjBR,WACAC,WACAC,WACAC,WACAC,uBAELK,MAAKC,IAEc,oBAAdA,EAAIC,QAIJD,EAAIC,MAGO,YAAZD,EAAIC,OACPlB,KAAKmB,SAASF,EAAIC,OAElBE,aAAaC,QAAQ,iBAAkBP,KAAKC,UAAUE,EAAIK,iBAE7DC,IAAkBC,UAAUP,EAAIO,UAC7BD,IAAkBE,OAAOR,EAAIQ,OAC7BF,IAAkBG,aAAaT,EAAIS,aAEpB,YAAZT,EAAIC,QACPS,IAAQC,KAAKd,KAAKe,MAAMZ,EAAIa,SAhBjBC,QAAQC,QAAQf,KAoBnC,CAEAgB,aACI,OAAOrC,CACX,CACAsC,WAAWC,GACPvC,EAAOuC,CACX,CAuBAC,WACA,MAAMC,EAAQrC,KACd,OAAO,I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K,SAAWA,EACXL,CAEd,E","file":"static/js/main~06837ae4.989e9752.chunk.js","sourcesContent":["import decode from 'jwt-decode';\r\nimport {globales,pendientes_alumno,usuario} from './global'\r\nimport Request from 'superagent';\r\n\r\nlet global;\r\nlet render;\r\n\r\nexport default class AuthService {\r\n // Initializing important variables\r\n constructor(domain) {\r\n this.domain = domain || globales.ip // API server domain\r\n this.fetch = this.fetch.bind(this) // React binding stuff\r\n this.login = this.login.bind(this)\r\n this.getProfile = this.getProfile.bind(this)\r\n }\r\n\r\nlogin(tokenGoo,username, password, sucursal, descrip_sucursal) { // Get a token from api server using the fetch api\r\n //console.log(tokenGoo) \r\n return this.fetch(`${this.domain}/generar_token`, {\r\n method: 'POST',\r\n body: JSON.stringify({\r\n tokenGoo,\r\n username,\r\n password,\r\n sucursal,\r\n descrip_sucursal,\r\n })\r\n }).then(res => {\r\n //console.log(res)\r\n if( res.token === \"Not_information\" ){\r\n return Promise.resolve(res);\r\n }\r\n\r\n if( res.token !== \"Authentication_Failed\" ){\r\n }\r\n \r\n if(res.token!=='INTERNO')\r\n this.setToken(res.token) // Setting the token in localStorage\r\n\r\n localStorage.setItem('notificaciones', JSON.stringify(res.notificaciones))\r\n\r\n\t pendientes_alumno.matricula=res.matricula;\r\n pendientes_alumno.cuotas=res.cuotas;\r\n pendientes_alumno.toda_factura=res.toda_factura;\r\n\r\n if(res.token!=='INTERNO')\r\n usuario.like=JSON.parse(res.LIKES);\r\n \r\n return Promise.resolve(res);\r\n })\r\n }\r\n\r\n get_render(){\r\n return render;\r\n }\r\n set_render(r){\r\n render=r;\r\n }\r\n /*\r\n ver() {\r\n const _this = this\r\n return new Promise(async function (resolve, reject) { \r\n const token = _this.getToken()\r\n var bol;\r\n if(token!==null)\r\n Request.get(`${globales.ip}/verifica_token/`).set({'authorization': 'Bearer '+token})\r\n .end((err, res)=>{\r\n const tmp = JSON.parse(res.text);\r\n if(tmp){\r\n bol= true;\r\n }\r\n else{\r\n bol= false;\r\n }\r\n resolve(global=bol); \r\n })\r\n \r\n });\r\n }\r\n */\r\n loggedIn() { // Checks if there is a saved token and it's still valid\r\n const _this = this\r\n return new Promise(async function (resolve, reject) { \r\n const token = _this.getToken()\r\n \r\n var bol;\r\n if(token!==null)\r\n {\r\n Request.get(`${globales.ip}/verifica_token/`).set({'authorization': 'Bearer '+token})\r\n .end((err, res) => {\r\n\t\t if (err) { return resolve(false); }\r\n if(res!==undefined){\r\n const tmp = JSON.parse(res.text);\r\n if(tmp){\r\n bol= true;\r\n }\r\n else{\r\n bol= false;\r\n }\r\n }\r\n else\r\n bol= false;\r\n\r\n global=bol\r\n resolve(global); \r\n })\r\n }\r\n else{\r\n global=false\r\n resolve(false);\r\n }\r\n /*if(token!==null)\r\n {\r\n resolve(true);\r\n }\r\n else{\r\n resolve(false); \r\n }*/\r\n });\r\n //this.ver()\r\n //return global\r\n }\r\n \r\n setToken(idToken) { // Saves user token to localStorage\r\n localStorage.setItem('id_token', idToken)\r\n }\r\n\r\n getToken() { // Retrieves the user token from localStorage\r\n return localStorage.getItem('id_token')\r\n }\r\n\r\n getglobal(){\r\n return global;\r\n }\r\n\r\n logout() {// Clear user token and profile data from localStorage\r\n\r\n localStorage.removeItem('id_token');\r\n localStorage.removeItem('usuario');\r\n localStorage.removeItem('estado_menu');\r\n\t localStorage.removeItem('Tabs_user');\r\n }\r\n\r\n getProfile() { // Using jwt-decode npm package to decode the token\r\n var token=this.getToken();\r\n if(token!==null){\r\n try{\r\n return decode(token);\r\n }\r\n catch(error){\r\n return ''\r\n }\r\n }\r\n else\r\n return ''\r\n }\r\n\r\n fetch(url, options){// performs api calls sending the required authentication headers\r\n const headers = {\r\n 'Accept': 'application/json',\r\n 'Content-Type': 'application/json'\r\n }\r\n // Setting Authorization header\r\n if (this.loggedIn()) {\r\n headers['Authorization'] = 'Bearer ' + this.getToken()\r\n }\r\n return fetch(url, {\r\n headers,\r\n ...options\r\n }).then(this._checkStatus).then(response => response.json())\r\n }\r\n\r\n _checkStatus(response) { // raises an error in case response status is not a success\r\n if (response.status >= 200 && response.status < 300) { // Success status lies between 200 to 300\r\n return response\r\n } else {\r\n var error = new Error(response.statusText)\r\n error.response = response\r\n throw error\r\n }\r\n }\r\n}","import decode from 'jwt-decode';\r\nimport {globales} from './global'\r\nconst jwt = require('jsonwebtoken');\r\n\r\nlet global;\r\n\r\nexport default class AuthService_primero {\r\n // Initializing important variables\r\n constructor(domain) {\r\n this.domain = domain || globales.ip // API server domain\r\n this.fetch = this.fetch.bind(this) // React binding stuff\r\n this.login = this.login.bind(this)\r\n this.getProfile = this.getProfile.bind(this)\r\n }\r\n login(username, password) { // Get a token from api server using the fetch api\r\n //console.log('obtener_sucursal');\r\n return this.fetch(`${this.domain}/obtener_sucursal`, {\r\n method: 'POST',\r\n body: JSON.stringify({\r\n username\r\n })\r\n }).then(res => {\r\n if( res.mensaje !== \"Authentication_Failed\" ){\r\n localStorage.setItem('usuario', username)\r\n return res;\r\n }\r\n return Promise.resolve(res);\r\n })\r\n }\r\n\r\n ver() {\r\n const _this = this\r\n return new Promise(function (resolve, reject) { \r\n const token = _this.getToken()\r\n \r\n var bol;\r\n jwt.verify(token, 'abc+123', function(err, decoded) {\r\n if(err!==null)\r\n {\r\n bol= false;\r\n }\r\n else\r\n {\r\n bol= true;\r\n }\r\n });\r\n ;\r\n resolve(global=bol); \r\n });\r\n }\r\n loggedIn() { // Checks if there is a saved token and it's still valid\r\n const token = this.getToken() // GEtting token from localstorage \r\n this.ver().then(function (){\r\n })\r\n if(token!==null && global===true )\r\n {\r\n return global;\r\n }\r\n else{\r\n return global;\r\n } \r\n }\r\n\r\n getToken() { // Retrieves the user token from localStorage\r\n return localStorage.getItem('id_token')\r\n }\r\n logout() {// Clear user token and profile data from localStorage\r\n localStorage.removeItem('id_token');\r\n localStorage.removeItem('usuario');\r\n localStorage.removeItem('estado_menu'); \r\n }\r\n getProfile() { // Using jwt-decode npm package to decode the token\r\n return decode(this.getToken());\r\n }\r\n fetch(url, options){// performs api calls sending the required authentication headers\r\n const headers = {\r\n 'Accept': 'application/json',\r\n 'Content-Type': 'application/json'\r\n }\r\n // Setting Authorization header\r\n if (this.loggedIn()) {\r\n headers['Authorization'] = 'Bearer ' + this.getToken()\r\n }\r\n return fetch(url, {\r\n headers,\r\n ...options\r\n })\r\n .then(this._checkStatus)\r\n .then(response => response.json())\r\n }\r\n _checkStatus(response) { // raises an error in case response status is not a success\r\n if (response.status >= 200 && response.status < 300) { // Success status lies between 200 to 300\r\n return response\r\n } else {\r\n var error = new Error(response.statusText)\r\n error.response = response\r\n throw error\r\n }\r\n }\r\n}"],"sourceRoot":""}