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) => {
|
||||
if (this.props.forJamalette){
|
||||
this.handleSubmitJamalette(event)
|
||||
}else{
|
||||
this.handleSubmitLogin(event)
|
||||
}
|
||||
}
|
||||
|
||||
handleSubmitJamalette = (event) => {
|
||||
event.preventDefault()
|
||||
console.log(this.state.password);
|
||||
|
||||
let bodyFormData = new FormData();
|
||||
bodyFormData.set('identifyer',this.state.identifyer);
|
||||
bodyFormData.set('identifyer',"jamalette");
|
||||
bodyFormData.set('password',this.state.password)
|
||||
|
||||
|
||||
axios.post('https://etud.insa-toulouse.fr/~proximo/v2/api/login',bodyFormData)
|
||||
.then(res => {
|
||||
sessionStorage.setItem('token',res.data.api_token)
|
||||
sessionStorage.setItem('token_jamalette',res.data.api_token)
|
||||
this.setState({redirect:true})
|
||||
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() {
|
||||
if (this.state.redirect){
|
||||
return (<Redirect to="/stock"/>)
|
||||
|
@ -55,13 +88,14 @@ class Connection extends Component {
|
|||
<div id="transp">
|
||||
<div id="formBody">
|
||||
<div id="formHead">
|
||||
<div id="formHeadTxt">Connexion</div>
|
||||
<div id="formHeadTxt">{this.props.title}</div>
|
||||
<div id="crossClose" onClick={this.props.handleCloseAbove}>
|
||||
<Icon icon={plusIcon} style={{transform : 'rotate(-45deg)', color: '#ffffff', fontSize: '3vw'}} />
|
||||
</div>
|
||||
</div>
|
||||
<div id="formMainContent">
|
||||
<form method='POST' onSubmit={this.handleSubmit}>
|
||||
{!this.props.forJamalette ?
|
||||
<div id="identifyerBlock">
|
||||
<div id="identifyerBlockInput">
|
||||
<label htmlFor="identifyerBox">Identifiant</label>
|
||||
|
@ -70,7 +104,7 @@ class Connection extends Component {
|
|||
<div id="errorIdentifyerBlock">
|
||||
<p id="errorIdentifyer">{this.state.errors.identifyer}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div> : null }
|
||||
<div id="passwordBlock">
|
||||
<div id="passwordBlockInput">
|
||||
<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
|
||||
Paramètres :
|
||||
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
|
||||
Paramètre : title : texte intérieur */}
|
||||
|
|
|
@ -175,7 +175,7 @@ getBulleById = (id) => {
|
|||
let element;
|
||||
let articles = document.getElementById("articles")
|
||||
for (let i = 0; i < articles.childElementCount ; i++){
|
||||
if (id == articles.children[i].title){
|
||||
if (id === articles.children[i].title){
|
||||
element = articles.children[i]
|
||||
}
|
||||
}
|
||||
|
@ -485,7 +485,7 @@ updateArticle = (index,id) => {
|
|||
|
||||
|
||||
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>)
|
||||
} else {
|
||||
return (
|
||||
|
|
|
@ -11,6 +11,7 @@ import ArticleDetails from '../Components/ArticleDetails';
|
|||
import { Link } from 'react-router-dom';
|
||||
import NotInBdd from '../Components/NotInBdd';
|
||||
import Money from '../Components/Money';
|
||||
import Connection from '../Components/Connection';
|
||||
|
||||
export default class Stock extends React.Component {
|
||||
|
||||
|
@ -24,7 +25,8 @@ export default class Stock extends React.Component {
|
|||
totalPrice:0,
|
||||
totalQuantity:0,
|
||||
redirect:false,
|
||||
onNotInBdd:false
|
||||
onNotInBdd:false,
|
||||
onConnection:false
|
||||
}
|
||||
|
||||
this.handleScan = this.handleScan.bind(this);
|
||||
|
@ -122,8 +124,12 @@ export default class Stock extends React.Component {
|
|||
}
|
||||
|
||||
handleScan(code) {
|
||||
if (!sessionStorage.getItem('token_jamalette')){
|
||||
this.setState({onConnection:true,scannedCode:code})
|
||||
} else {
|
||||
this.getArticleByCode(code)
|
||||
}
|
||||
}
|
||||
|
||||
colorArticle = (color,element) => {
|
||||
|
||||
|
@ -184,8 +190,12 @@ export default class Stock extends React.Component {
|
|||
this.setState({onMoney:false})
|
||||
}
|
||||
|
||||
handleCloseConnection = () => {
|
||||
this.setState({onConnection:false},()=>{this.getArticleByCode(this.state.scannedCode)})
|
||||
}
|
||||
|
||||
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>)
|
||||
} else {
|
||||
return (
|
||||
|
@ -194,6 +204,9 @@ export default class Stock extends React.Component {
|
|||
<Navbar redirect="/stock" left="Monnaie" right="Le Stock" handleMoney={this.handleMoney}/>
|
||||
<BarcodeReader onScan={this.handleScan}/>
|
||||
<SearchBar/>
|
||||
{this.state.onConnection &&
|
||||
<Connection handleCloseAbove={this.handleCloseConnection} title="Jamalette" forJamalette={true}/>
|
||||
}
|
||||
{this.state.onMoney &&
|
||||
<Money empty={this.state.empty} handleCloseAbove={this.handleCloseMoney} totalPrice={this.state.totalPrice}/>
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue