Pārlūkot izejas kodu

login page changes

Naresh Ch 2 gadus atpakaļ
vecāks
revīzija
c11d4f2aa4
3 mainītis faili ar 109 papildinājumiem un 16 dzēšanām
  1. 15
    5
      assets/css/login.css
  2. 88
    7
      assets/js/login.js
  3. 6
    4
      login/index.html

+ 15
- 5
assets/css/login.css Parādīt failu

@@ -27,6 +27,10 @@ body {
27 27
     color: #3d3d3d;
28 28
 }
29 29
 
30
+.d-none {
31
+    display: none;
32
+}
33
+
30 34
 .biz-login-wrap {
31 35
     width: 100%;
32 36
     display: flex;
@@ -63,6 +67,10 @@ body {
63 67
     z-index: 1;
64 68
 }
65 69
 
70
+.biz-login-wrap .form-group input.error {
71
+    border-color: #d93025;
72
+}
73
+
66 74
 .biz-login-wrap .form-group label {
67 75
     position: absolute;
68 76
     left: 10px;
@@ -151,6 +159,7 @@ body {
151 159
     border-radius: 4px;
152 160
     font-weight: 500;
153 161
     font-size: 16px;
162
+    cursor: pointer;
154 163
 }
155 164
 
156 165
 .biz-login-wrap a {
@@ -188,6 +197,11 @@ body {
188 197
     font-weight: 500;
189 198
 }
190 199
 
200
+.biz-login-wrap .err-msg {
201
+    color: #d93025;
202
+    font-size: 12px;
203
+}
204
+
191 205
 .biz-login-wrap h4 {
192 206
     font-size: 16px;
193 207
     font-weight: 500;
@@ -244,7 +258,7 @@ body {
244 258
     margin-left: 5px;
245 259
 }
246 260
 
247
-h2 {
261
+.biz-login-wrap h2 {
248 262
     margin: 0;
249 263
     font-size: 24px;
250 264
     font-weight: 500;
@@ -256,10 +270,6 @@ h2 {
256 270
     margin: 20px 0px;
257 271
 }
258 272
 
259
-.d-none {
260
-    display: none;
261
-}
262
-
263 273
 .conformPassword {
264 274
     margin-top: 30px;
265 275
 }

+ 88
- 7
assets/js/login.js Parādīt failu

@@ -1,19 +1,31 @@
1
+const serverUrl = 'http://localhost:3088/';
2
+const emailInputEl = document.getElementById('email');
3
+const passwordInputEl = document.getElementById('password');
4
+const emailErrEl = document.getElementById('emailErrMsg');
5
+const passwordErrEl = document.getElementById('passwordErrMsg');
6
+
1 7
 document.getElementById('passwordBox').style.display = 'none';
2 8
 
3 9
 function showPasswordBox() {
4
-  const email = document.getElementById('email').value;
5
-  if (email.length > 0) {
10
+  const email = emailInputEl.value;
11
+  if (email.includes('@')) {
6 12
     document.getElementById('emailBox').style.display = 'none';
7 13
     document.getElementById('passwordBox').style.display = 'block';
8 14
     document.getElementById('entered-email').innerHTML = email;
15
+    emailInputEl.classList.remove('error');
16
+    emailErrEl.innerText = '';
17
+  } else {
18
+    emailInputEl.classList.add('error');
19
+    emailErrEl.innerText = 'Please enter valid email';
9 20
   }
10 21
 }
11
-function onEyeClick() {
22
+
23
+function togglePassword() {
12 24
   const ele = document.getElementById('showPassword');
13
-  const password = document.getElementById('password');
25
+  const password = passwordInputEl;
14 26
 
15 27
   if (password.value.length > 0) {
16
-    document.getElementById('password').value = password.value;
28
+    passwordInputEl.value = password.value;
17 29
     password.focus();
18 30
     if (ele.checked) {
19 31
       password.setAttribute('type', 'text');
@@ -22,9 +34,9 @@ function onEyeClick() {
22 34
     }
23 35
   }
24 36
 }
37
+
25 38
 function onPasswordFocus() {
26
-  const password = document.getElementById('password');
27
-  if (password.value.length > 0) {
39
+  if (passwordInputEl.value.length > 0) {
28 40
     document.getElementById('password-label').classList.add('password-fixed');
29 41
   } else {
30 42
     document
@@ -32,3 +44,72 @@ function onPasswordFocus() {
32 44
       .classList.remove('password-fixed');
33 45
   }
34 46
 }
47
+
48
+function setCookie(name, value, days) {
49
+  var expires = '';
50
+  if (days) {
51
+    var date = new Date();
52
+    date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
53
+    expires = '; expires=' + date.toUTCString();
54
+  }
55
+  document.cookie = name + '=' + (value || '') + expires + '; path=/';
56
+}
57
+
58
+function loginUser(email, password) {
59
+  const postData = JSON.stringify({
60
+    UserName: email,
61
+    Password: password,
62
+    UnibaseId: '',
63
+    RememberMe: false,
64
+  });
65
+
66
+  const requestOptions = {
67
+    method: 'POST',
68
+    headers: {
69
+      'Content-Type': 'application/json',
70
+    },
71
+    body: postData,
72
+    redirect: 'follow',
73
+  };
74
+
75
+  fetch(serverUrl + 'account/login', requestOptions)
76
+    .then((response) => response.text())
77
+    .then((result) => {
78
+      const user = JSON.parse(result);
79
+      setCookie('authentication', JSON.stringify(user.sessionId), 1);
80
+    })
81
+    .catch((error) => console.log('error', error));
82
+}
83
+
84
+function validateLogin() {
85
+  const email = emailInputEl.value;
86
+  const password = passwordInputEl.value;
87
+  if (email.includes('@') && password.trim().length !== 0) {
88
+    loginUser(email, password);
89
+  } else if (!email.includes('@')) {
90
+    emailErrEl.innerHTML = 'Please enter valid email';
91
+  } else {
92
+    passwordInputEl.classList.add('error');
93
+    passwordErrEl.innerText = 'Please enter valid password';
94
+  }
95
+}
96
+
97
+function initializeEventListeners() {
98
+  document.getElementById('emailNextBtn').addEventListener('click', () => {
99
+    showPasswordBox();
100
+  });
101
+
102
+  document.getElementById('showPassword').addEventListener('click', () => {
103
+    togglePassword();
104
+  });
105
+
106
+  document.getElementById('showPassword').addEventListener('onfocusout', () => {
107
+    onPasswordFocus();
108
+  });
109
+
110
+  document.getElementById('loginSubmitBtn').addEventListener('click', () => {
111
+    validateLogin();
112
+  });
113
+}
114
+
115
+initializeEventListeners();

+ 6
- 4
login/index.html Parādīt failu

@@ -23,6 +23,7 @@
23 23
                         <div class="form-group">
24 24
                             <input type="text input" id="email" class="email-input">
25 25
                             <label class="form-control-placeholder" for="name">Email or phone</label>
26
+                            <div class="err-msg" id="emailErrMsg"></div>
26 27
                         </div>
27 28
                         <div class="form-link mt-10">
28 29
                             <label><a href="javascript:;">Forgot email?</a></label>
@@ -34,7 +35,7 @@
34 35
                     </div>
35 36
                     <div class="form-link flex-between-center">
36 37
                         <label><a href="javascript:;">Create account</a></label>
37
-                        <button class="btn next-btn" onclick="showPasswordBox()">Next</button>
38
+                        <button class="btn next-btn" id="emailNextBtn">Next</button>
38 39
                     </div>
39 40
                 </div>
40 41
             </div>
@@ -49,18 +50,19 @@
49 50
                     <div class="form-input-wrap">
50 51
                         <div class="form-group">
51 52
                             <input type="password" id="password" class="password-input"
52
-                                onfocus="this.value = this.value;" onfocusout="onPasswordFocus()">
53
+                                onfocus="this.value = this.value;">
53 54
                             <label class="form-control-placeholder" id="password-label" for="name">Enter Your
54 55
                                 Password</label>
56
+                            <div class="err-msg" id="passwordErrMsg"></div>
55 57
                         </div>
56 58
                         <div class="form-link show-password-link">
57
-                            <input type="checkbox" id="showPassword" class="password-checkbox" onclick="onEyeClick()">
59
+                            <input type="checkbox" id="showPassword" class="password-checkbox">
58 60
                             <label for="showPassword">Show password</label>
59 61
                         </div>
60 62
                     </div>
61 63
                     <div class="form-link flex-between-center">
62 64
                         <label><a href="../forgotpassword/index.html">Forgot password?</a></label>
63
-                        <button class="btn">Next</button>
65
+                        <button class="btn" id="loginSubmitBtn">Submit</button>
64 66
                     </div>
65 67
                 </div>
66 68
             </div>

Notiek ielāde…
Atcelt
Saglabāt