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

Enhance User Registration with Input Validation and Success Feedback #908

Open
wants to merge 3 commits into
base: develop
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
14 changes: 14 additions & 0 deletions apps/signup/signup.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ body {
font-family: 'Roboto', sans-serif;
overflow-x: hidden;
}
.popup {
position: fixed;
top: 10%;
right: 5%;
max-width: 300px;
height: 50px;
padding: 10px;
background-color: #28a745;
color: #fff;
text-align: center;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
z-index:9999;
}
.bg-dark {
background-color: #343a40!important;
}
Expand Down
16 changes: 10 additions & 6 deletions apps/signup/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
style="text-align:center; background: #17a2b8; font-size: xx-large; color: white; padding: 4px; border-radius: 5px 5px 0px 0px;">
caMicroscope
</div>
<!-- <hr style="width: 24.25em; height: 0.01em; background-color: black; margin-top: 0em; margin-bottom: 0;"> -->

<form id="userForm" onsubmit="return false;">
<h2 style="margin-top: -.5em;">User Signup</h2>
Expand All @@ -77,17 +76,18 @@ <h2 style="margin-top: -.5em;">User Signup</h2>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope" style="margin-top: 0.5em;"></i></span>
<input id="mail" type="email" class="form-control" name="email" placeholder="Email" >
<input id="mail" type="email" class="form-control" name="email" placeholder="Email">
</div>
<div id="emailerror" class="error-message"></div>
<div id="emailError" class="error-message text-danger"></div>

</div>
<br>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-th-list" style="margin-top: 0.5em;"></i></span>
<input type="text" id="filters" class="form-control" placeholder="['list','of','filters']"
required="required">
<input type="text" id="filters" class="form-control" placeholder="['list','of','filters']">
</div>
<div id="filtersError" class="error-message ml-1 text-danger"></div>
</div> <br>

<!-- User Type selection -->
Expand All @@ -105,9 +105,11 @@ <h2 style="margin-top: -.5em;">User Signup</h2>
</button>
<div class="text-center" onclick="loginPage()" style="margin-top: 0.5em;">Already have an account? </div>
</div>

<!-- <p class="small text-center">This form is only useful to Admin users. If you reach this page, it's likely that you tried to log into this instance but lack
access. Email the administrator if you want to be added.</p> -->
<p id="info" class="small text-center;">

Non-admin users have to submit a request ticket to admins to get their approval to signup new users.
If you are an Admin, you can directly signup users.
</p>
Expand All @@ -118,7 +120,9 @@ <h2 style="margin-top: -.5em;">User Signup</h2>

<footer id="footer-layout"></footer>
<!-- popup -->
<div id="popup-container"></div>
<div id="successPopup" class="alert alert-success popup" role="alert" style="display:none;">
User registered successfully!
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js"
integrity="sha384-p34f1UUtsS3wqzfto5wAAmdvj+osOnFyQFpp4Ua3gs/ZVWx6oOypYoCJhGGScy+8"
Expand Down
41 changes: 35 additions & 6 deletions apps/signup/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ var userSignupUrl = "../../data/User/post";
var protoTokenUrl = "../../auth/Token/proto";
var permissions;
const store = new Store('../../data/');
var emailError = document.getElementById("emailError");
var filtersError = document.getElementById("filtersError");

// Validation function for email
function validateEmail(email) {
return /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(email);
}

// Validation function for filters
function validateFilters(filters) {
Lochipi marked this conversation as resolved.
Show resolved Hide resolved
return filters.trim() !== ''; // Basic validation: ensuring it's not empty
}

function addUser(){
var email = document.getElementById("mail").value
Expand All @@ -11,10 +23,21 @@ function addUser(){
var attr = attrEle.options[attrEle.selectedIndex].value;
var emailErr = document.getElementById('emailerror');

if (email === '') {
emailErr.textContent = 'Please enter your email';
} else if (!(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(email))) {
emailErr.textContent = 'Please enter a valid email';
// Clear previous error messages
emailError.style.display = "none";
filtersError.style.display = "none";

if (!validateEmail(email)) {
emailError.style.display = "block";
emailError.innerHTML = "Please enter a valid email address.";
return;
}

if (!validateFilters(filters)) {
filtersError.style.display = "block";
filtersError.innerHTML = "Please enter atleast one filter.";
return;

}


Expand Down Expand Up @@ -88,7 +111,14 @@ function addUser(){
}
x.json()
}).then(x=>{
window.alert("User registered successfully");
// Show success popup
document.getElementById("successPopup").style.display = "block";
document.getElementById('mail').value = '';
document.getElementById('filters').value = '';

setTimeout(function(){
document.getElementById("successPopup").style.display = "none";
}, 3000)
}).catch(e=>{
// window.alert("error!")
console.error(e)
Expand All @@ -99,7 +129,6 @@ function addUser(){
}
});
}

$(window).on('load', function() {
$('#sub').text('Sign up');
$('#sub').removeAttr('disabled');
Expand Down