This repository has been archived by the owner on Sep 20, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Agrega estado de autenticación para el front
- Loading branch information
Showing
11 changed files
with
330 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,38 @@ | ||
import axios from 'axios'; | ||
import { obtenerSession } from '../sesion'; | ||
|
||
export default class Backend { | ||
static login(email) { | ||
return axios.post(`/login`, { email }); | ||
} | ||
static login(email) { | ||
return axios.post(`/login`, { email }); | ||
} | ||
|
||
static cancelarSolicitud({ _id }) { | ||
return axios.patch(`/solicitudes/${_id}/cancelar`, {email: 'pepito@gmail.com'}).then(res => res.data); | ||
} | ||
static _tokenUsuario() { | ||
const usuario = obtenerSession(); | ||
const headers = { headers: { 'token-usuario': usuario.token } }; | ||
return { usuario, headers }; | ||
} | ||
|
||
static guardarSolicitud({ email, area, insumo }) { | ||
return axios.post(`/solicitudes`, { email, area, insumo }); | ||
} | ||
static usuarios() { | ||
return axios.get('/usuarios', this._tokenUsuario().headers); | ||
} | ||
|
||
static crearUsuario(nuevoUsuario) { | ||
return axios.post(`/usuarios`,nuevoUsuario , this._tokenUsuario().headers); | ||
} | ||
|
||
static solicitudes() { | ||
return axios.get('/solicitudes', this._tokenUsuario().headers); | ||
} | ||
|
||
static cancelarSolicitud({ _id }) { | ||
let { usuario, headers } = this._tokenUsuario(); | ||
|
||
return axios.patch(`/solicitudes/${_id}/cancelar`, | ||
{ email: usuario.email }, headers).then(res => res.data); | ||
} | ||
|
||
static guardarSolicitud({ email, area, insumo }) { | ||
return axios.post(`/solicitudes`, { email, area, insumo }, | ||
this._tokenUsuario().headers); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { Redirect, Route } from 'react-router-dom'; | ||
import UsuarioContext from './UsuarioContext'; | ||
|
||
class RutaAutenticada extends React.Component { | ||
render() { | ||
return <UsuarioContext.Consumer> | ||
{contexto => { | ||
return !contexto.logueado ? | ||
<Redirect to="/"/> : | ||
<Route {...this.props}/>; | ||
}} | ||
</UsuarioContext.Consumer>; | ||
} | ||
} | ||
|
||
UsuarioContext.contextType = RutaAutenticada; | ||
|
||
export default RutaAutenticada; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
|
||
const UsuarioContext = React.createContext({ // valores defaults | ||
logueado: false, | ||
usuario: { token: '', email: '' }, | ||
guardarUsuario: (usuario) => ({ usuario }), | ||
}, | ||
); | ||
|
||
UsuarioContext.displayName = 'UsuarioContext'; | ||
|
||
export default UsuarioContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.