Bläddra i källkod

login page changes

Naresh Ch 2 år sedan
förälder
incheckning
c11d4f2aa4
3 ändrade filer med 109 tillägg och 16 borttagningar
  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 Visa fil

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

+ 88
- 7
assets/js/login.js Visa fil

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
 document.getElementById('passwordBox').style.display = 'none';
7
 document.getElementById('passwordBox').style.display = 'none';
2
 
8
 
3
 function showPasswordBox() {
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
     document.getElementById('emailBox').style.display = 'none';
12
     document.getElementById('emailBox').style.display = 'none';
7
     document.getElementById('passwordBox').style.display = 'block';
13
     document.getElementById('passwordBox').style.display = 'block';
8
     document.getElementById('entered-email').innerHTML = email;
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
   const ele = document.getElementById('showPassword');
24
   const ele = document.getElementById('showPassword');
13
-  const password = document.getElementById('password');
25
+  const password = passwordInputEl;
14
 
26
 
15
   if (password.value.length > 0) {
27
   if (password.value.length > 0) {
16
-    document.getElementById('password').value = password.value;
28
+    passwordInputEl.value = password.value;
17
     password.focus();
29
     password.focus();
18
     if (ele.checked) {
30
     if (ele.checked) {
19
       password.setAttribute('type', 'text');
31
       password.setAttribute('type', 'text');
22
     }
34
     }
23
   }
35
   }
24
 }
36
 }
37
+
25
 function onPasswordFocus() {
38
 function onPasswordFocus() {
26
-  const password = document.getElementById('password');
27
-  if (password.value.length > 0) {
39
+  if (passwordInputEl.value.length > 0) {
28
     document.getElementById('password-label').classList.add('password-fixed');
40
     document.getElementById('password-label').classList.add('password-fixed');
29
   } else {
41
   } else {
30
     document
42
     document
32
       .classList.remove('password-fixed');
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 Visa fil

23
                         <div class="form-group">
23
                         <div class="form-group">
24
                             <input type="text input" id="email" class="email-input">
24
                             <input type="text input" id="email" class="email-input">
25
                             <label class="form-control-placeholder" for="name">Email or phone</label>
25
                             <label class="form-control-placeholder" for="name">Email or phone</label>
26
+                            <div class="err-msg" id="emailErrMsg"></div>
26
                         </div>
27
                         </div>
27
                         <div class="form-link mt-10">
28
                         <div class="form-link mt-10">
28
                             <label><a href="javascript:;">Forgot email?</a></label>
29
                             <label><a href="javascript:;">Forgot email?</a></label>
34
                     </div>
35
                     </div>
35
                     <div class="form-link flex-between-center">
36
                     <div class="form-link flex-between-center">
36
                         <label><a href="javascript:;">Create account</a></label>
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
                     </div>
39
                     </div>
39
                 </div>
40
                 </div>
40
             </div>
41
             </div>
49
                     <div class="form-input-wrap">
50
                     <div class="form-input-wrap">
50
                         <div class="form-group">
51
                         <div class="form-group">
51
                             <input type="password" id="password" class="password-input"
52
                             <input type="password" id="password" class="password-input"
52
-                                onfocus="this.value = this.value;" onfocusout="onPasswordFocus()">
53
+                                onfocus="this.value = this.value;">
53
                             <label class="form-control-placeholder" id="password-label" for="name">Enter Your
54
                             <label class="form-control-placeholder" id="password-label" for="name">Enter Your
54
                                 Password</label>
55
                                 Password</label>
56
+                            <div class="err-msg" id="passwordErrMsg"></div>
55
                         </div>
57
                         </div>
56
                         <div class="form-link show-password-link">
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
                             <label for="showPassword">Show password</label>
60
                             <label for="showPassword">Show password</label>
59
                         </div>
61
                         </div>
60
                     </div>
62
                     </div>
61
                     <div class="form-link flex-between-center">
63
                     <div class="form-link flex-between-center">
62
                         <label><a href="../forgotpassword/index.html">Forgot password?</a></label>
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
                     </div>
66
                     </div>
65
                 </div>
67
                 </div>
66
             </div>
68
             </div>

Laddar…
Avbryt
Spara