Skip to content

Commit

Permalink
Improve formatting for remember me code
Browse files Browse the repository at this point in the history
Normalize spacing and indentation, change "let" to "const" where
appropriate, use triple-equals, and change some names to be more
semantically accurate
  • Loading branch information
psvenk committed Oct 3, 2020
1 parent 34a1df1 commit c8040c2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
50 changes: 28 additions & 22 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,46 @@ if ('serviceWorker' in navigator) {
});
});
}

// Remember me and autofill functions

function rememberMe() {
if(localStorage.getItem("remember") == "yes"){
document.getElementById("check").setAttribute('checked', true)
if (localStorage.getItem("remember") === "yes") {
document.getElementById("remember-me").setAttribute('checked', true);
}
else {
document.getElementById("check").setAttribute('checked', false)
document.getElementById("remember-me").setAttribute('checked', false);
}

if (localStorage.getItem("username") === null) {
localStorage.removeItem("username")
localStorage.removeItem("username");
}
else {
document.getElementById("input-name").setAttribute('value',localStorage.getItem("username"))
document.getElementById("input-password").setAttribute('value',localStorage.getItem("password"))
document.getElementById("input-username").setAttribute(
'value', localStorage.getItem("username")
);
document.getElementById("input-password").setAttribute(
'value', localStorage.getItem("password")
);
}

if (localStorage.getItem("password") === null){
localStorage.removeItem("password")
if (localStorage.getItem("password") === null) {
localStorage.removeItem("password");
}
}
function autofill () {
let checkBox = document.getElementById("check");
if(checkBox.checked === true) {
let name = document.getElementById("input-name").value;
let password = document.getElementById("input-password").value;
localStorage.setItem("username", name)
localStorage.setItem("password", password)
localStorage.setItem("remember", "yes")

function autofill() {
const checkBox = document.getElementById("remember-me");
if (checkBox.checked === true) {
const username = document.getElementById("input-username").value;
const password = document.getElementById("input-password").value;
localStorage.setItem("username", username);
localStorage.setItem("password", password);
localStorage.setItem("remember", "yes");
}
if(checkBox.checked === false) {
localStorage.removeItem("username")
localStorage.removeItem("password")
localStorage.setItem("remember", "no")
}
}
if (checkBox.checked === false) {
localStorage.removeItem("username");
localStorage.removeItem("password");
localStorage.setItem("remember", "no");
}
}
4 changes: 2 additions & 2 deletions public/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</div>
<!-- Username Input -->
<div class="wrap-input100">
<input class="input100" id="input-name" type="text" name="username" placeholder="Student ID" aria-label="Aspen Student ID" autofocus>
<input class="input100" id="input-username" type="text" name="username" placeholder="Student ID" aria-label="Aspen Student ID" autofocus>
<span class="focus-input100"></span>
<span class="symbol-input100">
<i class="fa fa-id-card" aria-hidden="true"></i>
Expand All @@ -81,7 +81,7 @@
<div class="checkbox">
<span>
Remember Me?
<input id ="check" type="checkbox">
<input id="remember-me" type="checkbox">
</span>
</div>
<!-- Login Button -->
Expand Down

0 comments on commit c8040c2

Please sign in to comment.