From e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d Mon Sep 17 00:00:00 2001
From: Piotr Russ <mail@pruss.it>
Date: Mon, 16 Nov 2020 00:10:28 +0100
Subject: api, login, auth

---
 client/src/login/jsx/LoginPanel.jsx | 80 +++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100644 client/src/login/jsx/LoginPanel.jsx

(limited to 'client/src/login/jsx/LoginPanel.jsx')

diff --git a/client/src/login/jsx/LoginPanel.jsx b/client/src/login/jsx/LoginPanel.jsx
new file mode 100644
index 0000000..296dc0e
--- /dev/null
+++ b/client/src/login/jsx/LoginPanel.jsx
@@ -0,0 +1,80 @@
+import React, {useState, useEffect} from 'react';
+
+const LoginPanel = ({setUser, t}) => {
+  const [username, setUsername] = useState('');
+  const [password, setPassword] = useState('');
+  const [active, setActive] = useState(false);
+
+  useEffect(() => {
+    if (username.length > 4 && password.length > 4) {
+      setActive(true);
+    } else {
+      setActive(false);
+    }
+  }, [username, password])
+
+  const usernameValidation = (e) => {
+    const value = e.target.value;
+    const regex = /^[0-9a-zA-Z]+$/;
+
+    if ((value.length < 20 && value.match(regex)) || value === "") {
+      setUsername(value);
+    }
+  };
+
+  const passwordValidation = (e) => {
+    e.target.value.length < 20 && setPassword(e.target.value);
+  };
+
+  const submit = (e) => {
+    e.preventDefault();
+    if (username === 'admin' && password === 'admin') {
+      setUser('admin');
+    }
+  }
+
+  return (
+    <div className="login-panel">
+      <form className="login-panel__form" onSubmit={submit}>
+        <p className="login-panel__header">
+          {t('login-to-admin')}
+        </p>
+        <div className="text-input">
+          <input
+            onChange={usernameValidation}
+            placeholder={t('user')}
+            id="admin-user-name"
+            name="admin-user-name"
+            type="text"
+            className="text-input-field"
+            value={username}
+          />
+          <label htmlFor="admin-user-name" className="text-input-label">{t('user')}</label>
+        </div>
+        <div className="text-input">
+          <input
+            onChange={passwordValidation}
+            placeholder={t('password')}
+            id="admin-password"
+            name="admin-password"
+            type="password"
+            className="text-input-field"
+            value={password}
+          />
+          <label htmlFor="admin-password" className="text-input-label">
+            {t('password')}
+          </label>
+        </div>
+        <div>
+          <input
+            type="submit"
+            className={`login-panel__button${active ? ' active' : ''}`}
+            value={t('login')}
+          />
+        </div>
+      </form>
+    </div>
+  );
+};
+
+export default LoginPanel;
-- 
cgit v1.2.3

