Skip to content

Commit

Permalink
email duplicate pop up now available, icons for edit and delete in pl…
Browse files Browse the repository at this point in the history
…ace, yet to add functionality
  • Loading branch information
surajcm committed Feb 16, 2024
1 parent b4baefd commit 243fdf5
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.quiz.darkhold.user.entity.User;
import com.quiz.darkhold.user.service.SecurityService;
import com.quiz.darkhold.user.service.UserService;
import com.quiz.darkhold.util.CommonUtils;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.logging.log4j.LogManager;
Expand All @@ -23,12 +22,9 @@ public class LoginController {
private final Logger logger = LogManager.getLogger(LoginController.class);

private final SecurityService securityService;
private final UserService userService;

public LoginController(final SecurityService securityService,
final UserService userService) {
public LoginController(final SecurityService securityService) {
this.securityService = securityService;
this.userService = userService;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import com.quiz.darkhold.user.entity.User;
import com.quiz.darkhold.user.repository.RoleRepository;
import com.quiz.darkhold.user.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -48,7 +46,7 @@ public List<Role> listRoles() {
}

@Override
public Boolean isEmailUnique(String email) {
public Boolean isEmailUnique(final String email) {
return userRepository.findByEmail(email) == null;
}
}

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions src/main/resources/static/styles/icon-styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.icon-white {color: white;}
.icon-silver {color: silver;}
.icon-green {color: green;}
.icon-dark {color: grey;}
45 changes: 44 additions & 1 deletion src/main/resources/templates/user/createuser.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<meta name="author" content="Suraj" />
<title>Getting Started: Darkhold classroom quiz experience</title>
<link href="/styles/error-styles.css" rel="stylesheet" />
<link href="/styles/core/fontawesome-6.2.1/css/all.min.css" rel="stylesheet">
<script type="text/javascript" src="/scripts/common-scripts.js"></script>
<script type="text/javascript" src="/scripts/user-management-scripts.js"></script>
<script type="text/javascript" src="/scripts/core/bootstrap-5.3.1/bootstrap.min.js"></script>
Expand Down Expand Up @@ -71,16 +72,58 @@ <h3 class="panel-title">Create User</h3>
</div>
</div>
</form>
<div class="modal fade text-center" id="modalDialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="modalTitle">Warning</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal">&times;</button>
</div>
<div class="modal-body">
<span id="modalBody"></span>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</main>
<script type="text/javascript">
/*<![CDATA[*/
function toUsers() {
window.location = "/userManagement";
}
function checkEmailUnique() {

function checkEmailUnique(form) {
const email = form.email.value;
const xhr = new XMLHttpRequest();
xhr.open("POST", "/users/check_email", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("email=" + encodeURIComponent(email));
xhr.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
// The request has been processed successfully
const response = this.responseText;
if (response == 'OK') {
form.submit();
} else if (response == 'DUPLICATED') {
showModelDialog("Warning", "Email already exists. Please use a different email : " + email);
} else {
showModelDialog("Error", "An error occurred while checking email uniqueness. Please try again later.");
}
}
}
return false;
}

function showModelDialog(title, body) {
document.getElementById('modalTitle').innerText = title;
document.getElementById('modalBody').innerText = body;
const myModal = new bootstrap.Modal(document.getElementById('modalDialog'));
myModal.show();
}
/*]]>*/
</script>
</body>
Expand Down
17 changes: 13 additions & 4 deletions src/main/resources/templates/user/usermanagement.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Getting Started: Darkhold classroom quiz experience</title>
<link href="/styles/error-styles.css" rel="stylesheet" />
<link href="/styles/core/fontawesome-6.2.1/css/all.min.css" rel="stylesheet">
<link href="/styles/icon-styles.css" rel="stylesheet">
<script type="text/javascript" src="/scripts/common-scripts.js"></script>
<script type="text/javascript" src="/scripts/user-management-scripts.js"></script>
<script type="text/javascript" src="/scripts/core/bootstrap-5.3.1/bootstrap.min.js"></script>
Expand All @@ -21,7 +23,7 @@ <h2>Manage Users</h2>
</div>
</div>
<div>
<form th:action="" method="post">
<form action="" method="post">
<table class="table table-bordered table-striped table-hover table-responsive-xl">
<thead class="thead-dark">
<tr>
Expand All @@ -38,13 +40,20 @@ <h2>Manage Users</h2>
<tbody>
<tr th:each="user: ${listusers}">
<td>[[${user.id}]]</td>
<td></td>
<td><span class="fas fa-portrait fa-3x icon-silver"></span></td>
<td>[[${user.email}]]</td>
<td>[[${user.firstName}]]</td>
<td>[[${user.lastName}]]</td>
<td>[[${user.roles}]]</td>
<td>[[${user.enabled}]]</td>
<td>Edit &nbsp; Delete </td>
<td>
<a th:if="${user.enabled == true}" class="fas fa-check-circle fa-2x icon-green" href=""></a>
<a th:if="${user.enabled == false}" class="fas fa-check-circle fa-2x icon-dark" href=""></a>
</td>
<td>
<a class="fas fa-edit fa-2x icon-green" th:href="@{'/users/edit/' + ${user.id}}" title="Edit this user"></a>
&nbsp;
<a class="fas fa-trash fa-2x icon-dark" href=""></a>
</td>
</tr>
</tbody>
</table>
Expand Down

0 comments on commit 243fdf5

Please sign in to comment.