]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git/blame - cmd/web/js/otp.jsx
Upgrade ReactJS. EC6 import modules.
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git] / cmd / web / js / otp.jsx
CommitLineData
989fb5c7 1import Api from './api.js';
2import App from './app.js';
3import classNames from 'classnames';
4import React from 'react';
7a9e5112 5
989fb5c7 6class OtpQrCode extends React.Component {
7 render = () => {
7a9e5112 8 return (
9 <div>
10 <img src={this.props.img} />
11 <p>{this.props.secret}</p>
12 </div>
13 );
14 }
989fb5c7 15}
7a9e5112 16
989fb5c7 17class OtpEnrollForm extends React.Component {
18 constructor(props) {
19 super(props);
20 this.state = {'hideMsg': true, 'msg': '', 'msgOk': false, 'pass': ''};
21 }
22
23 handleSubmit = (e) => {
7a9e5112 24 Api.Call('OTP_VALIDATE', {'pass': this.state.pass}, function(err, status, data) {
25 if (err) {
26 console.error(err, data);
27 this.displayMessage(App.errorCodeToMessage(err.code), false);
28 return;
29 }
30
31 this.displayMessage('OK', true);
32 this.props.onSuccess(data.token);
33
34 }.bind(this));
35
36 e.preventDefault();
989fb5c7 37 }
38
39 handlePassChange = (event) => {
7a9e5112 40 this.setState({'pass': event.target.value});
989fb5c7 41 }
42
43 hideMessage = () => {
7a9e5112 44 this.setState({'hideMsg': true});
989fb5c7 45 }
46
47 displayMessage = (msg, ok) => {
7a9e5112 48 this.setState({'msg': msg, 'msgOk': ok, 'hideMsg': false});
989fb5c7 49 }
50
51 render = () => {
7a9e5112 52 var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk});
53 var qrCode = null;
54
55 if (this.props.img) {
989fb5c7 56 qrCode =
57 <div className="row justify-content-center">
7a9e5112 58 <OtpQrCode img={this.props.img} secret={this.props.secret} />
989fb5c7 59 </div>;
60}
7a9e5112 61 return (
989fb5c7 62 <div className="row otp-enroll">
63 <div className="offset-4 col-4 col-xs-offset-1 col-xs-10 text-center">
7a9e5112 64 {qrCode}
989fb5c7 65 <div className="row justify-content-center">
66 <form role="form" onSubmit={this.handleSubmit}>
67 <input className="form-control" type="pass" placeholder="code" onChange={this.handlePassChange} />
68 <input className="form-control submit" type="submit" value="Validate" />
69 <div className={cName}>{this.state.msg}</div>
7a9e5112 70 </form>
71 </div>
72 </div>
73 </div>
74 );
75 }
989fb5c7 76}
77
78export default OtpEnrollForm;