Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Did some changes #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
</ul>
<div>
<form class="form-inline my-2 my-lg-0">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">SignOut</button>
<button class="btn btn-outline-success my-2 my-sm-0" type="submit" id="signout_btn">SignOut</button>
<h3 id="greetings"></h3>
</form>
</div>
</div>
Expand Down
44 changes: 44 additions & 0 deletions js/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var elem_reg = document.getElementById("submit_reg");
if(elem_reg != null){
elem_reg.addEventListener('click', function(event){
element_terms = document.getElementById("terms");
if(element_terms.checked != true){
window.alert("Please check terms and conditions")
}else{
password = document.getElementById("password_reg")
password_conf = document.getElementById("password_reg_conf")
username = document.getElementById("username_reg").value
if(password.value != password_conf.value){
window.alert("Password doesn't match")
}else if(username.length <= 1 || password.value.length <= 1){
window.alert("Enter valid username and password")
}else{
localStorage.removeItem("username")
localStorage.removeItem("password")
localStorage.setItem("username", username)
localStorage.setItem("password", password.value)
sessionStorage.setItem("logged_in", username)
window.location.href = "index.html"
}
}
})
}

var elem_login = document.getElementById("login_btn")
if(elem_login != null){
elem_login.addEventListener('click', function(event){
console.log("log in")
username = document.getElementById('username_login').value
password = document.getElementById('username_password').value

user_storage = localStorage.getItem("username")
pwd_storage = localStorage.getItem("password")

if(username == user_storage && password == pwd_storage){
sessionStorage.setItem("logged_in", username)
window.location.href = "index.html"
}else{
window.alert("Invalid username/password")
}
})
}
6 changes: 6 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,10 @@ if (chBar) {
}
}
});
}

var log_flag = sessionStorage.getItem("logged_in")
if(log_flag.length >1){
document.getElementById("signout_btn").style.display = "none"
document.getElementById("greetings").innerHTML = "Hello " + log_flag
}
28 changes: 18 additions & 10 deletions loginform.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,19 @@

img.avatar {
width: 40%;
height: 50%;
border-radius: 50%;
}

.container {
padding: 16px;
text-align: center;
}
.container_parent {
padding: 16px;
width: 40%;
margin: auto;
border: 3px solid #f1f1f1;
}

span.psw {
Expand All @@ -66,23 +74,22 @@
}
</style>
</head>
<body>
<body style="text-align: center;">
<div class="container_parent">

<h2 style="text-align: center;">Login Form</h2>

<form action="/action_page.php">
<div class="imgcontainer">
<img src="img_avatar2.png" alt="Avatar" class="avatar">
</div>

<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>
<label><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" id="username_login" required>

<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<label><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" id="username_password" required>

<button type="submit">Login</button>
<button type="button" id="login_btn">Login</button>
<label>
<input type="checkbox" checked="checked" name="remember"> Remember me
</label>
Expand All @@ -92,7 +99,8 @@ <h2 style="text-align: center;">Login Form</h2>
<button type="button" class="cancelbtn" onclick="history.back()">Cancel</button>
<span class="psw">Forgot <a href="#">password?</a></span>
</div>
</form>

</div>
</body>
</html>

<script src="./js/common.js"></script>
14 changes: 8 additions & 6 deletions registerform.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1>Register</h1>
</div>
<div class="row align-items-center">
<div class="col mt-4">
<input type="text" class="form-control" placeholder="User Name">
<input type="text" id="username_reg" class="form-control" placeholder="User Name">
</div>
</div>
<div class="row align-items-center mt-4">
Expand All @@ -36,22 +36,22 @@ <h1>Register</h1>
</div>
<div class="row align-items-center mt-4">
<div class="col">
<input type="password" class="form-control" placeholder="Password">
<input type="password" id="password_reg" class="form-control" placeholder="Password">
</div>
<div class="col">
<input type="password" class="form-control" placeholder="Confirm Password">
<input type="password" id="password_reg_conf" class="form-control" placeholder="Confirm Password">
</div>
</div>
<div class="row justify-content-start mt-4">
<div class="col">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input">
<input type="checkbox" id="terms" class="form-check-input">
I Read and Accept <a href="#">Terms and Conditions</a>
</label>
</div>

<button class="btn btn-primary mt-4">Submit</button>
<button class="btn btn-primary mt-4" id="submit_reg">Submit</button>
<button type="button" class="btn btn-danger mt-4" onclick="history.back()">Cancel</button>
</div>
</div>
Expand All @@ -63,4 +63,6 @@ <h1>Register</h1>
</body>


</html>
</html>

<script src="./js/common.js"></script>