Mdp jamalette
This commit is contained in:
parent
e64c3ca948
commit
d2494a3483
4 changed files with 57 additions and 10 deletions
|
@ -26,16 +26,25 @@ class Connection extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit = (event) => {
|
handleSubmit = (event) => {
|
||||||
|
if (this.props.forJamalette){
|
||||||
|
this.handleSubmitJamalette(event)
|
||||||
|
}else{
|
||||||
|
this.handleSubmitLogin(event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSubmitJamalette = (event) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
console.log(this.state.password);
|
console.log(this.state.password);
|
||||||
|
|
||||||
let bodyFormData = new FormData();
|
let bodyFormData = new FormData();
|
||||||
bodyFormData.set('identifyer',this.state.identifyer);
|
bodyFormData.set('identifyer',"jamalette");
|
||||||
bodyFormData.set('password',this.state.password)
|
bodyFormData.set('password',this.state.password)
|
||||||
|
|
||||||
|
|
||||||
axios.post('https://etud.insa-toulouse.fr/~proximo/v2/api/login',bodyFormData)
|
axios.post('https://etud.insa-toulouse.fr/~proximo/v2/api/login',bodyFormData)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
sessionStorage.setItem('token',res.data.api_token)
|
sessionStorage.setItem('token_jamalette',res.data.api_token)
|
||||||
this.setState({redirect:true})
|
this.setState({redirect:true})
|
||||||
console.log(res.data.api_token);
|
console.log(res.data.api_token);
|
||||||
})
|
})
|
||||||
|
@ -47,6 +56,30 @@ class Connection extends Component {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleSubmitLogin = (event) => {
|
||||||
|
event.preventDefault()
|
||||||
|
console.log(this.state.password);
|
||||||
|
|
||||||
|
let bodyFormData = new FormData();
|
||||||
|
bodyFormData.set('identifyer',this.state.identifyer);
|
||||||
|
bodyFormData.set('password',this.state.password)
|
||||||
|
|
||||||
|
|
||||||
|
axios.post('https://etud.insa-toulouse.fr/~proximo/v2/api/login',bodyFormData)
|
||||||
|
.then(res => {
|
||||||
|
sessionStorage.setItem('token_login',res.data.api_token)
|
||||||
|
this.setState({redirect:true})
|
||||||
|
console.log(res.data.api_token);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
if(error.response.status === 401){
|
||||||
|
this.setState({errors:error.response.data.errors})
|
||||||
|
}
|
||||||
|
console.log(error.response);
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (this.state.redirect){
|
if (this.state.redirect){
|
||||||
return (<Redirect to="/stock"/>)
|
return (<Redirect to="/stock"/>)
|
||||||
|
@ -55,13 +88,14 @@ class Connection extends Component {
|
||||||
<div id="transp">
|
<div id="transp">
|
||||||
<div id="formBody">
|
<div id="formBody">
|
||||||
<div id="formHead">
|
<div id="formHead">
|
||||||
<div id="formHeadTxt">Connexion</div>
|
<div id="formHeadTxt">{this.props.title}</div>
|
||||||
<div id="crossClose" onClick={this.props.handleCloseAbove}>
|
<div id="crossClose" onClick={this.props.handleCloseAbove}>
|
||||||
<Icon icon={plusIcon} style={{transform : 'rotate(-45deg)', color: '#ffffff', fontSize: '3vw'}} />
|
<Icon icon={plusIcon} style={{transform : 'rotate(-45deg)', color: '#ffffff', fontSize: '3vw'}} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="formMainContent">
|
<div id="formMainContent">
|
||||||
<form method='POST' onSubmit={this.handleSubmit}>
|
<form method='POST' onSubmit={this.handleSubmit}>
|
||||||
|
{!this.props.forJamalette ?
|
||||||
<div id="identifyerBlock">
|
<div id="identifyerBlock">
|
||||||
<div id="identifyerBlockInput">
|
<div id="identifyerBlockInput">
|
||||||
<label htmlFor="identifyerBox">Identifiant</label>
|
<label htmlFor="identifyerBox">Identifiant</label>
|
||||||
|
@ -70,7 +104,7 @@ class Connection extends Component {
|
||||||
<div id="errorIdentifyerBlock">
|
<div id="errorIdentifyerBlock">
|
||||||
<p id="errorIdentifyer">{this.state.errors.identifyer}</p>
|
<p id="errorIdentifyer">{this.state.errors.identifyer}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div> : null }
|
||||||
<div id="passwordBlock">
|
<div id="passwordBlock">
|
||||||
<div id="passwordBlockInput">
|
<div id="passwordBlockInput">
|
||||||
<label htmlFor="passwordBox">Mot de Passe</label>
|
<label htmlFor="passwordBox">Mot de Passe</label>
|
||||||
|
|
|
@ -32,7 +32,7 @@ class Home extends React.Component {
|
||||||
/* Appel du composant Connection qui affiche l'interface de connexion
|
/* Appel du composant Connection qui affiche l'interface de connexion
|
||||||
Paramètres :
|
Paramètres :
|
||||||
handleCloseAbove : gère la fermeture du composant */
|
handleCloseAbove : gère la fermeture du composant */
|
||||||
<Connection handleCloseAbove={this.handleCloseConnection}/>
|
<Connection handleCloseAbove={this.handleCloseConnection} title="Connexion" forJamalette={false}/>
|
||||||
}
|
}
|
||||||
{/* Appel du composant Header qui affiche le Header du site
|
{/* Appel du composant Header qui affiche le Header du site
|
||||||
Paramètre : title : texte intérieur */}
|
Paramètre : title : texte intérieur */}
|
||||||
|
|
|
@ -175,7 +175,7 @@ getBulleById = (id) => {
|
||||||
let element;
|
let element;
|
||||||
let articles = document.getElementById("articles")
|
let articles = document.getElementById("articles")
|
||||||
for (let i = 0; i < articles.childElementCount ; i++){
|
for (let i = 0; i < articles.childElementCount ; i++){
|
||||||
if (id == articles.children[i].title){
|
if (id === articles.children[i].title){
|
||||||
element = articles.children[i]
|
element = articles.children[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -485,7 +485,7 @@ updateArticle = (index,id) => {
|
||||||
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (!sessionStorage.getItem('token')){
|
if (!sessionStorage.getItem('token_login')){
|
||||||
return (<div id="errorRouteBlock"><div id="errorRouteTitle">ERREUR </div><br/><div id="errorRouteTxt">Vous n'êtes pas connecté</div><br/><Link id="link" to='/'>Retourner à l'Accueil</Link></div>)
|
return (<div id="errorRouteBlock"><div id="errorRouteTitle">ERREUR </div><br/><div id="errorRouteTxt">Vous n'êtes pas connecté</div><br/><Link id="link" to='/'>Retourner à l'Accueil</Link></div>)
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -11,6 +11,7 @@ import ArticleDetails from '../Components/ArticleDetails';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import NotInBdd from '../Components/NotInBdd';
|
import NotInBdd from '../Components/NotInBdd';
|
||||||
import Money from '../Components/Money';
|
import Money from '../Components/Money';
|
||||||
|
import Connection from '../Components/Connection';
|
||||||
|
|
||||||
export default class Stock extends React.Component {
|
export default class Stock extends React.Component {
|
||||||
|
|
||||||
|
@ -24,7 +25,8 @@ export default class Stock extends React.Component {
|
||||||
totalPrice:0,
|
totalPrice:0,
|
||||||
totalQuantity:0,
|
totalQuantity:0,
|
||||||
redirect:false,
|
redirect:false,
|
||||||
onNotInBdd:false
|
onNotInBdd:false,
|
||||||
|
onConnection:false
|
||||||
}
|
}
|
||||||
|
|
||||||
this.handleScan = this.handleScan.bind(this);
|
this.handleScan = this.handleScan.bind(this);
|
||||||
|
@ -122,7 +124,11 @@ export default class Stock extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleScan(code) {
|
handleScan(code) {
|
||||||
this.getArticleByCode(code)
|
if (!sessionStorage.getItem('token_jamalette')){
|
||||||
|
this.setState({onConnection:true,scannedCode:code})
|
||||||
|
} else {
|
||||||
|
this.getArticleByCode(code)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
colorArticle = (color,element) => {
|
colorArticle = (color,element) => {
|
||||||
|
@ -184,8 +190,12 @@ export default class Stock extends React.Component {
|
||||||
this.setState({onMoney:false})
|
this.setState({onMoney:false})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleCloseConnection = () => {
|
||||||
|
this.setState({onConnection:false},()=>{this.getArticleByCode(this.state.scannedCode)})
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (!sessionStorage.getItem('token')){
|
if (!sessionStorage.getItem('token_login')){
|
||||||
return (<div id="errorRouteBlock"><div id="errorRouteTitle">ERREUR </div><br/><div id="errorRouteTxt">Vous n'êtes pas connecté</div><br/><Link id="link" to='/'>Retourner à l'Accueil</Link></div>)
|
return (<div id="errorRouteBlock"><div id="errorRouteTitle">ERREUR </div><br/><div id="errorRouteTxt">Vous n'êtes pas connecté</div><br/><Link id="link" to='/'>Retourner à l'Accueil</Link></div>)
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
|
@ -194,6 +204,9 @@ export default class Stock extends React.Component {
|
||||||
<Navbar redirect="/stock" left="Monnaie" right="Le Stock" handleMoney={this.handleMoney}/>
|
<Navbar redirect="/stock" left="Monnaie" right="Le Stock" handleMoney={this.handleMoney}/>
|
||||||
<BarcodeReader onScan={this.handleScan}/>
|
<BarcodeReader onScan={this.handleScan}/>
|
||||||
<SearchBar/>
|
<SearchBar/>
|
||||||
|
{this.state.onConnection &&
|
||||||
|
<Connection handleCloseAbove={this.handleCloseConnection} title="Jamalette" forJamalette={true}/>
|
||||||
|
}
|
||||||
{this.state.onMoney &&
|
{this.state.onMoney &&
|
||||||
<Money empty={this.state.empty} handleCloseAbove={this.handleCloseMoney} totalPrice={this.state.totalPrice}/>
|
<Money empty={this.state.empty} handleCloseAbove={this.handleCloseMoney} totalPrice={this.state.totalPrice}/>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue