瀏覽代碼

js/01: +change credential +add new auth valid errors

ilya_shyian 3 年之前
父節點
當前提交
10a80c5460
共有 1 個文件被更改,包括 5 次插入7 次删除
  1. 5 7
      js/01/index.html

+ 5 - 7
js/01/index.html

@@ -57,11 +57,7 @@
             const btnLogout = `
                 <button class="btn btn-logout" onclick="logout()">Logout</button>
             `;
-            const credentials = [
-                { login: "test1", password: "test1" },
-                { login: "test2", password: "test3" },
-                { login: "test3", password: "test2" },
-            ];
+            const credentials = { login: "admin", password: "qwerty" };
 
             document.querySelector(".container-form").innerHTML = "loading...";
             fetch("https://open.er-api.com/v6/latest/USD", {
@@ -99,9 +95,11 @@
                 e.preventDefault();
                 let login = e.target.elements.login.value;
                 let password = e.target.elements.password.value;
-                let accountCredentials = credentials.filter((el) => el.login === login)[0];
 
-                if (!accountCredentials || accountCredentials?.password !== password) {
+                login ? removeError("Login is required") : addError("Login is required");
+                password ? removeError("Password is required") : addError("Password is required");
+
+                if (credentials.login !== login || credentials.password !== password) {
                     localStorage.setItem("isAuth", false);
                     addError("The username or password is incorrect");
                     return;