index.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <style>
  2. .site-card {
  3. height: 100vh;
  4. width: 100vw;
  5. padding: 20px;
  6. background: #ececec;
  7. }
  8. .content {
  9. width: 100%;
  10. height: 100%;
  11. }
  12. .grid {
  13. width: 25%;
  14. text-align: center;
  15. }
  16. </style>
  17. <script type="text/babel">
  18. const { LoadingOutlined } = window.icons;
  19. const { Card, Form, Input, Button, Row, Col, Modal } = window.antd;
  20. const App = () => {
  21. let onFinish = async (f) => {
  22. let request = {
  23. "method": "POST",
  24. "headers": {
  25. "Content-Type": "application/json",
  26. "<?= \Yii::$app->getRequest()->csrfParam ?>": "<?= \Yii::$app->getRequest()->csrfToken ?>",
  27. },
  28. body: JSON.stringify({
  29. "usuario": f.usuario,
  30. "clave": f.clave
  31. })
  32. };
  33. let resp = await fetch("/login", request);
  34. let data = await resp.json();
  35. if(data && data.success) {
  36. window.location.href = "/";
  37. return;
  38. }
  39. Modal.warning({title: "Los datos ingresados son incorrectos"});
  40. }
  41. return (
  42. <div className="site-card">
  43. <Row>
  44. <Col span={8} offset={8}>
  45. <Card>
  46. <Form
  47. name="basic"
  48. labelCol={{ span: 8 }}
  49. wrapperCol={{ span: 16 }}
  50. onFinish={onFinish}
  51. autoComplete="off"
  52. >
  53. <Form.Item
  54. label="Usuario"
  55. name="usuario"
  56. rules={[{ required: true, message: 'El Correo es obligatorio' }]}
  57. >
  58. <Input />
  59. </Form.Item>
  60. <Form.Item
  61. label="Contraseña"
  62. name="clave"
  63. rules={[{ required: true, message: 'La Contraseña es obligatoria' }]}
  64. >
  65. <Input.Password />
  66. </Form.Item>
  67. <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
  68. <Button type="primary" htmlType="submit">
  69. Iniciar Sesión
  70. </Button>
  71. </Form.Item>
  72. </Form>
  73. </Card>
  74. </Col>
  75. </Row>
  76. </div>
  77. );
  78. }
  79. ReactDOM.render(<App />, document.getElementById('root'));
  80. </script>