Browse Source

HW YB2NKR8B2LL done

Varvara Huza 3 years ago
parent
commit
2b361ad952
3 changed files with 208 additions and 0 deletions
  1. 33 0
      Homework_2/index.html
  2. 67 0
      Homework_2/main.js
  3. 108 0
      Homework_2/style.css

+ 33 - 0
Homework_2/index.html

@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Login</title>
+  <link rel="stylesheet" href="style.css">
+</head>
+<body>
+  <div class="container">
+      <form id="form" action="/" method="">
+        <div class="form-wrapper">
+          <div class="login-form form">
+            <label class="label login-label" for="login-input">Login</label> <br />
+            <input class="input login-input" type="text" id="login-input" name="login" />
+            <div id="login-error">This field cannot be empty!</div>
+          </div>
+
+          <div class="password-form form">
+            <label class="label password-label" for="password-input">Password</label> <br />
+            <input class="input password-input" type="password" id="password-input" name="password"/>
+            <div id="password-error">This field cannot be empty!</div>
+          </div>
+
+          <button class="submit-btn" type="submit">Login</button>
+        </div>
+      </form>
+    </div>
+  </div>
+<script src="main.js"></script>
+</body>
+</html>

+ 67 - 0
Homework_2/main.js

@@ -0,0 +1,67 @@
+alert('Сейчас мы посчитаем Ваше нормальное артериальное давление!')
+
+let age; 
+
+do {
+    age = prompt('Сколько Вам лет?');
+} while(age == null || age == '')
+
+
+let normalPressureMax = Math.round(102 + 0.6 * age)
+let normalPressureMin = Math.round(63 + 0.5 * age)
+
+alert('Ваше нормальное артериальное давление: ' + normalPressureMax + ' на ' + normalPressureMin + '. А теперь можете перейти к авторизации!')
+
+const login = document.getElementById('login-input')
+const password = document.getElementById('password-input')
+const form = document.getElementById('form')
+const formWrapper = document.querySelector('.form-wrapper')
+
+const loginError = document.getElementById('login-error')
+const passwordError = document.getElementById('password-error')
+
+const error = document.createElement('div')
+error.classList.add("error")
+error.innerHTML = 'Access denied'
+const success = document.createElement('success')
+success.classList.add("success")
+success.innerHTML = 'Success!'
+
+let credentials = {
+    login: 'admin',
+    password: 'qwerty',
+}
+
+
+form.addEventListener('submit', (e) => {
+  let messages = []
+  if (login.value === '' || login.value == null) {
+    loginError.style.display='block'
+    e.preventDefault()
+  } else if (login.value !== '' && login.value !== null) {
+    loginError.style.display='none'
+  }
+
+  if (password.value === '' || password.value == null) {
+    passwordError.style.display='block'
+    e.preventDefault()
+  } else if (password.value !== '' && password.value !== null) {
+    passwordError.style.display='none'
+  } 
+
+  if (login.value === credentials.login && password.value === credentials.password) {
+    e.preventDefault()
+    formWrapper.appendChild(success)
+      if (document.querySelector('.error') !== null) {
+          formWrapper.removeChild(error)
+      }
+   
+  } else {
+    e.preventDefault()
+    formWrapper.appendChild(error)
+    if (document.querySelector('.success') !== null) {
+          formWrapper.removeChild(success)
+      }
+    
+  }
+})

+ 108 - 0
Homework_2/style.css

@@ -0,0 +1,108 @@
+html {
+    box-sizing: border-box;
+  }
+  
+  *,
+  *::before,
+  *::after {
+    box-sizing: inherit;
+  }
+  
+  body {
+    margin: 0;
+    font-size: 16px;
+    line-height: 1;
+    color: #2a464d;
+    background-color: rgb(255, 239, 226);
+  }
+  
+  .container {
+    max-width: 1000px;
+    padding: 0 15px;
+    margin: 0 auto;
+  }
+  
+  .form-wrapper {
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    flex-direction: column;
+    padding: 30px;
+  }
+  
+  .form {
+    display: flex;
+    flex-direction: column;
+    justify-content: center;
+    margin-bottom: 15px;
+    text-align: center;
+  }
+  
+  .input {
+    padding: 10px 10px;
+    border: none;
+    border-radius: 3px;
+  }
+  
+  .input:hover {
+    outline: rgb(255, 223, 195) solid 1px;
+    outline-offset: 0;
+  }
+  
+  .input:focus {
+    outline: rgb(255, 210, 170) solid 1px;
+    outline-offset: 0;
+  }
+  
+  .submit-btn {
+    padding: 5px 15px;
+    border: none;
+    border-radius: 3px;
+    background-color: #fff;
+    cursor: pointer;
+    outline: rgb(255, 210, 170) solid 1px;
+    transition: 0.3s;
+    margin-bottom: 25px;
+  }
+  
+  .submit-btn:hover {
+    box-shadow: 1px 1px 3px 0 rgba(0, 0, 0, 0.096);
+  }
+  
+  #login-error,
+  #password-error {
+    margin-top: 7px;
+    font-size: 12px;
+    padding: 5px 25px;
+    color: rgb(255, 79, 79);
+    background: rgba(255, 79, 79, 0.1);
+    text-align: center;
+    border-radius: 3px;
+    border: 1px solid #ef9a9a;
+    display: none;
+  }
+  
+  .error,
+  .success {
+    width: 350px;
+    height: 150px;
+    display: flex;
+    justify-content: center;
+    padding: 15px;
+    font-weight: bold;
+    text-transform: uppercase;
+    border-radius: 5px;
+    align-items: center;
+  }
+  
+  .error {
+    background-color: rgba(255, 79, 79, 0.1);
+    border: 3px solid rgb(255, 79, 79);
+    color: rgb(255, 79, 79);
+  }
+  
+  .success {
+    background-color: rgb(82, 245, 150);
+    border: 3px solid rgb(35, 150, 64);
+    color: rgb(35, 150, 64);
+  }